* the end of the SchemaPath. If the DataSchemaNode is not present in the
* Schema Context the method will return <code>null</code>. <br>
* In case that Schema Context or Schema Path are not specified correctly
- * (i.e. contains <code>null</code> values) the method will return
+ * (i.e. contains <code>null</code> values) the method will throw
* IllegalArgumentException.
*
* @param context
* Schema Path to search for
* @return SchemaNode from the end of the Schema Path or <code>null</code>
* if the Node is not present.
- *
- * @throws IllegalArgumentException
+ * @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");
* @return Returns Data Schema Node for specified Schema Context for given
* Non-conditional Revision Aware XPath, or <code>null</code> if the
* DataSchemaNode is not present in Schema Context.
- * @throws IllegalArgumentException
*/
public static SchemaNode findDataSchemaNode(final SchemaContext context, final Module module,
final RevisionAwareXPath nonCondXPath) {
* @return DataSchemaNode if is present in specified Schema Context for
* given relative Revision Aware XPath, otherwise will return
* <code>null</code>.
- *
- * @throws IllegalArgumentException
*/
public static SchemaNode findDataSchemaNodeForRelativeXPath(final SchemaContext context, final Module module,
final SchemaNode actualSchemaNode, final RevisionAwareXPath relativeXPath) {
* Schema Node
* @return Yang Module for specified Schema Context and Schema Node, if Schema Node is NOT present, the method will
* return <code>null</code>
- *
- * @throws IllegalArgumentException
*/
public static Module findParentModule(final SchemaContext context, final SchemaNode schemaNode) {
Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL!");
}
/**
- * Returns NotificationDefinition from Schema Context
+ * Returns NotificationDefinition from Schema Context.
*
* @param schema SchemaContext in which lookup should be performed.
* @param path Schema Path of notification
* @return Notification schema or null, if notification is not present in schema context.
*/
@Beta
- @Nullable public static NotificationDefinition getNotificationSchema(@Nonnull final SchemaContext schema,
+ @Nullable
+ public static NotificationDefinition getNotificationSchema(@Nonnull final SchemaContext schema,
@Nonnull final SchemaPath path) {
Preconditions.checkNotNull(schema, "Schema context must not be null.");
Preconditions.checkNotNull(path, "Schema path must not be null.");
for (final NotificationDefinition potential : schema.getNotifications()) {
if (path.equals(potential.getPath())) {
- return potential;
+ return potential;
}
}
return null;
* @return Notification schema or null, if notification is not present in schema context.
*/
@Beta
- @Nullable public static ContainerSchemaNode getRpcDataSchema(@Nonnull final SchemaContext schema,
+ @Nullable
+ public static ContainerSchemaNode getRpcDataSchema(@Nonnull final SchemaContext schema,
@Nonnull final SchemaPath path) {
Preconditions.checkNotNull(schema, "Schema context must not be null.");
Preconditions.checkNotNull(path, "Schema path must not be null.");
final QName inOrOut = it.next();
for (final RpcDefinition potential : schema.getOperations()) {
if (rpcName.equals(potential.getQName())) {
- return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut);
+ return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut);
}
}
return null;
* XPath String
* @return return a list of QName
*
- * @throws IllegalArgumentException
+ * @throws IllegalArgumentException if any arguments are null
+ *
*/
private static List<QName> xpathToQNamePath(final SchemaContext context, final Module parentModule,
final String xpath) {
+ // 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(xpath != null, "XPath string reference cannot be NULL");
* @param prefixedPathPart
* Prefixed Path Part string
* @return QName from prefixed Path Part String.
- *
- * @throws IllegalArgumentException
+ * @throws IllegalArgumentException if any arguments are null
*/
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!");
* Module Prefix
* @return Module for given prefix in specified Schema Context if is
* present, otherwise returns <code>null</code>
- *
- * @throws IllegalArgumentException
+ * @throws IllegalArgumentException if any arguments are null
*/
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");
}
/**
+ * Resolve a relative XPath into a set of QNames.
+ *
* @param context
* Schema Context
* @param module
* @param actualSchemaNode
* actual schema node
* @return list of QName
- *
- * @throws IllegalArgumentException
+ * @throws IllegalArgumentException if any arguments are null
*/
private static Iterable<QName> resolveRelativeXPath(final SchemaContext context, final Module module,
final RevisionAwareXPath relativeXPath, final SchemaNode actualSchemaNode) {
+ // 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(relativeXPath != null, "Non Conditional Revision Aware XPath cannot be NULL");
return targetTypeDefinition;
}
- private static Module findParentModuleOfReferencingType(final SchemaContext schemaContext,
- final SchemaNode schemaNode) {
- Preconditions.checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!");
- Preconditions.checkArgument(schemaNode instanceof TypedSchemaNode, "Unsupported node %s", schemaNode);
-
- TypeDefinition<?> nodeType = ((TypedSchemaNode) schemaNode).getType();
- if (nodeType.getBaseType() != null) {
- while (nodeType.getBaseType() != null) {
- nodeType = nodeType.getBaseType();
- }
-
- final QNameModule typeDefModuleQname = nodeType.getQName().getModule();
- return schemaContext.findModuleByNamespaceAndRevision(typeDefModuleQname.getNamespace(),
- typeDefModuleQname.getRevision());
- }
-
- return SchemaContextUtil.findParentModule(schemaContext, schemaNode);
- }
-
/**
- * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qName}. This handle
+ * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qname}. This handle
* the case when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other
* module as typedef which is then imported to referenced module.
*
+ * <p>
* Because {@code typeDefinition} is definied via typedef statement, only absolute path is meaningful.
- *
- * @param typeDefinition
- * @param schemaContext
- * @param qName
*/
public static TypeDefinition<?> getBaseTypeForLeafRef(final LeafrefTypeDefinition typeDefinition,
- final SchemaContext schemaContext, final QName qName) {
+ final SchemaContext schemaContext, final QName qname) {
final RevisionAwareXPath pathStatement = typeDefinition.getPathStatement();
final RevisionAwareXPath strippedPathStatement = new RevisionAwareXPathImpl(
stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute());
return null;
}
- final Module parentModule = schemaContext.findModuleByNamespaceAndRevision(qName.getNamespace()
- ,qName.getRevision());
+ final Module parentModule = schemaContext.findModuleByNamespaceAndRevision(qname.getNamespace(),
+ qname.getRevision());
final DataSchemaNode dataSchemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(schemaContext,
parentModule, strippedPathStatement);
final TypeDefinition<?> targetTypeDefinition = typeDefinition(dataSchemaNode);
return targetTypeDefinition;
}
+ private static Module findParentModuleOfReferencingType(final SchemaContext schemaContext,
+ final SchemaNode schemaNode) {
+ Preconditions.checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!");
+ Preconditions.checkArgument(schemaNode instanceof TypedSchemaNode, "Unsupported node %s", schemaNode);
+
+ TypeDefinition<?> nodeType = ((TypedSchemaNode) schemaNode).getType();
+ if (nodeType.getBaseType() != null) {
+ while (nodeType.getBaseType() != null) {
+ nodeType = nodeType.getBaseType();
+ }
+
+ final QNameModule typeDefModuleQname = nodeType.getQName().getModule();
+ return schemaContext.findModuleByNamespaceAndRevision(typeDefModuleQname.getNamespace(),
+ typeDefModuleQname.getRevision());
+ }
+
+ return SchemaContextUtil.findParentModule(schemaContext, schemaNode);
+ }
+
private static final Pattern STRIP_PATTERN = Pattern.compile("\\[[^\\[\\]]*\\]");
/**
* @param pathStatement
* xPath to target node
* @return string representation of xPath without conditions
- *
*/
@VisibleForTesting
static String stripConditionsFromXPathString(final RevisionAwareXPath pathStatement) {