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<>();
}
}
+ /**
+ * 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;
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());
}