001package com.example.metaschema; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; 004import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; 005import gov.nist.secauto.metaschema.core.datatype.adapter.UriAdapter; 006import gov.nist.secauto.metaschema.core.datatype.adapter.UriReferenceAdapter; 007import gov.nist.secauto.metaschema.core.model.IBoundObject; 008import gov.nist.secauto.metaschema.core.model.IMetaschemaData; 009import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; 010import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; 011import gov.nist.secauto.metaschema.core.util.ObjectUtils; 012import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; 013import gov.nist.secauto.metaschema.databind.model.annotations.BoundChoiceGroup; 014import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 015import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; 016import gov.nist.secauto.metaschema.databind.model.annotations.BoundGroupedAssembly; 017import gov.nist.secauto.metaschema.databind.model.annotations.Expect; 018import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 019import gov.nist.secauto.metaschema.databind.model.annotations.Let; 020import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 021import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 022import java.lang.Object; 023import java.lang.Override; 024import java.lang.String; 025import java.net.URI; 026import java.util.LinkedList; 027import java.util.List; 028import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 029import org.apache.commons.lang3.builder.ToStringStyle; 030 031/** 032 * Defines constraint rules to be applied to an existing set of Metaschema module-based models. 033 */ 034@MetaschemaAssembly( 035 formalName = "External Module Constraints", 036 description = "Defines constraint rules to be applied to an existing set of Metaschema module-based models.", 037 name = "metaschema-module-constraints", 038 moduleClass = MetaschemaModelModule.class, 039 rootName = "METASCHEMA-CONSTRAINTS", 040 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.")) 041) 042public class MetaschemaModuleConstraints implements IBoundObject { 043 private final IMetaschemaData __metaschemaData; 044 045 @BoundField( 046 description = "The name of this constraint set.", 047 useName = "name", 048 minOccurs = 1 049 ) 050 private String _name; 051 052 @BoundField( 053 description = "The version of this constraint set. A version string used to distinguish between multiple revisions of the same resource.", 054 useName = "version", 055 minOccurs = 1 056 ) 057 private String _version; 058 059 @BoundAssembly( 060 description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.", 061 useName = "import", 062 maxOccurs = -1, 063 groupAs = @GroupAs(name = "imports", inJson = JsonGroupAsBehavior.LIST) 064 ) 065 private List<Import> _imports; 066 067 @BoundAssembly( 068 formalName = "Metapath Namespace Declaration", 069 description = "Assigns a Metapath namespace to a prefix for use in a Metapath expression in a lexical qualified name.", 070 useName = "namespace-binding", 071 maxOccurs = -1, 072 groupAs = @GroupAs(name = "namespace-bindings") 073 ) 074 private List<MetapathNamespace> _namespaceBindings; 075 076 @BoundAssembly( 077 useName = "scope", 078 minOccurs = 1, 079 maxOccurs = -1, 080 groupAs = @GroupAs(name = "scopes", inJson = JsonGroupAsBehavior.LIST) 081 ) 082 private List<Scope> _scopes; 083 084 public MetaschemaModuleConstraints() { 085 this(null); 086 } 087 088 public MetaschemaModuleConstraints(IMetaschemaData data) { 089 this.__metaschemaData = data; 090 } 091 092 @Override 093 public IMetaschemaData getMetaschemaData() { 094 return __metaschemaData; 095 } 096 097 public String getName() { 098 return _name; 099 } 100 101 public void setName(String value) { 102 _name = value; 103 } 104 105 public String getVersion() { 106 return _version; 107 } 108 109 public void setVersion(String value) { 110 _version = value; 111 } 112 113 public List<Import> getImports() { 114 return _imports; 115 } 116 117 public void setImports(List<Import> value) { 118 _imports = value; 119 } 120 121 /** 122 * Add a new {@link Import} item to the underlying collection. 123 * @param item the item to add 124 * @return {@code true} 125 */ 126 public boolean addImport(Import item) { 127 Import value = ObjectUtils.requireNonNull(item,"item cannot be null"); 128 if (_imports == null) { 129 _imports = new LinkedList<>(); 130 } 131 return _imports.add(value); 132 } 133 134 /** 135 * Remove the first matching {@link Import} item from the underlying collection. 136 * @param item the item to remove 137 * @return {@code true} if the item was removed or {@code false} otherwise 138 */ 139 public boolean removeImport(Import item) { 140 Import value = ObjectUtils.requireNonNull(item,"item cannot be null"); 141 return _imports != null && _imports.remove(value); 142 } 143 144 public List<MetapathNamespace> getNamespaceBindings() { 145 return _namespaceBindings; 146 } 147 148 public void setNamespaceBindings(List<MetapathNamespace> value) { 149 _namespaceBindings = value; 150 } 151 152 /** 153 * Add a new {@link MetapathNamespace} item to the underlying collection. 154 * @param item the item to add 155 * @return {@code true} 156 */ 157 public boolean addNamespaceBinding(MetapathNamespace item) { 158 MetapathNamespace value = ObjectUtils.requireNonNull(item,"item cannot be null"); 159 if (_namespaceBindings == null) { 160 _namespaceBindings = new LinkedList<>(); 161 } 162 return _namespaceBindings.add(value); 163 } 164 165 /** 166 * Remove the first matching {@link MetapathNamespace} item from the underlying collection. 167 * @param item the item to remove 168 * @return {@code true} if the item was removed or {@code false} otherwise 169 */ 170 public boolean removeNamespaceBinding(MetapathNamespace item) { 171 MetapathNamespace value = ObjectUtils.requireNonNull(item,"item cannot be null"); 172 return _namespaceBindings != null && _namespaceBindings.remove(value); 173 } 174 175 public List<Scope> getScopes() { 176 return _scopes; 177 } 178 179 public void setScopes(List<Scope> value) { 180 _scopes = value; 181 } 182 183 /** 184 * Add a new {@link Scope} item to the underlying collection. 185 * @param item the item to add 186 * @return {@code true} 187 */ 188 public boolean addScope(Scope item) { 189 Scope value = ObjectUtils.requireNonNull(item,"item cannot be null"); 190 if (_scopes == null) { 191 _scopes = new LinkedList<>(); 192 } 193 return _scopes.add(value); 194 } 195 196 /** 197 * Remove the first matching {@link Scope} item from the underlying collection. 198 * @param item the item to remove 199 * @return {@code true} if the item was removed or {@code false} otherwise 200 */ 201 public boolean removeScope(Scope item) { 202 Scope value = ObjectUtils.requireNonNull(item,"item cannot be null"); 203 return _scopes != null && _scopes.remove(value); 204 } 205 206 @Override 207 public String toString() { 208 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 209 } 210 211 /** 212 * Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets. 213 */ 214 @MetaschemaAssembly( 215 description = "Declares a set of Metaschema constraints from an out-of-line resource to import, supporting composition of constraint sets.", 216 name = "import", 217 moduleClass = MetaschemaModelModule.class 218 ) 219 public static class Import implements IBoundObject { 220 private final IMetaschemaData __metaschemaData; 221 222 /** 223 * "A relative or absolute URI for retrieving an out-of-line Metaschema constraint definition." 224 */ 225 @BoundFlag( 226 description = "A relative or absolute URI for retrieving an out-of-line Metaschema constraint definition.", 227 name = "href", 228 required = true, 229 typeAdapter = UriReferenceAdapter.class 230 ) 231 private URI _href; 232 233 public Import() { 234 this(null); 235 } 236 237 public Import(IMetaschemaData data) { 238 this.__metaschemaData = data; 239 } 240 241 @Override 242 public IMetaschemaData getMetaschemaData() { 243 return __metaschemaData; 244 } 245 246 public URI getHref() { 247 return _href; 248 } 249 250 public void setHref(URI value) { 251 _href = value; 252 } 253 254 @Override 255 public String toString() { 256 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 257 } 258 } 259 260 @MetaschemaAssembly( 261 name = "scope", 262 moduleClass = MetaschemaModelModule.class 263 ) 264 public static class Scope implements IBoundObject { 265 private final IMetaschemaData __metaschemaData; 266 267 @BoundFlag( 268 name = "metaschema-namespace", 269 required = true, 270 typeAdapter = UriAdapter.class 271 ) 272 private URI _metaschemaNamespace; 273 274 @BoundFlag( 275 name = "metaschema-short-name", 276 required = true, 277 typeAdapter = TokenAdapter.class 278 ) 279 private String _metaschemaShortName; 280 281 @BoundChoiceGroup( 282 minOccurs = 1, 283 maxOccurs = -1, 284 assemblies = { 285 @BoundGroupedAssembly(useName = "assembly", binding = Assembly.class), 286 @BoundGroupedAssembly(useName = "field", binding = Field.class), 287 @BoundGroupedAssembly(useName = "flag", binding = Flag.class) 288 }, 289 groupAs = @GroupAs(name = "constraints", inJson = JsonGroupAsBehavior.LIST) 290 ) 291 private List<Object> _constraints; 292 293 @BoundField( 294 formalName = "Constraint Condition Violation Message", 295 useName = "message" 296 ) 297 private String _message; 298 299 @BoundField( 300 formalName = "Remarks", 301 description = "Any explanatory or helpful information to be provided about the remarks parent.", 302 useName = "remarks" 303 ) 304 private Remarks _remarks; 305 306 public Scope() { 307 this(null); 308 } 309 310 public Scope(IMetaschemaData data) { 311 this.__metaschemaData = data; 312 } 313 314 @Override 315 public IMetaschemaData getMetaschemaData() { 316 return __metaschemaData; 317 } 318 319 public URI getMetaschemaNamespace() { 320 return _metaschemaNamespace; 321 } 322 323 public void setMetaschemaNamespace(URI value) { 324 _metaschemaNamespace = value; 325 } 326 327 public String getMetaschemaShortName() { 328 return _metaschemaShortName; 329 } 330 331 public void setMetaschemaShortName(String value) { 332 _metaschemaShortName = value; 333 } 334 335 public List<Object> getConstraints() { 336 return _constraints; 337 } 338 339 public void setConstraints(List<Object> value) { 340 _constraints = value; 341 } 342 343 public String getMessage() { 344 return _message; 345 } 346 347 public void setMessage(String value) { 348 _message = value; 349 } 350 351 public Remarks getRemarks() { 352 return _remarks; 353 } 354 355 public void setRemarks(Remarks value) { 356 _remarks = value; 357 } 358 359 @Override 360 public String toString() { 361 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 362 } 363 364 @MetaschemaAssembly( 365 name = "assembly", 366 moduleClass = MetaschemaModelModule.class 367 ) 368 public static class Assembly implements IBoundObject { 369 private final IMetaschemaData __metaschemaData; 370 371 @BoundFlag( 372 formalName = "Constraint Target Metapath Expression", 373 name = "target", 374 required = true, 375 typeAdapter = StringAdapter.class 376 ) 377 private String _target; 378 379 @BoundChoiceGroup( 380 minOccurs = 1, 381 maxOccurs = -1, 382 assemblies = { 383 @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", binding = TargetedAllowedValuesConstraint.class), 384 @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", binding = TargetedExpectConstraint.class), 385 @BoundGroupedAssembly(formalName = "Targeted Index Has Key Constraint", useName = "index-has-key", binding = TargetedIndexHasKeyConstraint.class), 386 @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class), 387 @BoundGroupedAssembly(formalName = "Targeted Unique Constraint", useName = "is-unique", binding = TargetedIsUniqueConstraint.class), 388 @BoundGroupedAssembly(formalName = "Targeted Index Constraint", useName = "index", binding = TargetedIndexConstraint.class), 389 @BoundGroupedAssembly(formalName = "Targeted Cardinality Constraint", useName = "has-cardinality", binding = TargetedHasCardinalityConstraint.class) 390 }, 391 groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST) 392 ) 393 private List<Object> _rules; 394 395 public Assembly() { 396 this(null); 397 } 398 399 public Assembly(IMetaschemaData data) { 400 this.__metaschemaData = data; 401 } 402 403 @Override 404 public IMetaschemaData getMetaschemaData() { 405 return __metaschemaData; 406 } 407 408 public String getTarget() { 409 return _target; 410 } 411 412 public void setTarget(String value) { 413 _target = value; 414 } 415 416 public List<Object> getRules() { 417 return _rules; 418 } 419 420 public void setRules(List<Object> value) { 421 _rules = value; 422 } 423 424 @Override 425 public String toString() { 426 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 427 } 428 } 429 430 @MetaschemaAssembly( 431 name = "field", 432 moduleClass = MetaschemaModelModule.class 433 ) 434 public static class Field implements IBoundObject { 435 private final IMetaschemaData __metaschemaData; 436 437 @BoundFlag( 438 formalName = "Constraint Target Metapath Expression", 439 name = "target", 440 required = true, 441 typeAdapter = StringAdapter.class 442 ) 443 private String _target; 444 445 @BoundChoiceGroup( 446 minOccurs = 1, 447 maxOccurs = -1, 448 assemblies = { 449 @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", binding = TargetedAllowedValuesConstraint.class), 450 @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", binding = TargetedExpectConstraint.class), 451 @BoundGroupedAssembly(formalName = "Targeted Index Has Key Constraint", useName = "index-has-key", binding = TargetedIndexHasKeyConstraint.class), 452 @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class) 453 }, 454 groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST) 455 ) 456 private List<Object> _rules; 457 458 public Field() { 459 this(null); 460 } 461 462 public Field(IMetaschemaData data) { 463 this.__metaschemaData = data; 464 } 465 466 @Override 467 public IMetaschemaData getMetaschemaData() { 468 return __metaschemaData; 469 } 470 471 public String getTarget() { 472 return _target; 473 } 474 475 public void setTarget(String value) { 476 _target = value; 477 } 478 479 public List<Object> getRules() { 480 return _rules; 481 } 482 483 public void setRules(List<Object> value) { 484 _rules = value; 485 } 486 487 @Override 488 public String toString() { 489 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 490 } 491 } 492 493 @MetaschemaAssembly( 494 name = "flag", 495 moduleClass = MetaschemaModelModule.class 496 ) 497 public static class Flag implements IBoundObject { 498 private final IMetaschemaData __metaschemaData; 499 500 @BoundFlag( 501 formalName = "Constraint Target Metapath Expression", 502 name = "target", 503 required = true, 504 typeAdapter = StringAdapter.class 505 ) 506 private String _target; 507 508 @BoundChoiceGroup( 509 minOccurs = 1, 510 maxOccurs = -1, 511 assemblies = { 512 @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", binding = FlagAllowedValues.class), 513 @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", binding = FlagExpect.class), 514 @BoundGroupedAssembly(formalName = "Index Has Key Constraint", useName = "index-has-key", binding = FlagIndexHasKey.class), 515 @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = FlagMatches.class) 516 }, 517 groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST) 518 ) 519 private List<Object> _rules; 520 521 public Flag() { 522 this(null); 523 } 524 525 public Flag(IMetaschemaData data) { 526 this.__metaschemaData = data; 527 } 528 529 @Override 530 public IMetaschemaData getMetaschemaData() { 531 return __metaschemaData; 532 } 533 534 public String getTarget() { 535 return _target; 536 } 537 538 public void setTarget(String value) { 539 _target = value; 540 } 541 542 public List<Object> getRules() { 543 return _rules; 544 } 545 546 public void setRules(List<Object> value) { 547 _rules = value; 548 } 549 550 @Override 551 public String toString() { 552 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 553 } 554 } 555 } 556}