Skip to content

Commit 8a2275a

Browse files
interim commit
1 parent 2918db8 commit 8a2275a

12 files changed

+206
-270
lines changed

core/src/main/java/gov/nist/secauto/metaschema/core/model/FlagContainerBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public IContainerFlagSupport<T> build() {
7373
Map<QName, T> flagMap = CollectionUtil.unmodifiableMap(ObjectUtils.notNull(flags.stream()
7474
.collect(
7575
CustomCollectors.toMap(
76-
INamedModelElement::getXmlQName,
76+
INamed::getXmlQName,
7777
CustomCollectors.identity(),
7878
FlagContainerBuilder::handleShadowedInstances,
7979
LinkedHashMap::new))));

core/src/main/java/gov/nist/secauto/metaschema/core/model/IDescribable.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,28 @@ public interface IDescribable {
4848
// from INamedModelElement
4949
@Nullable
5050
MarkupLine getDescription();
51+
52+
/**
53+
* The resolved formal display name, which allows an instance to override a
54+
* definition's name.
55+
*
56+
* @return the formal name or {@code null} if not defined
57+
*/
58+
// from INamedModelElement
59+
@Nullable
60+
default String getEffectiveFormalName() {
61+
return getFormalName();
62+
}
63+
64+
/**
65+
* Get the text that describes the basic use of the element, which allows an
66+
* instance to override a definition's description.
67+
*
68+
* @return a line of markup text or {@code null} if not defined
69+
*/
70+
// from INamedModelElement
71+
@Nullable
72+
default MarkupLine getEffectiveDescription() {
73+
return getDescription();
74+
}
5175
}
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
2525
*/
2626

27-
package gov.nist.secauto.metaschema.databind.model;
27+
package gov.nist.secauto.metaschema.core.model;
2828

29-
import gov.nist.secauto.metaschema.core.model.INamedInstance;
29+
import edu.umd.cs.findbugs.annotations.NonNull;
3030

31-
public interface IBoundInstanceNamed extends IBoundInstance, INamedInstance {
31+
public interface IJsonNamed {
3232

33-
@Override
34-
default String getJsonName() {
35-
// needed to avoid conflict between IBoundInstance and INamedInstance
36-
return INamedInstance.super.getJsonName();
37-
}
33+
/**
34+
* Get the name used for the associated property in JSON/YAML
35+
* serialization-related operations.
36+
*
37+
* @return the JSON property name
38+
*/
39+
@NonNull
40+
String getJsonName();
3841
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Portions of this software was developed by employees of the National Institute
3+
* of Standards and Technology (NIST), an agency of the Federal Government and is
4+
* being made available as a public service. Pursuant to title 17 United States
5+
* Code Section 105, works of NIST employees are not subject to copyright
6+
* protection in the United States. This software may be subject to foreign
7+
* copyright. Permission in the United States and in foreign countries, to the
8+
* extent that NIST may hold copyright, to use, copy, modify, create derivative
9+
* works, and distribute this software and its documentation without fee is hereby
10+
* granted on a non-exclusive basis, provided that this notice and disclaimer
11+
* of warranty appears in all copies.
12+
*
13+
* THE SOFTWARE IS PROVIDED 'AS IS' WITHOUT ANY WARRANTY OF ANY KIND, EITHER
14+
* EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
15+
* THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND FREEDOM FROM
17+
* INFRINGEMENT, AND ANY WARRANTY THAT THE DOCUMENTATION WILL CONFORM TO THE
18+
* SOFTWARE, OR ANY WARRANTY THAT THE SOFTWARE WILL BE ERROR FREE. IN NO EVENT
19+
* SHALL NIST BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT,
20+
* INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM,
21+
* OR IN ANY WAY CONNECTED WITH THIS SOFTWARE, WHETHER OR NOT BASED UPON WARRANTY,
22+
* CONTRACT, TORT, OR OTHERWISE, WHETHER OR NOT INJURY WAS SUSTAINED BY PERSONS OR
23+
* PROPERTY OR OTHERWISE, AND WHETHER OR NOT LOSS WAS SUSTAINED FROM, OR AROSE OUT
24+
* OF THE RESULTS OF, OR USE OF, THE SOFTWARE OR SERVICES PROVIDED HEREUNDER.
25+
*/
26+
27+
package gov.nist.secauto.metaschema.core.model;
28+
29+
import javax.xml.XMLConstants;
30+
import javax.xml.namespace.QName;
31+
32+
import edu.umd.cs.findbugs.annotations.NonNull;
33+
import edu.umd.cs.findbugs.annotations.Nullable;
34+
35+
public interface INamed {
36+
37+
/**
38+
* Retrieve the name of the model element.
39+
*
40+
* @return the name
41+
*/
42+
@NonNull
43+
String getName();
44+
45+
/**
46+
* Retrieve the name to use for the model element, instead of the name.
47+
*
48+
* @return the use name or {@code null} if no use name is defined
49+
*/
50+
// from INamedModelElement
51+
@Nullable
52+
default String getUseName() {
53+
// no use-name by default
54+
return null;
55+
}
56+
57+
/**
58+
* Get the name to use based on the provided names. This method will return the
59+
* use name provided by {@link #getUseName()} if the call is not {@code null},
60+
* and fall back to the name provided by {@link #getName()} otherwise. This is
61+
* the model name to use for the for an instance where the instance is
62+
* referenced.
63+
*
64+
* @return the use name if available, or the name if not
65+
*
66+
* @see #getUseName()
67+
* @see #getName()
68+
*/
69+
// from INamedModelElement
70+
@NonNull
71+
default String getEffectiveName() {
72+
@Nullable String useName = getUseName();
73+
return useName == null ? getName() : useName;
74+
}
75+
76+
/**
77+
* Retrieve the XML namespace for this instance.
78+
* <p>
79+
* Multiple calls to this method are expected to produce the same, deterministic
80+
* return value.
81+
*
82+
* @return the XML namespace or {@code null} if no namespace is defined
83+
*/
84+
@Nullable
85+
default String getXmlNamespace() {
86+
return getXmlQName().getNamespaceURI();
87+
}
88+
89+
/**
90+
* Get the unique XML qualified name for this model element.
91+
* <p>
92+
* The qualified name is considered to be unique relative to all sibling
93+
* elements. For a flag, this name will be unique among all flag instances on
94+
* the same field or assembly definition. For a field or assembly, this name
95+
* will be unique among all sibling field or assembly instances on the same
96+
* assembly definition.
97+
* <p>
98+
* Multiple calls to this method are expected to produce the same, deterministic
99+
* return value.
100+
* <p>
101+
* If {@link #getXmlNamespace()} is {@code null}, the the resulting QName will
102+
* have the namespace {@link XMLConstants#NULL_NS_URI}.
103+
* <p>
104+
* This implementation may be overridden by implementation that cache the QName
105+
* or provide for a more efficient method for QName creation.
106+
*
107+
* @return the XML qualified name, or {@code null} if there isn't one
108+
*/
109+
// REFACTOR: rename to getQName
110+
@NonNull
111+
QName getXmlQName();
112+
113+
/**
114+
* Retrieve the index value to use for binary naming.
115+
*
116+
* @return the name index or {@code null} if no name index is defined
117+
*/
118+
// from INamedModelElement
119+
@Nullable
120+
default Integer getIndex() {
121+
// no index by default
122+
return null;
123+
}
124+
125+
/**
126+
* Retrieve the index value to use for binary naming, instead of the name.
127+
*
128+
* @return the use name index or {@code null} if no use name index is defined
129+
*/
130+
// from INamedModelElement
131+
@Nullable
132+
default Integer getUseIndex() {
133+
// no use-name index by default
134+
return null;
135+
}
136+
137+
/**
138+
* Get the index value to use for binary naming based on the provided index
139+
* values.
140+
* <p>
141+
* This method will return the use index value provided by
142+
* {@link #getUseIndex()} if the call result is not {@code null}, and fall back
143+
* to the index value provided by {@link #getIndex()} otherwise.
144+
*
145+
* @return the index value if available, or {@code null} otherwise
146+
*/
147+
// from INamedModelElement
148+
@Nullable
149+
default Integer getEffectiveIndex() {
150+
@Nullable Integer useIndex = getUseIndex();
151+
return useIndex == null ? getIndex() : useIndex;
152+
}
153+
}

core/src/main/java/gov/nist/secauto/metaschema/core/model/INamedModelElement.java

Lines changed: 2 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -26,167 +26,15 @@
2626

2727
package gov.nist.secauto.metaschema.core.model;
2828

29-
import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
30-
31-
import javax.xml.XMLConstants;
32-
import javax.xml.namespace.QName;
33-
3429
import edu.umd.cs.findbugs.annotations.NonNull;
35-
import edu.umd.cs.findbugs.annotations.Nullable;
3630

3731
/**
3832
* A marker interface for Metaschema constructs that can be members of a
3933
* Metaschema module's model that have a name and other identifying
4034
* characteristics.
4135
*/
42-
public interface INamedModelElement extends IDescribable, IModelElement {
43-
/**
44-
* The resolved formal display name, which allows an instance to override a
45-
* definition's name.
46-
*
47-
* @return the formal name or {@code null} if not defined
48-
*/
49-
// from INamedModelElement
50-
@Nullable
51-
default String getEffectiveFormalName() {
52-
return getFormalName();
53-
}
54-
55-
/**
56-
* Get the text that describes the basic use of the element, which allows an
57-
* instance to override a definition's description.
58-
*
59-
* @return a line of markup text or {@code null} if not defined
60-
*/
61-
// from INamedModelElement
62-
@Nullable
63-
default MarkupLine getEffectiveDescription() {
64-
return getDescription();
65-
}
66-
67-
/**
68-
* Retrieve the name of the model element.
69-
*
70-
* @return the name
71-
*/
72-
@NonNull
73-
String getName();
74-
75-
/**
76-
* Retrieve the name to use for the model element, instead of the name.
77-
*
78-
* @return the use name or {@code null} if no use name is defined
79-
*/
80-
// from INamedModelElement
81-
@Nullable
82-
default String getUseName() {
83-
// no use-name by default
84-
return null;
85-
}
86-
87-
/**
88-
* Get the name to use based on the provided names. This method will return the
89-
* use name provided by {@link #getUseName()} if the call is not {@code null},
90-
* and fall back to the name provided by {@link #getName()} otherwise. This is
91-
* the model name to use for the for an instance where the instance is
92-
* referenced.
93-
*
94-
* @return the use name if available, or the name if not
95-
*
96-
* @see #getUseName()
97-
* @see #getName()
98-
*/
99-
// from INamedModelElement
100-
@NonNull
101-
default String getEffectiveName() {
102-
@Nullable String useName = getUseName();
103-
return useName == null ? getName() : useName;
104-
}
105-
106-
/**
107-
* Retrieve the XML namespace for this instance.
108-
* <p>
109-
* Multiple calls to this method are expected to produce the same, deterministic
110-
* return value.
111-
*
112-
* @return the XML namespace or {@code null} if no namespace is defined
113-
*/
114-
@Nullable
115-
default String getXmlNamespace() {
116-
return getXmlQName().getNamespaceURI();
117-
}
118-
119-
/**
120-
* Get the unique XML qualified name for this model element.
121-
* <p>
122-
* The qualified name is considered to be unique relative to all sibling
123-
* elements. For a flag, this name will be unique among all flag instances on
124-
* the same field or assembly definition. For a field or assembly, this name
125-
* will be unique among all sibling field or assembly instances on the same
126-
* assembly definition.
127-
* <p>
128-
* Multiple calls to this method are expected to produce the same, deterministic
129-
* return value.
130-
* <p>
131-
* If {@link #getXmlNamespace()} is {@code null}, the the resulting QName will
132-
* have the namespace {@link XMLConstants#NULL_NS_URI}.
133-
* <p>
134-
* This implementation may be overridden by implementation that cache the QName
135-
* or provide for a more efficient method for QName creation.
136-
*
137-
* @return the XML qualified name, or {@code null} if there isn't one
138-
*/
139-
// REFACTOR: rename to getQName
140-
@NonNull
141-
QName getXmlQName();
142-
143-
/**
144-
* Retrieve the index value to use for binary naming.
145-
*
146-
* @return the name index or {@code null} if no name index is defined
147-
*/
148-
// from INamedModelElement
149-
@Nullable
150-
default Integer getIndex() {
151-
// no index by default
152-
return null;
153-
}
154-
155-
/**
156-
* Retrieve the index value to use for binary naming, instead of the name.
157-
*
158-
* @return the use name index or {@code null} if no use name index is defined
159-
*/
160-
// from INamedModelElement
161-
@Nullable
162-
default Integer getUseIndex() {
163-
// no use-name index by default
164-
return null;
165-
}
166-
167-
/**
168-
* Get the index value to use for binary naming based on the provided index
169-
* values.
170-
* <p>
171-
* This method will return the use index value provided by
172-
* {@link #getUseIndex()} if the call result is not {@code null}, and fall back
173-
* to the index value provided by {@link #getIndex()} otherwise.
174-
*
175-
* @return the index value if available, or {@code null} otherwise
176-
*/
177-
// from INamedModelElement
178-
@Nullable
179-
default Integer getEffectiveIndex() {
180-
@Nullable Integer useIndex = getUseIndex();
181-
return useIndex == null ? getIndex() : useIndex;
182-
}
183-
184-
/**
185-
* Get the name used for the associated property in JSON/YAML.
186-
*
187-
* @return the JSON property name
188-
*/
189-
// from INamedModelElement
36+
public interface INamedModelElement extends IDescribable, IModelElement, IJsonNamed, INamed {
37+
@Override
19038
@NonNull
19139
default String getJsonName() {
19240
return getEffectiveName();

databind/src/main/java/gov/nist/secauto/metaschema/databind/DefaultBindingContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,6 @@ public <CLASS> CLASS deepCopy(@NonNull CLASS other, Object parentInstance) throw
322322
if (definition == null) {
323323
throw new IllegalStateException(String.format("Class '%s' is not bound", other.getClass().getName()));
324324
}
325-
return (CLASS) definition.deepCopyItem(other, parentInstance);
325+
return ObjectUtils.asType(definition.deepCopyItem(other, parentInstance));
326326
}
327327
}

0 commit comments

Comments
 (0)