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", inJson = JsonGroupAsBehavior.LIST) 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 groupAs = @GroupAs(name = "constraints", inJson = JsonGroupAsBehavior.LIST), 285 assemblies = { 286 @BoundGroupedAssembly(useName = "assembly", binding = Assembly.class), 287 @BoundGroupedAssembly(useName = "field", binding = Field.class), 288 @BoundGroupedAssembly(useName = "flag", binding = Flag.class) 289 } 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 groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST), 383 assemblies = { 384 @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", binding = TargetedAllowedValuesConstraint.class), 385 @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", binding = TargetedExpectConstraint.class), 386 @BoundGroupedAssembly(formalName = "Targeted Index Has Key Constraint", useName = "index-has-key", binding = TargetedIndexHasKeyConstraint.class), 387 @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class), 388 @BoundGroupedAssembly(formalName = "Targeted Unique Constraint", useName = "is-unique", binding = TargetedIsUniqueConstraint.class), 389 @BoundGroupedAssembly(formalName = "Targeted Index Constraint", useName = "index", binding = TargetedIndexConstraint.class), 390 @BoundGroupedAssembly(formalName = "Targeted Cardinality Constraint", useName = "has-cardinality", binding = TargetedHasCardinalityConstraint.class), 391 @BoundGroupedAssembly(formalName = "Report Condition Constraint", useName = "report", binding = TargetedReportConstraint.class) 392 } 393 ) 394 private List<Object> _rules; 395 396 public Assembly() { 397 this(null); 398 } 399 400 public Assembly(IMetaschemaData data) { 401 this.__metaschemaData = data; 402 } 403 404 @Override 405 public IMetaschemaData getMetaschemaData() { 406 return __metaschemaData; 407 } 408 409 public String getTarget() { 410 return _target; 411 } 412 413 public void setTarget(String value) { 414 _target = value; 415 } 416 417 public List<Object> getRules() { 418 return _rules; 419 } 420 421 public void setRules(List<Object> value) { 422 _rules = value; 423 } 424 425 @Override 426 public String toString() { 427 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 428 } 429 } 430 431 @MetaschemaAssembly( 432 name = "field", 433 moduleClass = MetaschemaModelModule.class 434 ) 435 public static class Field implements IBoundObject { 436 private final IMetaschemaData __metaschemaData; 437 438 @BoundFlag( 439 formalName = "Constraint Target Metapath Expression", 440 name = "target", 441 required = true, 442 typeAdapter = StringAdapter.class 443 ) 444 private String _target; 445 446 @BoundChoiceGroup( 447 minOccurs = 1, 448 maxOccurs = -1, 449 groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST), 450 assemblies = { 451 @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", binding = TargetedAllowedValuesConstraint.class), 452 @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", binding = TargetedExpectConstraint.class), 453 @BoundGroupedAssembly(formalName = "Targeted Index Has Key Constraint", useName = "index-has-key", binding = TargetedIndexHasKeyConstraint.class), 454 @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class), 455 @BoundGroupedAssembly(formalName = "Report Condition Constraint", useName = "report", binding = TargetedReportConstraint.class) 456 } 457 ) 458 private List<Object> _rules; 459 460 public Field() { 461 this(null); 462 } 463 464 public Field(IMetaschemaData data) { 465 this.__metaschemaData = data; 466 } 467 468 @Override 469 public IMetaschemaData getMetaschemaData() { 470 return __metaschemaData; 471 } 472 473 public String getTarget() { 474 return _target; 475 } 476 477 public void setTarget(String value) { 478 _target = value; 479 } 480 481 public List<Object> getRules() { 482 return _rules; 483 } 484 485 public void setRules(List<Object> value) { 486 _rules = value; 487 } 488 489 @Override 490 public String toString() { 491 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 492 } 493 } 494 495 @MetaschemaAssembly( 496 name = "flag", 497 moduleClass = MetaschemaModelModule.class 498 ) 499 public static class Flag implements IBoundObject { 500 private final IMetaschemaData __metaschemaData; 501 502 @BoundFlag( 503 formalName = "Constraint Target Metapath Expression", 504 name = "target", 505 required = true, 506 typeAdapter = StringAdapter.class 507 ) 508 private String _target; 509 510 @BoundChoiceGroup( 511 minOccurs = 1, 512 maxOccurs = -1, 513 groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST), 514 assemblies = { 515 @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", binding = FlagAllowedValues.class), 516 @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", binding = FlagExpect.class), 517 @BoundGroupedAssembly(formalName = "Index Has Key Constraint", useName = "index-has-key", binding = FlagIndexHasKey.class), 518 @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = FlagMatches.class), 519 @BoundGroupedAssembly(formalName = "Report Condition Constraint", useName = "report", binding = FlagReport.class) 520 } 521 ) 522 private List<Object> _rules; 523 524 public Flag() { 525 this(null); 526 } 527 528 public Flag(IMetaschemaData data) { 529 this.__metaschemaData = data; 530 } 531 532 @Override 533 public IMetaschemaData getMetaschemaData() { 534 return __metaschemaData; 535 } 536 537 public String getTarget() { 538 return _target; 539 } 540 541 public void setTarget(String value) { 542 _target = value; 543 } 544 545 public List<Object> getRules() { 546 return _rules; 547 } 548 549 public void setRules(List<Object> value) { 550 _rules = value; 551 } 552 553 @Override 554 public String toString() { 555 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 556 } 557 } 558 } 559}