import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * @deprecated Pre-Beryllium implementation, scheduled for removal.
+ */
+@Deprecated
public final class BuilderUtils {
private static final Logger LOG = LoggerFactory.getLogger(BuilderUtils.class);
});
}
- /**
- * Create new SchemaPath from given path and qname.
- *
- * @param schemaPath
- * base path
- * @param qname
- * one or more qnames added to base path
- * @return new SchemaPath from given path and qname
- *
- * @deprecated Use {@link SchemaPath#createChild(QName...)} instead.
- */
- @Deprecated
- public static SchemaPath createSchemaPath(final SchemaPath schemaPath, final QName... qname) {
- return schemaPath.createChild(qname);
- }
-
/**
* Find dependent module based on given prefix
*
return dependentModule;
}
- public static ModuleBuilder findModuleFromBuilders(ModuleImport imp, Iterable<ModuleBuilder> modules) {
+ public static ModuleBuilder findModuleFromBuilders(final ModuleImport imp, final Iterable<ModuleBuilder> modules) {
String name = imp.getModuleName();
Date revision = imp.getRevision();
NavigableMap<Date, ModuleBuilder> map = new TreeMap<>();
/**
* Set addedByUses flag to true for node and all its child nodes.
*
- * @param node
+ * @param node grouping member node
*/
public static void setNodeAddedByUses(final GroupingMember node) {
node.setAddedByUses(true);
}
}
+ /**
+ * Find builder of schema node under parent builder (including under
+ * AugmentationSchemaBuilder).
+ *
+ * @param path
+ * - path of target schema node builder
+ * @param parent
+ * - base data node container builder under which the target
+ * schema node builder should be found
+ * @return builder of schema node
+ */
+ public static SchemaNodeBuilder findTargetNode(final Iterable<QName> path,
+ final DataNodeContainerBuilder parent) {
+
+ Preconditions.checkNotNull(parent);
+ Preconditions.checkNotNull(path);
+
+ SchemaNodeBuilder foundNode = null;
+
+ final Iterator<QName> pathIterator = path.iterator();
+ if (pathIterator.hasNext()) {
+ String name = pathIterator.next().getLocalName();
+ foundNode = parent.getDataChildByName(name);
+ if (foundNode == null) {
+ foundNode = findUnknownNode(name, parent);
+ }
+ }
+
+ if (pathIterator.hasNext() && foundNode != null) {
+ return findSchemaNode(Iterables.skip(path, 1), foundNode);
+ } else {
+ return foundNode;
+ }
+ }
+
public static SchemaNodeBuilder findSchemaNode(final Iterable<QName> path, final SchemaNodeBuilder parentNode) {
SchemaNodeBuilder node = null;
SchemaNodeBuilder parent = parentNode;
Set<NotificationBuilder> notifications = module.getAddedNotifications();
for (NotificationBuilder notification : notifications) {
if (notification.getQName().equals(child)) {
- return Optional.<SchemaNodeBuilder> of(notification);
+ return Optional.of(notification);
}
}
Set<RpcDefinitionBuilder> rpcs = module.getAddedRpcs();
for (RpcDefinitionBuilder rpc : rpcs) {
if (rpc.getQName().equals(child)) {
- return Optional.<SchemaNodeBuilder> of(rpc);
+ return Optional.of(rpc);
}
}
LOG.trace("Child {} not found in data namespace of module {}", child, module);
private static Optional<SchemaNodeBuilder> getDataChildByQName(final DataNodeContainerBuilder builder, final QName child) {
for (DataSchemaNodeBuilder childNode : builder.getChildNodeBuilders()) {
if (childNode.getQName().equals(child)) {
- return Optional.<SchemaNodeBuilder> of(childNode);
+ return Optional.of(childNode);
}
}
LOG.trace(CHILD_NOT_FOUND_IN_NODE_STR, child, builder);
/**
* Get module in which this node is defined.
*
- * @param node
+ * @param node node
* @return builder of module where this node is defined
*/
public static ModuleBuilder getParentModule(final Builder node) {
if (qname.getRevision() == null) {
return map.lastEntry().getValue();
}
+
+ final Entry<Date, ModuleBuilder> lastEntry = map.lastEntry();
+ if (qname.getRevision().compareTo(lastEntry.getKey()) > 0) {
+ /*
+ * We are trying to find more recent revision of module than is in
+ * the map. Most probably the yang models are not referenced
+ * correctly and the revision of a base module or submodule has not
+ * been updated along with revision of a referenced module or
+ * submodule. However, we should return the most recent entry in the
+ * map, otherwise the null pointer exception occurs (see Bug3799).
+ */
+ LOG.warn(String
+ .format("Attempt to find more recent revision of module than is available. "
+ + "The requested revision is [%s], but the most recent available revision of module is [%s]."
+ + " Most probably some of Yang models do not have updated revision or they are not "
+ + "referenced correctly.",
+ qname.getRevision(), lastEntry.getKey()));
+ return lastEntry.getValue();
+ }
+
return map.get(qname.getRevision());
}