null
. null
values) the method will return
+ * (i.e. contains null
values) the method will throw
* IllegalArgumentException.
*
- * @throws IllegalArgumentException
- *
* @param context
* Schema Context
* @param schemaPath
* Schema Path to search for
* @return SchemaNode from the end of the Schema Path or null
* if the Node is not present.
+ * @throws IllegalArgumentException if context or schemaPath is not correct.
*/
public static SchemaNode findDataSchemaNode(final SchemaContext context, final SchemaPath schemaPath) {
Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL");
@@ -98,8 +111,6 @@ public final class SchemaContextUtil {
* method will return specified Data Schema Node, otherwise the operation
* will fail and method will return null
.
*
- * @throws IllegalArgumentException
- *
* @param context
* Schema Context
* @param module
@@ -110,16 +121,18 @@ public final class SchemaContextUtil {
* Non-conditional Revision Aware XPath, or null
if the
* DataSchemaNode is not present in Schema Context.
*/
- public static SchemaNode findDataSchemaNode(final SchemaContext context, final Module module, final RevisionAwareXPath nonCondXPath) {
+ public static SchemaNode findDataSchemaNode(final SchemaContext context, final Module module,
+ final RevisionAwareXPath nonCondXPath) {
Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL");
Preconditions.checkArgument(module != null, "Module reference cannot be NULL");
Preconditions.checkArgument(nonCondXPath != null, "Non Conditional Revision Aware XPath cannot be NULL");
- String strXPath = nonCondXPath.toString();
+ final String strXPath = nonCondXPath.toString();
if (strXPath != null) {
- Preconditions.checkArgument(strXPath.indexOf('[') == -1, "Revision Aware XPath may not contain a condition");
+ Preconditions.checkArgument(strXPath.indexOf('[') == -1,
+ "Revision Aware XPath may not contain a condition");
if (nonCondXPath.isAbsolute()) {
- Listnull
.
*
- * @throws IllegalArgumentException
- *
* @param context
* Schema Context
* @param module
@@ -177,9 +188,9 @@ public final class SchemaContextUtil {
"Revision Aware XPath MUST be relative i.e. MUST contains ../, "
+ "for non relative Revision Aware XPath use findDataSchemaNode method");
- SchemaPath actualNodePath = actualSchemaNode.getPath();
+ final SchemaPath actualNodePath = actualSchemaNode.getPath();
if (actualNodePath != null) {
- Iterablenull
references
* the method will throw IllegalArgumentException
*
- * @throws IllegalArgumentException
- *
* @param context
* Schema Context
* @param schemaNode
* Schema Node
- * @return Yang Module for specified Schema Context and Schema Node, if
- * Schema Node is NOT present, the method will returns
- * null
+ * @return Yang Module for specified Schema Context and Schema Node, if Schema Node is NOT present, the method will
+ * return null
*/
public static Module findParentModule(final SchemaContext context, final SchemaNode schemaNode) {
Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL!");
@@ -211,203 +219,236 @@ public final class SchemaContextUtil {
Preconditions.checkState(schemaNode.getPath() != null, "Schema Path for Schema Node is not "
+ "set properly (Schema Path is NULL)");
- final QName qname = Iterables.getFirst(schemaNode.getPath().getPathTowardsRoot(), null);
- Preconditions.checkState(qname != null,
- "Schema Path contains invalid state of path parts. " +
- "The Schema Path MUST contain at least ONE QName which defines namespace and Local name of path.");
- return context.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision());
+ final QName qname = schemaNode.getPath().getLastComponent();
+ Preconditions.checkState(qname != null, "Schema Path contains invalid state of path parts. "
+ + "The Schema Path MUST contain at least ONE QName which defines namespace and Local name of path.");
+ return context.findModule(qname.getModule()).orElse(null);
}
public static SchemaNode findNodeInSchemaContext(final SchemaContext context, final Iterablenull
values, the method will throws IllegalArgumentException
*
- * @throws IllegalArgumentException
- *
* @param context
* Schema Context
* @param parentModule
@@ -453,14 +497,19 @@ public final class SchemaContextUtil {
* @param xpath
* XPath String
* @return return a list of QName
+ *
+ * @throws IllegalArgumentException if any arguments are null
+ *
*/
- private static Listnull
the method will throw IllegalArgumentException
*
- * @throws IllegalArgumentException
- *
* @param context
* Schema Context
* @param parentModule
@@ -488,8 +535,11 @@ public final class SchemaContextUtil {
* @param prefixedPathPart
* Prefixed Path Part string
* @return QName from prefixed Path Part String.
+ * @throws IllegalArgumentException if any arguments are null
*/
- private static QName stringPathPartToQName(final SchemaContext context, final Module parentModule, final String prefixedPathPart) {
+ private static QName stringPathPartToQName(final SchemaContext context, final Module parentModule,
+ final String prefixedPathPart) {
+ // FIXME: 2.0.0: this should throw NPE, not IAE
Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL");
Preconditions.checkArgument(parentModule != null, "Parent Module reference cannot be NULL");
Preconditions.checkArgument(prefixedPathPart != null, "Prefixed Path Part cannot be NULL!");
@@ -498,15 +548,15 @@ public final class SchemaContextUtil {
final Iteratornull
* the method will return IllegalArgumentException
*
- * @throws IllegalArgumentException
- *
* @param context
* Schema Context
* @param module
@@ -532,8 +580,11 @@ public final class SchemaContextUtil {
* Module Prefix
* @return Module for given prefix in specified Schema Context if is
* present, otherwise returns null
+ * @throws IllegalArgumentException if any arguments are null
*/
- private static Module resolveModuleForPrefix(final SchemaContext context, final Module module, final String prefix) {
+ private static Module resolveModuleForPrefix(final SchemaContext context, final Module module,
+ final String prefix) {
+ // FIXME: 2.0.0: this should throw NPE, not IAE
Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL");
Preconditions.checkArgument(module != null, "Module reference cannot be NULL");
Preconditions.checkArgument(prefix != null, "Prefix string cannot be NULL");
@@ -542,17 +593,17 @@ public final class SchemaContextUtil {
return module;
}
- Set
+ * Because {@code typeDefinition} is definied via typedef statement, only absolute path is meaningful.
+ */
+ public static TypeDefinition> getBaseTypeForLeafRef(final LeafrefTypeDefinition typeDefinition,
+ final SchemaContext schemaContext, final QName qname) {
+ final RevisionAwareXPath pathStatement = typeDefinition.getPathStatement();
+ final RevisionAwareXPath strippedPathStatement = new RevisionAwareXPathImpl(
+ stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute());
+ if (!strippedPathStatement.isAbsolute()) {
+ return null;
+ }
+
+ final Optional