001package com.example.metaschema;
002
003import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter;
004import gov.nist.secauto.metaschema.core.datatype.adapter.UriAdapter;
005import gov.nist.secauto.metaschema.core.datatype.adapter.UriReferenceAdapter;
006import gov.nist.secauto.metaschema.core.model.IBoundObject;
007import gov.nist.secauto.metaschema.core.model.IMetaschemaData;
008import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
009import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
010import gov.nist.secauto.metaschema.core.util.ObjectUtils;
011import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly;
012import gov.nist.secauto.metaschema.databind.model.annotations.BoundField;
013import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag;
014import gov.nist.secauto.metaschema.databind.model.annotations.Expect;
015import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
016import gov.nist.secauto.metaschema.databind.model.annotations.IsUnique;
017import gov.nist.secauto.metaschema.databind.model.annotations.KeyField;
018import gov.nist.secauto.metaschema.databind.model.annotations.Let;
019import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
020import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints;
021import java.lang.Override;
022import java.lang.String;
023import java.net.URI;
024import java.util.LinkedList;
025import java.util.List;
026import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
027import org.apache.commons.lang3.builder.ToStringStyle;
028
029/**
030 * Defines constraint rules to be applied to an existing set of Metaschema module-based models.
031 */
032@MetaschemaAssembly(
033    formalName = "External Module Constraints",
034    description = "Defines constraint rules to be applied to an existing set of Metaschema module-based models.",
035    name = "metaschema-meta-constraints",
036    moduleClass = MetaschemaModelModule.class,
037    rootName = "metaschema-meta-constraints",
038    valueConstraints = @ValueConstraints(lets = @Let(name = "deprecated-type-map", target = "map { 'base64Binary':'base64','dateTime':'date-time','dateTime-with-timezone':'date-time-with-timezone','email':'email-address','nonNegativeInteger':'non-negative-integer','positiveInteger':'positive-integer' }"), expect = @Expect(id = "metaschema-deprecated-types", formalName = "Avoid Deprecated Data Type Use", description = "Ensure that the data type specified is not one of the legacy Metaschema data types which have been deprecated (i.e. base64Binary, dateTime, dateTime-with-timezone, email, nonNegativeInteger, positiveInteger).", level = IConstraint.Level.WARNING, target = ".//matches/@datatype|.//(define-field|define-flag)/@as-type", test = "not(.=('base64Binary','dateTime','dateTime-with-timezone','email','nonNegativeInteger','positiveInteger'))", message = "Use of the type '{ . }' is deprecated. Use '{ $deprecated-type-map(.)}' instead.")),
039    modelConstraints = @gov.nist.secauto.metaschema.databind.model.annotations.AssemblyConstraints(unique = {@IsUnique(id = "meta-constraints-namespace-unique-entry", formalName = "Require Unique Namespace Entries", description = "Ensures that all declared namespace entries are unique.", level = IConstraint.Level.ERROR, target = "namespace-binding", keyFields = {@KeyField(target = "@prefix"), @KeyField(target = "@uri")}), @IsUnique(id = "meta-constraints-namespace-unique-prefix", formalName = "Require Unique Namespace Entry Prefixes", description = "Ensures that all declared namespace entries have a unique prefix.", level = IConstraint.Level.ERROR, target = "namespace-binding", keyFields = @KeyField(target = "@prefix"))})
040)
041public class MetaschemaMetaConstraints implements IBoundObject {
042  private final IMetaschemaData __metaschemaData;
043
044  @BoundAssembly(
045      description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.",
046      useName = "import",
047      maxOccurs = -1,
048      groupAs = @GroupAs(name = "imports", inJson = JsonGroupAsBehavior.LIST)
049  )
050  private List<Import> _imports;
051
052  @BoundAssembly(
053      formalName = "Metapath Namespace Declaration",
054      description = "Assigns a Metapath namespace to a prefix for use in a Metapath expression in a lexical qualified name.",
055      useName = "namespace-binding",
056      maxOccurs = -1,
057      groupAs = @GroupAs(name = "namespace-bindings")
058  )
059  private List<MetapathNamespace> _namespaceBindings;
060
061  @BoundAssembly(
062      useName = "definition-context"
063  )
064  private DefinitionContext _definitionContext;
065
066  @BoundAssembly(
067      useName = "context",
068      minOccurs = 1,
069      maxOccurs = -1,
070      groupAs = @GroupAs(name = "contexts", inJson = JsonGroupAsBehavior.LIST)
071  )
072  private List<MetapathContext> _contexts;
073
074  public MetaschemaMetaConstraints() {
075    this(null);
076  }
077
078  public MetaschemaMetaConstraints(IMetaschemaData data) {
079    this.__metaschemaData = data;
080  }
081
082  @Override
083  public IMetaschemaData getMetaschemaData() {
084    return __metaschemaData;
085  }
086
087  public List<Import> getImports() {
088    return _imports;
089  }
090
091  public void setImports(List<Import> value) {
092    _imports = value;
093  }
094
095  /**
096   * Add a new {@link Import} item to the underlying collection.
097   * @param item the item to add
098   * @return {@code true}
099   */
100  public boolean addImport(Import item) {
101    Import value = ObjectUtils.requireNonNull(item,"item cannot be null");
102    if (_imports == null) {
103      _imports = new LinkedList<>();
104    }
105    return _imports.add(value);
106  }
107
108  /**
109   * Remove the first matching {@link Import} item from the underlying collection.
110   * @param item the item to remove
111   * @return {@code true} if the item was removed or {@code false} otherwise
112   */
113  public boolean removeImport(Import item) {
114    Import value = ObjectUtils.requireNonNull(item,"item cannot be null");
115    return _imports != null && _imports.remove(value);
116  }
117
118  public List<MetapathNamespace> getNamespaceBindings() {
119    return _namespaceBindings;
120  }
121
122  public void setNamespaceBindings(List<MetapathNamespace> value) {
123    _namespaceBindings = value;
124  }
125
126  /**
127   * Add a new {@link MetapathNamespace} item to the underlying collection.
128   * @param item the item to add
129   * @return {@code true}
130   */
131  public boolean addNamespaceBinding(MetapathNamespace item) {
132    MetapathNamespace value = ObjectUtils.requireNonNull(item,"item cannot be null");
133    if (_namespaceBindings == null) {
134      _namespaceBindings = new LinkedList<>();
135    }
136    return _namespaceBindings.add(value);
137  }
138
139  /**
140   * Remove the first matching {@link MetapathNamespace} item from the underlying collection.
141   * @param item the item to remove
142   * @return {@code true} if the item was removed or {@code false} otherwise
143   */
144  public boolean removeNamespaceBinding(MetapathNamespace item) {
145    MetapathNamespace value = ObjectUtils.requireNonNull(item,"item cannot be null");
146    return _namespaceBindings != null && _namespaceBindings.remove(value);
147  }
148
149  public DefinitionContext getDefinitionContext() {
150    return _definitionContext;
151  }
152
153  public void setDefinitionContext(DefinitionContext value) {
154    _definitionContext = value;
155  }
156
157  public List<MetapathContext> getContexts() {
158    return _contexts;
159  }
160
161  public void setContexts(List<MetapathContext> value) {
162    _contexts = value;
163  }
164
165  /**
166   * Add a new {@link MetapathContext} item to the underlying collection.
167   * @param item the item to add
168   * @return {@code true}
169   */
170  public boolean addContext(MetapathContext item) {
171    MetapathContext value = ObjectUtils.requireNonNull(item,"item cannot be null");
172    if (_contexts == null) {
173      _contexts = new LinkedList<>();
174    }
175    return _contexts.add(value);
176  }
177
178  /**
179   * Remove the first matching {@link MetapathContext} item from the underlying collection.
180   * @param item the item to remove
181   * @return {@code true} if the item was removed or {@code false} otherwise
182   */
183  public boolean removeContext(MetapathContext item) {
184    MetapathContext value = ObjectUtils.requireNonNull(item,"item cannot be null");
185    return _contexts != null && _contexts.remove(value);
186  }
187
188  @Override
189  public String toString() {
190    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
191  }
192
193  /**
194   * Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.
195   */
196  @MetaschemaAssembly(
197      description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.",
198      name = "import",
199      moduleClass = MetaschemaModelModule.class
200  )
201  public static class Import implements IBoundObject {
202    private final IMetaschemaData __metaschemaData;
203
204    /**
205     * "A relative or absolute URI for retrieving an out-of-line Metaschema constraint definition."
206     */
207    @BoundFlag(
208        description = "A relative or absolute URI for retrieving an out-of-line Metaschema constraint definition.",
209        name = "href",
210        required = true,
211        typeAdapter = UriReferenceAdapter.class
212    )
213    private URI _href;
214
215    public Import() {
216      this(null);
217    }
218
219    public Import(IMetaschemaData data) {
220      this.__metaschemaData = data;
221    }
222
223    @Override
224    public IMetaschemaData getMetaschemaData() {
225      return __metaschemaData;
226    }
227
228    public URI getHref() {
229      return _href;
230    }
231
232    public void setHref(URI value) {
233      _href = value;
234    }
235
236    @Override
237    public String toString() {
238      return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
239    }
240  }
241
242  @MetaschemaAssembly(
243      name = "definition-context",
244      moduleClass = MetaschemaModelModule.class
245  )
246  public static class DefinitionContext implements IBoundObject {
247    private final IMetaschemaData __metaschemaData;
248
249    @BoundFlag(
250        name = "name",
251        required = true,
252        typeAdapter = TokenAdapter.class
253    )
254    private String _name;
255
256    @BoundFlag(
257        name = "namespace",
258        required = true,
259        typeAdapter = UriAdapter.class
260    )
261    private URI _namespace;
262
263    @BoundAssembly(
264        useName = "constraints",
265        minOccurs = 1
266    )
267    private AssemblyConstraints _constraints;
268
269    @BoundField(
270        formalName = "Remarks",
271        description = "Any explanatory or helpful information to be provided about the remarks parent.",
272        useName = "remarks"
273    )
274    private Remarks _remarks;
275
276    public DefinitionContext() {
277      this(null);
278    }
279
280    public DefinitionContext(IMetaschemaData data) {
281      this.__metaschemaData = data;
282    }
283
284    @Override
285    public IMetaschemaData getMetaschemaData() {
286      return __metaschemaData;
287    }
288
289    public String getName() {
290      return _name;
291    }
292
293    public void setName(String value) {
294      _name = value;
295    }
296
297    public URI getNamespace() {
298      return _namespace;
299    }
300
301    public void setNamespace(URI value) {
302      _namespace = value;
303    }
304
305    public AssemblyConstraints getConstraints() {
306      return _constraints;
307    }
308
309    public void setConstraints(AssemblyConstraints value) {
310      _constraints = value;
311    }
312
313    public Remarks getRemarks() {
314      return _remarks;
315    }
316
317    public void setRemarks(Remarks value) {
318      _remarks = value;
319    }
320
321    @Override
322    public String toString() {
323      return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
324    }
325  }
326}