Merge "BUG-461 Test transformation of rpc input using XmlDocumentUtils"
authorTony Tkacik <ttkacik@cisco.com>
Tue, 29 Jul 2014 09:25:01 +0000 (09:25 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 29 Jul 2014 09:25:01 +0000 (09:25 +0000)
27 files changed:
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/AbstractTransformerGenerator.java
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/LazyGeneratedCodecRegistry.java
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/util/JavassistUtils.java
code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/GroupingDefinitionDependencySort.java
code-generator/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/unified/doc/generator/GeneratorImpl.xtend
integration-test/yang-runtime-tests/src/test/java/org/opendaylight/yangtools/it/yang/runtime/tests/MultipleRevisionsSupportTest.java
model/ietf/ietf-inet-types/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev100924/HostBuilder.java
model/ietf/ietf-inet-types/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev100924/IpAddressBuilder.java
model/ietf/ietf-inet-types/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev100924/IpPrefixBuilder.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifier.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/KeyedInstanceIdentifier.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtils.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DataNodeContainer.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java
yang/yang-parser-impl/src/main/antlr/YangParser.g4
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/SchemaContextImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySort.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1413Test.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/OrderingTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java
yang/yang-parser-impl/src/test/resources/bugs/bug1413/bug1413.yang [new file with mode: 0644]

index 8fda4d19bcdb9f62d5c9b3ddefbe06170dba1282..bacff303f2ac28e5d6edddb6ed3abccb96a767d2 100644 (file)
@@ -73,16 +73,9 @@ abstract class AbstractTransformerGenerator {
     }
 
     protected final <V> V runOnClassLoader(final ClassLoader cls, final Callable<V> function) throws Exception {
-        final Lock lock = javAssist.getLock();
-
-        lock.lock();
-        try {
-            synchronized (javAssist) {
-                javAssist.appendClassLoaderIfMissing(cls);
-                return ClassLoaderUtils.withClassLoader(cls, function);
-            }
-        } finally {
-            lock.unlock();
+        synchronized (javAssist) {
+            javAssist.appendClassLoaderIfMissing(cls);
+            return ClassLoaderUtils.withClassLoader(cls, function);
         }
     }
 
index 15fa0902d0029ee7084d6f64ea63d1e76a1a7257..d448db765947b544e5d2ef3d3da289ab52da4af0 100644 (file)
@@ -30,6 +30,7 @@ import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findP
 import com.google.common.base.Splitter;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -38,6 +39,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
 import org.opendaylight.yangtools.binding.generator.util.BindingTypes;
 import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
@@ -525,8 +527,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
                         notification.getChildNodes());
 
                 listenerInterface.addMethod("on" + notificationInterface.getName())
-                        .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification")
-                        .setComment(notification.getDescription()).setReturnType(Types.VOID);
+                .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification")
+                .setComment(notification.getDescription()).setReturnType(Types.VOID);
             }
         }
 
@@ -594,7 +596,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                     .getQNameModule());
             final String returnTypeName = BindingMapping.getClassName(baseIdentity.getQName());
             final GeneratedTransferObject gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName)
-                    .toInstance();
+            .toInstance();
             newType.setExtendsType(gto);
         }
         newType.setAbstract(true);
@@ -641,7 +643,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
     private void groupingsToGenTypes(final Module module, final Collection<GroupingDefinition> groupings) {
         final String basePackageName = BindingMapping.getRootPackageName(module.getQNameModule());
         final List<GroupingDefinition> groupingsSortedByDependencies = new GroupingDefinitionDependencySort()
-                .sort(groupings);
+        .sort(groupings);
         for (GroupingDefinition grouping : groupingsSortedByDependencies) {
             groupingToGenType(basePackageName, grouping, module);
         }
@@ -996,8 +998,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
      *         added to it.
      */
     private GeneratedTypeBuilder resolveDataSchemaNodes(final Module module, final String basePackageName,
-            final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final Set<DataSchemaNode> schemaNodes) {
-        if ((schemaNodes != null) && (parent != null)) {
+            final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final Iterable<DataSchemaNode> schemaNodes) {
+        if (schemaNodes != null && parent != null) {
             for (DataSchemaNode schemaNode : schemaNodes) {
                 if (!schemaNode.isAugmenting() && !schemaNode.isAddedByUses()) {
                     addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, parent, childOf, module);
@@ -1031,7 +1033,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
      */
     private GeneratedTypeBuilder augSchemaNodeToMethods(final Module module, final String basePackageName,
             final GeneratedTypeBuilder typeBuilder, final GeneratedTypeBuilder childOf,
-            final Set<DataSchemaNode> schemaNodes) {
+            final Iterable<DataSchemaNode> schemaNodes) {
         if ((schemaNodes != null) && (typeBuilder != null)) {
             for (DataSchemaNode schemaNode : schemaNodes) {
                 if (!schemaNode.isAugmenting()) {
@@ -1164,7 +1166,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 caseTypeBuilder.addImplementsType(refChoiceType);
                 genCtx.get(module).addCaseType(caseNode.getPath(), caseTypeBuilder);
                 genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
-                final Set<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
+                final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
                 if (caseChildNodes != null) {
                     Object parentNode = null;
                     final SchemaPath nodeSp = choiceNode.getPath();
@@ -1183,7 +1185,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                             if (targetSchemaNode == null) {
                                 throw new IllegalStateException(
                                         "Failed to find target node from grouping for augmentation " + augSchema
-                                                + " in module " + module.getName());
+                                        + " in module " + module.getName());
                             }
                         }
                         parent = targetSchemaNode;
@@ -1231,7 +1233,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
      *             </ul>
      */
     private void generateTypesFromAugmentedChoiceCases(final Module module, final String basePackageName,
-            final Type targetType, final ChoiceNode targetNode, final Set<DataSchemaNode> augmentedNodes) {
+            final Type targetType, final ChoiceNode targetNode, final Iterable<DataSchemaNode> augmentedNodes) {
         checkArgument(basePackageName != null, "Base Package Name cannot be NULL.");
         checkArgument(targetType != null, "Referenced Choice Type cannot be NULL.");
         checkArgument(augmentedNodes != null, "Set of Choice Case Nodes cannot be NULL.");
@@ -1267,7 +1269,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 } else {
                     node = targetNode.getCaseNodeByName(caseNode.getQName().getLocalName());
                 }
-                final Set<DataSchemaNode> childNodes = node.getChildNodes();
+                final Iterable<DataSchemaNode> childNodes = node.getChildNodes();
                 if (childNodes != null) {
                     resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, childNodes);
                 }
index e87683db0710fe8ee10377a180a4d93fc1225e7c..86f0cdf881a64b156cde44b0a45ccb6270da2563 100644 (file)
@@ -311,8 +311,7 @@ class LazyGeneratedCodecRegistry implements CodecRegistry, SchemaContextListener
     }
 
     private DataSchemaNode searchInChoices(final DataNodeContainer node, final QName arg) {
-        Set<DataSchemaNode> children = node.getChildNodes();
-        for (DataSchemaNode child : children) {
+        for (DataSchemaNode child : node.getChildNodes()) {
             if (child instanceof ChoiceNode) {
                 ChoiceNode choiceNode = (ChoiceNode) child;
                 DataSchemaNode potential = searchInCases(choiceNode, arg);
@@ -425,8 +424,8 @@ class LazyGeneratedCodecRegistry implements CodecRegistry, SchemaContextListener
         for (Map.Entry<Type, AugmentationSchema> entry : bimap.entrySet()) {
             Type key = entry.getKey();
             AugmentationSchema value = entry.getValue();
-            Set<DataSchemaNode> augmentedNodes = value.getChildNodes();
-            if (augmentedNodes != null && !(augmentedNodes.isEmpty())) {
+            Collection<DataSchemaNode> augmentedNodes = value.getChildNodes();
+            if (augmentedNodes != null && !augmentedNodes.isEmpty()) {
                 typeToAugment.put(key, value);
             }
         }
index 4065992c1b92c308729ea4d3cad02386eb18d80d..3bb61900df69b6dfd128d36edf6563fe074994d9 100644 (file)
@@ -12,8 +12,6 @@ import com.google.common.base.Preconditions;
 import java.util.Collection;
 import java.util.Map;
 import java.util.WeakHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
 
 import javassist.CannotCompileException;
 import javassist.ClassClassPath;
@@ -25,31 +23,22 @@ import javassist.CtMethod;
 import javassist.LoaderClassPath;
 import javassist.Modifier;
 import javassist.NotFoundException;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Users of this utility class are expected to synchronize on this instance
+ * it they need to ensure atomic operations on it.
+ */
 public final class JavassistUtils {
     private static final Logger LOG = LoggerFactory.getLogger(JavassistUtils.class);
 
     private static final Map<ClassPool, JavassistUtils> INSTANCES = new WeakHashMap<>();
     private final Map<ClassLoader, ClassPath> loaderClassPaths = new WeakHashMap<>();
-    private final Lock lock = new ReentrantLock();
     private final ClassPool classPool;
 
-    /**
-     * @deprecated Use {@link #forClassPool(ClassPool)} instead.
-     *
-     * This class provides auto-loading into the classpool. Unfortunately reusing
-     * the same class pool with multiple instances can lead the same classpath
-     * being added multiple times, which lowers performance and leaks memory.
-     */
-    @Deprecated
-    public JavassistUtils(final ClassPool pool) {
-        this(pool, null);
-    }
-
-    private JavassistUtils(final ClassPool pool, final Object dummy) {
-        // FIXME: Remove 'dummy' once deprecated constructor is removed
+    private JavassistUtils(final ClassPool pool) {
         classPool = Preconditions.checkNotNull(pool);
     }
 
@@ -64,24 +53,12 @@ public final class JavassistUtils {
     public static synchronized JavassistUtils forClassPool(final ClassPool pool) {
         JavassistUtils ret = INSTANCES.get(Preconditions.checkNotNull(pool));
         if (ret == null) {
-            ret = new JavassistUtils(pool, null);
+            ret = new JavassistUtils(pool);
             INSTANCES.put(pool, ret);
         }
         return ret;
     }
 
-    /**
-     * Get reference to the internal lock.
-     *
-     * @return Lock object
-     *
-     * @deprecated Synchronize on an instance of this class instead.
-     */
-    @Deprecated
-    public Lock getLock() {
-        return lock;
-    }
-
     public void method(final CtClass it, final Class<? extends Object> returnType, final String name,
             final Class<? extends Object> parameter, final MethodGenerator function1) throws CannotCompileException {
         final CtClass[] pa = new CtClass[] { asCtClass(parameter) };
@@ -160,8 +137,8 @@ public final class JavassistUtils {
     }
 
     public CtField staticField(final CtClass it, final String name,
-                               final Class<? extends Object> returnValue,
-                               SourceCodeGenerator sourceGenerator) throws CannotCompileException {
+            final Class<? extends Object> returnValue,
+            final SourceCodeGenerator sourceGenerator) throws CannotCompileException {
         final CtField field = new CtField(asCtClass(returnValue), name, it);
         field.setModifiers(Modifier.PUBLIC + Modifier.STATIC);
         it.addField(field);
index 1b6ffd9822baf31b9b2fab78b0348c01ec8060ef..b697bf99121377d019080e166d98652283ab86e5 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.sal.binding.yang.types;
 
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -25,9 +28,6 @@ import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort;
 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
 
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
 public class GroupingDefinitionDependencySort {
 
     /**
@@ -132,7 +132,7 @@ public class GroupingDefinitionDependencySort {
      *            data node container which can contain some uses of grouping
      * @return set of uses nodes which were find in <code>container</code>.
      */
-    private Set<UsesNode> getAllUsesNodes(DataNodeContainer container) {
+    private Set<UsesNode> getAllUsesNodes(final DataNodeContainer container) {
         Set<UsesNode> ret = new HashSet<>();
         Set<UsesNode> usesNodes = container.getUses();
         ret.addAll(usesNodes);
@@ -146,8 +146,7 @@ public class GroupingDefinitionDependencySort {
         for (GroupingDefinition groupingDefinition : groupings) {
             ret.addAll(getAllUsesNodes(groupingDefinition));
         }
-        Set<DataSchemaNode> childNodes = container.getChildNodes();
-        for (DataSchemaNode childNode : childNodes) {
+        for (DataSchemaNode childNode : container.getChildNodes()) {
             if (childNode instanceof DataNodeContainer) {
                 ret.addAll(getAllUsesNodes((DataNodeContainer) childNode));
             } else if (childNode instanceof ChoiceNode) {
index 8acc2ad11129abe0c24ccfc61863e3ec4695c645..bc4e267b0c6c429f1a52b8cf43dcf4cce1704d6b 100644 (file)
@@ -367,7 +367,7 @@ class GeneratorImpl {
         return targetPathNodes
     }
     
-    private def DataSchemaNode findNodeInChildNodes(QName findingNode, Set<DataSchemaNode> childNodes) {
+    private def DataSchemaNode findNodeInChildNodes(QName findingNode, Iterable<DataSchemaNode> childNodes) {
         for(child : childNodes) {
             if (child.QName.equals(findingNode))
                 return child;
@@ -950,7 +950,7 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence printChildren(Set<DataSchemaNode> nodes, int level, InstanceIdentifier path) {
+    def CharSequence printChildren(Iterable<DataSchemaNode> nodes, int level, InstanceIdentifier path) {
         val anyxmlNodes = nodes.filter(AnyXmlSchemaNode)
         val leafNodes = nodes.filter(LeafSchemaNode)
         val leafListNodes = nodes.filter(LeafListSchemaNode)
@@ -1000,13 +1000,13 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence xmlExample(Set<DataSchemaNode> nodes, QName name,InstanceIdentifier path) '''
+    def CharSequence xmlExample(Iterable<DataSchemaNode> nodes, QName name,InstanceIdentifier path) '''
     <pre>
         Â«xmlExampleTag(name,nodes.xmplExampleTags(path))»
     </pre>
     '''
 
-    def CharSequence xmplExampleTags(Set<DataSchemaNode> nodes, InstanceIdentifier identifier) '''
+    def CharSequence xmplExampleTags(Iterable<DataSchemaNode> nodes, InstanceIdentifier identifier) '''
         <!-- Child nodes -->
         Â«FOR node : nodes»
         <!-- Â«node.QName.localName» -->
index 16f408c243ee583777895488536082d1c6d23a3e..d75c5657bf1bceecc4be7925a286e9fbca481178 100644 (file)
@@ -11,6 +11,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.common.collect.ImmutableSet;
+
 import java.io.InputStream;
 import java.net.URI;
 import java.util.List;
@@ -30,10 +34,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
-import com.google.common.collect.ImmutableSet;
-
 public class MultipleRevisionsSupportTest {
 
     public static final YangModuleInfo TOPOLOGY_OLD_MODULE = org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.$YangModuleInfoImpl
@@ -117,7 +117,7 @@ public class MultipleRevisionsSupportTest {
         verifyBindingDifference(schemaContext, TOPOLOGY_OLD_MODULE, TOPOLOGY_NEW_MODULE);
     }
 
-    private SchemaContext contextVerified(List<InputStream> streams) {
+    private SchemaContext contextVerified(final List<InputStream> streams) {
         YangParserImpl parser = new YangParserImpl();
         Set<Module> modules = parser.parseYangModelsFromStreams(streams);
         assertNotNull(modules);
@@ -127,19 +127,19 @@ public class MultipleRevisionsSupportTest {
         return context;
     }
 
-    private void verifyBindingDifference(SchemaContext schemaContext, YangModuleInfo oldModule, YangModuleInfo newModule) {
+    private void verifyBindingDifference(final SchemaContext schemaContext, final YangModuleInfo oldModule, final YangModuleInfo newModule) {
         generatedTypesVerified(schemaContext, oldModule, newModule);
     }
 
-    private Map<Module, ModuleContext> generatedTypesVerified(SchemaContext schemaContext, YangModuleInfo oldModule,
-            YangModuleInfo newModule) {
+    private Map<Module, ModuleContext> generatedTypesVerified(final SchemaContext schemaContext, final YangModuleInfo oldModule,
+            final YangModuleInfo newModule) {
         BindingGeneratorImpl generator = new BindingGeneratorImpl();
         generator.generateTypes(schemaContext);
         return generator.getModuleContexts();
     }
 
-    private void verifySchemaDifference(SchemaContext context, YangModuleInfo topologyOldModule,
-            YangModuleInfo topologyNewModule) {
+    private void verifySchemaDifference(final SchemaContext context, final YangModuleInfo topologyOldModule,
+            final YangModuleInfo topologyNewModule) {
         Module oldModel = context.findModuleByNamespaceAndRevision(//
                 URI.create(TOPOLOGY_OLD_MODULE.getNamespace()), QName.parseRevision(TOPOLOGY_OLD_MODULE.getRevision()));
 
@@ -156,7 +156,7 @@ public class MultipleRevisionsSupportTest {
         assertDeepRevision(TOPOLOGY_NEW_MODULE.getRevision(), newNode);
     }
 
-    private static void assertDeepRevision(String revision, SchemaNode node) {
+    private static void assertDeepRevision(final String revision, final SchemaNode node) {
         assertEquals("Wrong revision: " + node.getPath(), revision, node.getQName().getFormattedRevision());
         if (node instanceof DataNodeContainer) {
             for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
@@ -169,7 +169,7 @@ public class MultipleRevisionsSupportTest {
         }
     }
 
-    private static final SchemaNode findSchemaNode(DataNodeContainer container, String... pathArgs) {
+    private static final SchemaNode findSchemaNode(final DataNodeContainer container, final String... pathArgs) {
         DataNodeContainer previous = container;
 
         SchemaNode result = (container instanceof SchemaNode) ? (SchemaNode) container : null;
@@ -177,8 +177,7 @@ public class MultipleRevisionsSupportTest {
             if (previous == null) {
                 return null;
             }
-            Set<DataSchemaNode> childs = previous.getChildNodes();
-            for (DataSchemaNode child : childs) {
+            for (DataSchemaNode child : previous.getChildNodes()) {
                 if (child.getQName().getLocalName().equals(arg)) {
                     if (child instanceof DataNodeContainer) {
                         previous = (DataNodeContainer) child;
@@ -193,7 +192,7 @@ public class MultipleRevisionsSupportTest {
         return result;
     }
 
-    private static final Iterable<? extends InputStream> toInputStreams(Set<YangModuleInfo> moduleInfos)
+    private static final Iterable<? extends InputStream> toInputStreams(final Set<YangModuleInfo> moduleInfos)
             throws Exception {
         Builder<InputStream> streams = ImmutableList.<InputStream> builder();
         for (YangModuleInfo yangModuleInfo : moduleInfos) {
index ee92e8051efeb5eb453f2bcd004cc9176698e45f..96f32fcba2099a8cfcda0c8987529a9b5448c050 100644 (file)
@@ -9,29 +9,38 @@ package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
-**/
-public class HostBuilder {
-    private static final Pattern ipv4Pattern = Pattern.compile("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?");
-    private static final Pattern  ipv6Pattern1 = Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?");
-    private static final Pattern ipv6Pattern2 = Pattern.compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?");
-    private static final Pattern domainPattern = Pattern.compile("((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)|\\.");
+ **/
+public final class HostBuilder {
+    private static final Pattern IPV4_PATTERN = Pattern.compile("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?");
+    private static final Pattern IPV6_PATTERN1 = Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?");
+    private static final Pattern IPV6_PATTERN2 = Pattern.compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?");
+    private static final Pattern DOMAIN_PATTERN = Pattern.compile("((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)|\\.");
 
-    public static Host getDefaultInstance(String defaultValue) {
+    private HostBuilder() {
 
-        List<String> matchers = new ArrayList<>();
-        if (ipv6Pattern1.matcher(defaultValue).matches() || ipv6Pattern2.matcher(defaultValue).matches()) {
+    }
+
+    public static Host getDefaultInstance(final String defaultValue) {
+        final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue);
+        final Matcher ipv6Matcher1 = IPV6_PATTERN1.matcher(defaultValue);
+        final Matcher ipv6Matcher2 = IPV6_PATTERN2.matcher(defaultValue);
+        final Matcher domainMatcher = DOMAIN_PATTERN.matcher(defaultValue);
+
+        List<String> matchers = new ArrayList<>(3);
+        if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) {
             matchers.add(Ipv6Address.class.getSimpleName());
         }
 
         // Ipv4 and Domain Name patterns are not exclusive
         // Address 127.0.0.1 matches both patterns
         // This way Ipv4 address is preferred to domain name
-        if (ipv4Pattern.matcher(defaultValue).matches()) {
+        if (ipv4Matcher.matches()) {
             matchers.add(Ipv4Address.class.getSimpleName());
-        } else if (domainPattern.matcher(defaultValue).matches()) {
+        } else if (domainMatcher.matches()) {
             matchers.add(DomainName.class.getSimpleName());
         }
 
@@ -40,17 +49,17 @@ public class HostBuilder {
                     + matchers);
         }
 
-        if (ipv4Pattern.matcher(defaultValue).matches()) {
+        if (ipv4Matcher.matches()) {
             Ipv4Address ipv4 = new Ipv4Address(defaultValue);
             IpAddress ipAddress = new IpAddress(ipv4);
             return new Host(ipAddress);
         }
-        if (ipv6Pattern1.matcher(defaultValue).matches() || ipv6Pattern2.matcher(defaultValue).matches()) {
+        if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) {
             Ipv6Address ipv6 = new Ipv6Address(defaultValue);
             IpAddress ipAddress = new IpAddress(ipv6);
             return new Host(ipAddress);
         }
-        if (domainPattern.matcher(defaultValue).matches()) {
+        if (domainMatcher.matches()) {
             DomainName domainName = new DomainName(defaultValue);
             return new Host(domainName);
         }
index a90deeb754144b91ce7fcb7a016a4285e25dcde3..26bfa2d981ddc67d45915ec03f49a34a31a4fc29 100644 (file)
@@ -7,39 +7,39 @@
  */
 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
-**/
-public class IpAddressBuilder {
+ **/
+public final class IpAddressBuilder {
+    private static final Pattern IPV4_PATTERN =
+            Pattern.compile("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?");
+    private static final Pattern IPV6_PATTERN1 =
+            Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?");
+    private static final Pattern IPV6_PATTERN2 =
+            Pattern.compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?");
 
-    public static IpAddress getDefaultInstance(String defaultValue) {
-        String ipv4Pattern = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?";
-        String ipv6Pattern1 = "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?";
-        String ipv6Pattern2 = "(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?";
+    private IpAddressBuilder() {
 
-        List<String> matchers = new ArrayList<>();
-        if (defaultValue.matches(ipv4Pattern)) {
-            matchers.add(Ipv4Address.class.getSimpleName());
-        }
-        if (defaultValue.matches(ipv6Pattern1) && defaultValue.matches(ipv6Pattern2)) {
-            matchers.add(Ipv6Address.class.getSimpleName());
-        }
-        if (matchers.size() > 1) {
-            throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue
-                    + ". Value is ambigious for " + matchers);
-        }
+    }
 
-        if (defaultValue.matches(ipv4Pattern)) {
-            Ipv4Address ipv4 = new Ipv4Address(defaultValue);
-            return new IpAddress(ipv4);
-        }
-        if (defaultValue.matches(ipv6Pattern1) && defaultValue.matches(ipv6Pattern2)) {
-            Ipv6Address ipv6 = new Ipv6Address(defaultValue);
-            return new IpAddress(ipv6);
+    public static IpAddress getDefaultInstance(final String defaultValue) {
+        final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue);
+
+        if (ipv4Matcher.matches()) {
+            if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+                throw new IllegalArgumentException(
+                        String.format("Cannot create IpAddress from \"%s\", matches both %s and %s",
+                                defaultValue, Ipv4Address.class.getSimpleName(), Ipv6Address.class.getSimpleName()));
+
+            }
+            return new IpAddress(new Ipv4Address(defaultValue));
+        } else if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+            return new IpAddress(new Ipv6Address(defaultValue));
+        } else {
+            throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue);
         }
-        throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue);
     }
 
 }
index 70e9520129d4f50782774c3e2744384921a7f368..4d151165f18a67979fb075ffdea7b1521674bbec 100644 (file)
@@ -7,39 +7,36 @@
  */
 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
-**/
-public class IpPrefixBuilder {
+ **/
+public final class IpPrefixBuilder {
+    private static final Pattern IPV4_PATTERN = Pattern.compile("(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/(([0-9])|([1-2][0-9])|(3[0-2]))");
+    private static final Pattern IPV6_PATTERN1 = Pattern.compile("((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))");
+    private static final Pattern IPV6_PATTERN2 = Pattern.compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(/.+)");
 
-    public static IpPrefix getDefaultInstance(String defaultValue) {
-        String ipv4Pattern = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/(([0-9])|([1-2][0-9])|(3[0-2]))";
-        String ipv6Pattern1 = "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))";
-        String ipv6Pattern2 = "(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(/.+)";
+    private IpPrefixBuilder() {
 
-        List<String> matchers = new ArrayList<>();
-        if (defaultValue.matches(ipv4Pattern)) {
-            matchers.add(Ipv4Address.class.getSimpleName());
-        }
-        if (defaultValue.matches(ipv6Pattern1) && defaultValue.matches(ipv6Pattern2)) {
-            matchers.add(Ipv6Address.class.getSimpleName());
-        }
-        if (matchers.size() > 1) {
-            throw new IllegalArgumentException("Cannot create IpPrefix from " + defaultValue
-                    + ". Value is ambigious for " + matchers);
-        }
+    }
 
-        if (defaultValue.matches(ipv4Pattern)) {
-            Ipv4Prefix ipv4 = new Ipv4Prefix(defaultValue);
-            return new IpPrefix(ipv4);
-        }
-        if (defaultValue.matches(ipv6Pattern1) && defaultValue.matches(ipv6Pattern2)) {
-            Ipv6Prefix ipv6 = new Ipv6Prefix(defaultValue);
-            return new IpPrefix(ipv6);
+    public static IpPrefix getDefaultInstance(final String defaultValue) {
+        final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue);
+
+        if (ipv4Matcher.matches()) {
+            if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+                throw new IllegalArgumentException(
+                        String.format("Cannot create IpPrefix from \"%s\", matches both %s and %s",
+                                defaultValue, Ipv4Address.class.getSimpleName(), Ipv6Address.class.getSimpleName()));
+
+            }
+            return new IpPrefix(new Ipv4Prefix(defaultValue));
+        } else if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+            return new IpPrefix(new Ipv6Prefix(defaultValue));
+        } else {
+            throw new IllegalArgumentException("Cannot create IpPrefix from " + defaultValue);
         }
-        throw new IllegalArgumentException("Cannot create IpPrefix from " + defaultValue);
     }
 
 }
index e97b5ab98d3a5efbfc1d5e9a1bc708887110404b..9a597152c3ce4f3aa1a4e04e8ff94c230378e0c4 100644 (file)
@@ -14,6 +14,8 @@ import com.google.common.collect.ImmutableCollection;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
+import java.io.IOException;
+import java.io.Serializable;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -52,7 +54,8 @@ import org.opendaylight.yangtools.util.HashCodeBuilder;
  * This would be the same as using a path like so, "/nodes/node/openflow:1" to refer to the openflow:1 node
  *
  */
-public class InstanceIdentifier<T extends DataObject> implements Path<InstanceIdentifier<? extends DataObject>>, Immutable {
+public class InstanceIdentifier<T extends DataObject> implements Path<InstanceIdentifier<? extends DataObject>>, Immutable, Serializable {
+    private static final long serialVersionUID = 1L;
     /*
      * Protected to differentiate internal and external access. Internal
      * access is required never to modify the contents. References passed
@@ -497,7 +500,8 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
         Class<? extends DataObject> getType();
     }
 
-    private static abstract class AbstractPathArgument<T extends DataObject> implements PathArgument {
+    private static abstract class AbstractPathArgument<T extends DataObject> implements PathArgument, Serializable {
+        private static final long serialVersionUID = 1L;
         private final Class<T> type;
 
         protected AbstractPathArgument(final Class<T> type) {
@@ -542,6 +546,8 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
      * @param <T>
      */
     public static final class Item<T extends DataObject> extends AbstractPathArgument<T> {
+        private static final long serialVersionUID = 1L;
+
         public Item(final Class<T> type) {
             super(type);
         }
@@ -560,6 +566,7 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
      * @param <T> The identifier of the object
      */
     public static final class IdentifiableItem<I extends Identifiable<T> & DataObject, T extends Identifier<I>> extends AbstractPathArgument<I> {
+        private static final long serialVersionUID = 1L;
         private final T key;
 
         public IdentifiableItem(final Class<I> type, final T key) {
@@ -644,4 +651,18 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
          */
         InstanceIdentifier<T> build();
     }
+
+    private void writeObject(final java.io.ObjectOutputStream out) throws IOException {
+        out.writeObject(targetType);
+        out.writeBoolean(wildcarded);
+        out.writeInt(hash);
+        out.write(Iterables.size(pathArguments));
+        for (Object o : pathArguments) {
+            out.writeObject(o);
+        }
+    }
+
+    private void readObject(final java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+        // TODO Auto-generated method stub
+    }
 }
index 60f891631ae26590e12faba89779ee4f2555e920..88ec004a5b176c76a3ae9d5ca9e795bade96553f 100644 (file)
@@ -15,6 +15,7 @@ package org.opendaylight.yangtools.yang.binding;
  * @param <K> Target key type
  */
 public class KeyedInstanceIdentifier<T extends Identifiable<K> & DataObject, K extends Identifier<T>> extends InstanceIdentifier<T> {
+    private static final long serialVersionUID = 1L;
     private final K key;
 
     KeyedInstanceIdentifier(final Class<T> type, final Iterable<PathArgument> pathArguments, final boolean wildcarded, final int hash, final K key) {
index a02dd7c7e787c1724dfe7260990d903664fba40d..02f020c47fdc98307eb4ad2cf9aff0621cfb9529 100644 (file)
@@ -9,6 +9,13 @@ package org.opendaylight.yangtools.yang.data.impl.codec.xml;
 
 import static com.google.common.base.Preconditions.checkState;
 
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
@@ -54,13 +61,6 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
-
 public class XmlDocumentUtils {
     private static class ElementWithSchemaContext {
         Element element;
@@ -288,8 +288,8 @@ public class XmlDocumentUtils {
         checkState(qName.getLocalName().equals(xmlElement.getLocalName()), "Not equal: %s to: %s for: %s and: %s", qName.getLocalName(), xmlElement.getLocalName(), qName, xmlElement);
     }
 
-    public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Set<DataSchemaNode> dataSchemaNode) {
-        if (dataSchemaNode != null && !dataSchemaNode.isEmpty() && qname != null) {
+    public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Iterable<DataSchemaNode> dataSchemaNode) {
+        if (dataSchemaNode != null && qname != null) {
             for (DataSchemaNode dsn : dataSchemaNode) {
                 if (qname.isEqualWithoutRevision(dsn.getQName())) {
                     return Optional.<DataSchemaNode> of(dsn);
@@ -336,7 +336,7 @@ public class XmlDocumentUtils {
         return ImmutableCompositeNode.create(qname, values.build());
     }
 
-    public static List<Node<?>> toDomNodes(final Element element, final Optional<Set<DataSchemaNode>> context,final SchemaContext schemaCtx) {
+    public static List<Node<?>> toDomNodes(final Element element, final Optional<? extends Iterable<DataSchemaNode>> context, final SchemaContext schemaCtx) {
         return forEachChild(element.getChildNodes(),schemaCtx, new Function<ElementWithSchemaContext, Optional<Node<?>>>() {
 
             @Override
@@ -345,7 +345,7 @@ public class XmlDocumentUtils {
                     QName partialQName = qNameFromElement(input.getElement());
                     Optional<DataSchemaNode> schemaNode = findFirstSchema(partialQName, context.get());
                     if (schemaNode.isPresent()) {
-                        return Optional.<Node<?>> fromNullable(//
+                        return Optional.<Node<?>> fromNullable(
                                 toNodeWithSchema(input.getElement(), schemaNode.get(), XmlUtils.DEFAULT_XML_CODEC_PROVIDER, input.getSchemaContext()));
                     }
                 }
@@ -356,8 +356,8 @@ public class XmlDocumentUtils {
 
     }
 
-    public static List<Node<?>> toDomNodes(final Element element, final Optional<Set<DataSchemaNode>> context) {
-        return toDomNodes(element,context,null);
+    public static List<Node<?>> toDomNodes(final Element element, final Optional<? extends Iterable<DataSchemaNode>> context) {
+        return toDomNodes(element, context, null);
     }
 
     /**
@@ -393,9 +393,9 @@ public class XmlDocumentUtils {
                     final Optional<NotificationDefinition> notificationDef = findNotification(partialQName,
                             notifications.get());
                     if (notificationDef.isPresent()) {
-                        final Set<DataSchemaNode> dataNodes = notificationDef.get().getChildNodes();
+                        final Iterable<DataSchemaNode> dataNodes = notificationDef.get().getChildNodes();
                         final List<Node<?>> domNodes = toDomNodes(childElement,
-                                Optional.<Set<DataSchemaNode>> fromNullable(dataNodes),schemaCtx);
+                                Optional.<Iterable<DataSchemaNode>> fromNullable(dataNodes),schemaCtx);
                         return ImmutableCompositeNode.create(notificationDef.get().getQName(), domNodes);
                     }
                 }
index fe5892a3f61cb5e906ff939fd52b59fe6de90a3d..bafeeaeb8a16de93d367f25a99e56fac5f08e4f4 100644 (file)
@@ -36,8 +36,8 @@ public final class SchemaUtils {
     private SchemaUtils() {
     }
 
-    public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Set<DataSchemaNode> dataSchemaNode) {
-        if (dataSchemaNode != null && !dataSchemaNode.isEmpty() && qname != null) {
+    public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Iterable<DataSchemaNode> dataSchemaNode) {
+        if (dataSchemaNode != null && qname != null) {
             for (DataSchemaNode dsn : dataSchemaNode) {
                 if (qname.isEqualWithoutRevision(dsn.getQName())) {
                     return Optional.<DataSchemaNode> of(dsn);
@@ -55,11 +55,10 @@ public final class SchemaUtils {
     }
 
     public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname) {
-        Set<DataSchemaNode> childNodes = schema.getChildNodes();
-        return findSchemaForChild(schema, qname, childNodes);
+        return findSchemaForChild(schema, qname, schema.getChildNodes());
     }
 
-    public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final Set<DataSchemaNode> childNodes) {
+    public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final Iterable<DataSchemaNode> childNodes) {
         Optional<DataSchemaNode> childSchema = findFirstSchema(qname, childNodes);
         Preconditions.checkState(childSchema.isPresent(),
                 "Unknown child(ren) node(s) detected, identified by: %s, in: %s", qname, schema);
@@ -125,12 +124,10 @@ public final class SchemaUtils {
      * @return Map with all child nodes, to their most top augmentation
      */
     public static Map<QName, ChoiceNode> mapChildElementsFromChoices(final DataNodeContainer schema) {
-        Set<DataSchemaNode> childNodes = schema.getChildNodes();
-
-        return mapChildElementsFromChoices(schema, childNodes);
+        return mapChildElementsFromChoices(schema, schema.getChildNodes());
     }
 
-    private static Map<QName, ChoiceNode> mapChildElementsFromChoices(final DataNodeContainer schema, final Set<DataSchemaNode> childNodes) {
+    private static Map<QName, ChoiceNode> mapChildElementsFromChoices(final DataNodeContainer schema, final Iterable<DataSchemaNode> childNodes) {
         Map<QName, ChoiceNode> mappedChoices = Maps.newLinkedHashMap();
 
         for (final DataSchemaNode childSchema : childNodes) {
index 6fcc0f345db85206043ad4a230dc4b5467f7ffb2..d15c6339c72b93d3c28f638d5ed197e940d2fe24 100644 (file)
@@ -7,6 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema;
 
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
 import java.io.InputStream;
 import java.net.URI;
 import java.util.Collections;
@@ -38,34 +44,28 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
 public class NormalizedDataBuilderTest {
 
     private ContainerSchemaNode containerNode;
     private SchemaContext schema;
 
-    SchemaContext parseTestSchema(String... yangPath) {
+    SchemaContext parseTestSchema(final String... yangPath) {
         YangParserImpl yangParserImpl = new YangParserImpl();
         Set<Module> modules = yangParserImpl.parseYangModelsFromStreams(getTestYangs(yangPath));
         return yangParserImpl.resolveSchemaContext(modules);
     }
 
-    List<InputStream> getTestYangs(String... yangPaths) {
+    List<InputStream> getTestYangs(final String... yangPaths) {
 
         return Lists.newArrayList(Collections2.transform(Lists.newArrayList(yangPaths),
                 new Function<String, InputStream>() {
-                    @Override
-                    public InputStream apply(String input) {
-                        InputStream resourceAsStream = getClass().getResourceAsStream(input);
-                        Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
-                        return resourceAsStream;
-                    }
-                }));
+            @Override
+            public InputStream apply(final String input) {
+                InputStream resourceAsStream = getClass().getResourceAsStream(input);
+                Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
+                return resourceAsStream;
+            }
+        }));
     }
 
     @Before
@@ -92,8 +92,8 @@ public class NormalizedDataBuilderTest {
                 .withChildValue(1)
                 .withChild(
                         Builders.<Integer> leafSetEntryBuilder()
-                                .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
-                .build();
+                        .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
+                        .build();
         builder.withChild(leafList);
 
         // list
@@ -101,12 +101,12 @@ public class NormalizedDataBuilderTest {
                 .mapEntryBuilder()
                 .withChild(
                         Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList"))
-                                .withValue(1).build())
-                .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build())
-                .withNodeIdentifier(
-                        new InstanceIdentifier.NodeIdentifierWithPredicates(getNodeIdentifier("list").getNodeType(),
-                                Collections.singletonMap(getNodeIdentifier("uint32InList").getNodeType(), (Object) 1)))
-                .build();
+                        .withValue(1).build())
+                        .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build())
+                        .withNodeIdentifier(
+                                new InstanceIdentifier.NodeIdentifierWithPredicates(getNodeIdentifier("list").getNodeType(),
+                                        Collections.singletonMap(getNodeIdentifier("uint32InList").getNodeType(), (Object) 1)))
+                                        .build();
 
         MapNode list = Builders.mapBuilder().withChild(listChild1).withNodeIdentifier(getNodeIdentifier("list"))
                 .build();
@@ -116,8 +116,8 @@ public class NormalizedDataBuilderTest {
                 .augmentationBuilder()
                 .withNodeIdentifier(
                         new InstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(getQName("augmentUint32"))))
-                .withChild(
-                        Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32"))
+                        .withChild(
+                                Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32"))
                                 .withValue(11).build()).build();
 
         builder.withChild(augmentation);
@@ -186,7 +186,7 @@ public class NormalizedDataBuilderTest {
         // .build());
     }
 
-    private AugmentationSchema getAugmentationSchemaForChild(ContainerSchemaNode containerNode, QName qName) {
+    private AugmentationSchema getAugmentationSchemaForChild(final ContainerSchemaNode containerNode, final QName qName) {
         for (AugmentationSchema augmentationSchema : containerNode.getAvailableAugmentations()) {
             if (augmentationSchema.getDataChildByName(qName) != null) {
                 return augmentationSchema;
@@ -195,20 +195,20 @@ public class NormalizedDataBuilderTest {
         throw new IllegalStateException("Unable to find child augmentation in " + containerNode);
     }
 
-    private InstanceIdentifier.NodeWithValue getNodeWithValueIdentifier(String localName, Object value) {
+    private InstanceIdentifier.NodeWithValue getNodeWithValueIdentifier(final String localName, final Object value) {
         return new InstanceIdentifier.NodeWithValue(getQName(localName), value);
     }
 
-    private QName getQName(String localName) {
+    private QName getQName(final String localName) {
         String namespace = "namespace";
         return new QName(URI.create(namespace), localName);
     }
 
-    private InstanceIdentifier.NodeIdentifier getNodeIdentifier(String localName) {
+    private InstanceIdentifier.NodeIdentifier getNodeIdentifier(final String localName) {
         return new InstanceIdentifier.NodeIdentifier(getQName(localName));
     }
 
-    public static DataSchemaNode getSchemaNode(SchemaContext context, String moduleName, String childNodeName) {
+    public static DataSchemaNode getSchemaNode(final SchemaContext context, final String moduleName, final String childNodeName) {
         for (Module module : context.getModules()) {
             if (module.getName().equals(moduleName)) {
                 DataSchemaNode found = findChildNode(module.getChildNodes(), childNodeName);
@@ -219,12 +219,13 @@ public class NormalizedDataBuilderTest {
         throw new IllegalStateException("Unable to find child node " + childNodeName);
     }
 
-    static DataSchemaNode findChildNode(Set<DataSchemaNode> children, String name) {
+    private static DataSchemaNode findChildNode(final Iterable<DataSchemaNode> children, final String name) {
         List<DataNodeContainer> containers = Lists.newArrayList();
 
         for (DataSchemaNode dataSchemaNode : children) {
-            if (dataSchemaNode.getQName().getLocalName().equals(name))
+            if (dataSchemaNode.getQName().getLocalName().equals(name)) {
                 return dataSchemaNode;
+            }
             if (dataSchemaNode instanceof DataNodeContainer) {
                 containers.add((DataNodeContainer) dataSchemaNode);
             } else if (dataSchemaNode instanceof ChoiceNode) {
index 8b20b2b72f3ee8f0f00444029d162b8f58988283..8b15c979a276d1b8819b342c4152abb17a5da23d 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.api;
 
+import java.util.Collection;
 import java.util.Set;
 
 import org.opendaylight.yangtools.yang.common.QName;
@@ -25,10 +26,12 @@ public interface DataNodeContainer {
 
     /**
      * Returns set of all child nodes defined within this DataNodeContainer.
+     * Although the return type is a collection, each node is guaranteed to
+     * be present at most once.
      *
      * @return child nodes in lexicographical order
      */
-    Set<DataSchemaNode> getChildNodes();
+    Collection<DataSchemaNode> getChildNodes();
 
     /**
      * Returns set of all groupings defined within this DataNodeContainer.
index 850b51de87f52d091536008723b4075c1ba4763e..025c11c1e26b3fd53d1f7b99b28be84fcb65f59c 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.model.util;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -109,7 +110,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
             return;
         }
 
-        final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
+        final Iterable<DataSchemaNode> childNodes = dataNode.getChildNodes();
         if (childNodes != null) {
             for (DataSchemaNode childNode : childNodes) {
                 if (childNode.isAugmenting()) {
@@ -183,7 +184,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
     @Override
     public boolean hasNext() {
         if (container.getChildNodes() != null) {
-            final Set<DataSchemaNode> childNodes = container.getChildNodes();
+            final Collection<DataSchemaNode> childNodes = container.getChildNodes();
 
             if ((childNodes != null) && !childNodes.isEmpty()) {
                 return childNodes.iterator().hasNext();
index dcf0e94404112045735c7755a1bee9e464283487..0de03b83cb1cf482b0ceca228ffd72726fc35c25 100644 (file)
@@ -136,7 +136,7 @@ base_stmt : BASE_KEYWORD string stmtend;
 identity_stmt : IDENTITY_KEYWORD string (SEMICOLON | (LEFT_BRACE  (identifier_stmt | base_stmt | status_stmt | description_stmt | reference_stmt )* RIGHT_BRACE));
 yin_element_arg : string; // TRUE_KEYWORD | FALSE_KEYWORD;
 yin_element_stmt : YIN_ELEMENT_KEYWORD yin_element_arg stmtend;
-argument_stmt : ARGUMENT_KEYWORD string (SEMICOLON | (LEFT_BRACE  (unknown_statement2)? (yin_element_stmt)? RIGHT_BRACE));
+argument_stmt : ARGUMENT_KEYWORD string (SEMICOLON | (LEFT_BRACE  (unknown_statement2)* (yin_element_stmt)? (unknown_statement2)* RIGHT_BRACE));
 extension_stmt : EXTENSION_KEYWORD string (SEMICOLON | (LEFT_BRACE  (unknown_statement | argument_stmt | status_stmt | description_stmt | reference_stmt )* RIGHT_BRACE));
 revision_date_stmt : REVISION_DATE_KEYWORD string stmtend;
 revision_stmt : REVISION_KEYWORD string (SEMICOLON | (LEFT_BRACE  (description_stmt )? (reference_stmt )? RIGHT_BRACE));
index b227759c6ea93e0c199e4562a4c01bcdb3aeccc2..2ce662647a0994fd0bce50c48d8af92dd3abdce3 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
+
 import org.apache.commons.io.IOUtils;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -662,8 +663,8 @@ public final class BuilderUtils {
     }
 
     public static Set<DataSchemaNodeBuilder> wrapChildNodes(final String moduleName, final int line,
-            final Set<DataSchemaNode> nodes, final SchemaPath parentPath, final QName parentQName) {
-        Set<DataSchemaNodeBuilder> result = new LinkedHashSet<>();
+            final Collection<DataSchemaNode> nodes, final SchemaPath parentPath, final QName parentQName) {
+        Set<DataSchemaNodeBuilder> result = new LinkedHashSet<>(nodes.size());
 
         for (DataSchemaNode node : nodes) {
             QName qname = QName.create(parentQName, node.getQName().getLocalName());
index 459ea32cdd4a1ca91ceaf698a1902ca1f1219a8f..4cb153e22c664ca2321c57d26e705f1c69cd6ffd 100644 (file)
@@ -7,10 +7,21 @@
  */
 package org.opendaylight.yangtools.yang.parser.impl;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Supplier;
+import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSetMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
@@ -39,14 +50,6 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Supplier;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.SetMultimap;
-
 @Immutable
 final class SchemaContextImpl implements SchemaContext {
     private static final Supplier<HashSet<Module>> URI_SET_SUPPLIER = new Supplier<HashSet<Module>>() {
@@ -56,8 +59,23 @@ final class SchemaContextImpl implements SchemaContext {
         }
     };
 
+    private static final Supplier<ArrayList<Module>> MODULE_LIST_SUPPLIER = new Supplier<ArrayList<Module>>() {
+        @Override
+        public ArrayList<Module> get() {
+            return new ArrayList<>();
+        }
+    };
+
+    private static final Comparator<Module> REVISION_COMPARATOR = new Comparator<Module>() {
+        @Override
+        public int compare(final Module o1, final Module o2) {
+            return o1.getRevision().compareTo(o2.getRevision());
+        }
+    };
+
     private final ImmutableMap<ModuleIdentifier, String> identifiersToSources;
     private final ImmutableSetMultimap<URI, Module> namespaceToModules;
+    private final ImmutableListMultimap<String, Module> nameToModules;
     private final ImmutableSet<Module> modules;
 
     SchemaContextImpl(final Set<Module> modules, final Map<ModuleIdentifier, String> identifiersToSources) {
@@ -70,16 +88,27 @@ final class SchemaContextImpl implements SchemaContext {
         this.modules = ImmutableSet.copyOf(ModuleDependencySort.sort(modules.toArray(new Module[modules.size()])));
 
         /*
-         * The most common lookup is from Namespace->Module. Invest some quality time in
-         * building that up.
+         * The most common lookup is from Namespace->Module.
+         *
+         * RESTCONF performs lookups based on module name only, where it wants
+         * to receive the latest revision
+         *
+         * Invest some quality time in building up lookup tables for both.
          */
-        final SetMultimap<URI, Module> multimap = Multimaps.newSetMultimap(
+        final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(
                 new TreeMap<URI, Collection<Module>>(), URI_SET_SUPPLIER);
+        final ListMultimap<String, Module> nameMap = Multimaps.newListMultimap(
+                new TreeMap<String, Collection<Module>>(), MODULE_LIST_SUPPLIER);
         for (Module m : modules) {
-            multimap.put(m.getNamespace(), m);
+            nameMap.put(m.getName(), m);
+            nsMap.put(m.getNamespace(), m);
+        }
+        for (String key : nameMap.keySet()) {
+            Collections.sort(nameMap.get(key), REVISION_COMPARATOR);
         }
 
-        namespaceToModules = ImmutableSetMultimap.copyOf(multimap);
+        namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
+        nameToModules = ImmutableListMultimap.copyOf(nameMap);
     }
 
     @Override
@@ -125,17 +154,15 @@ final class SchemaContextImpl implements SchemaContext {
 
     @Override
     public Module findModuleByName(final String name, final Date revision) {
-        if (name != null) {
-            for (final Module module : modules) {
-                if (revision == null) {
-                    if (module.getName().equals(name)) {
-                        return module;
-                    }
-                } else if (module.getName().equals(name) && module.getRevision().equals(revision)) {
+        final List<Module> mods = nameToModules.get(name);
+        if (mods != null) {
+            for (final Module module : mods) {
+                if (revision == null || module.getRevision().equals(revision)) {
                     return module;
                 }
             }
         }
+
         return null;
     }
 
index 728a1698a864579818cb9a2648ccc6dec4ea25b6..7b543b730702718226447a1ba3efde9ee4cc9a17 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
+
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -23,11 +24,13 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
+import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.NodeImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,6 +45,13 @@ public final class ModuleDependencySort {
 
     private static final Date DEFAULT_REVISION = new Date(0);
     private static final Logger LOGGER = LoggerFactory.getLogger(ModuleDependencySort.class);
+    private static final Function<Node, Module> TOPOLOGY_FUNCTION = new Function<TopologicalSort.Node, Module>() {
+        @Override
+        public Module apply(final TopologicalSort.Node input) {
+            ModuleOrModuleBuilder moduleOrModuleBuilder = ((ModuleNodeImpl) input).getReference();
+            return moduleOrModuleBuilder.getModule();
+        }
+    };
 
     /**
      * It is not desirable to instance this class
@@ -107,14 +117,7 @@ public final class ModuleDependencySort {
         List<TopologicalSort.Node> sorted = sortInternal(ModuleOrModuleBuilder.fromAll(asList(modules),
                 Collections.<ModuleBuilder>emptyList()));
         // Cast to Module from Node and return
-        return Lists.transform(sorted, new Function<TopologicalSort.Node, Module>() {
-
-            @Override
-            public Module apply(final TopologicalSort.Node input) {
-                ModuleOrModuleBuilder moduleOrModuleBuilder = ((ModuleNodeImpl) input).getReference();
-                return moduleOrModuleBuilder.getModule();
-            }
-        });
+        return Lists.transform(sorted, TOPOLOGY_FUNCTION);
     }
 
     private static List<TopologicalSort.Node> sortInternal(final Iterable<ModuleOrModuleBuilder> modules) {
@@ -372,12 +375,12 @@ class ModuleOrModuleBuilder {
     private final Optional<Module> maybeModule;
     private final Optional<ModuleBuilder> maybeModuleBuilder;
 
-    ModuleOrModuleBuilder(Module module) {
+    ModuleOrModuleBuilder(final Module module) {
         maybeModule = Optional.of(module);
         maybeModuleBuilder = Optional.absent();
     }
 
-    ModuleOrModuleBuilder(ModuleBuilder moduleBuilder) {
+    ModuleOrModuleBuilder(final ModuleBuilder moduleBuilder) {
         maybeModule = Optional.absent();
         maybeModuleBuilder = Optional.of(moduleBuilder);
     }
@@ -394,7 +397,7 @@ class ModuleOrModuleBuilder {
         return maybeModuleBuilder.get();
     }
 
-    static List<ModuleOrModuleBuilder> fromAll(Collection<Module> modules, Collection<ModuleBuilder> moduleBuilders) {
+    static List<ModuleOrModuleBuilder> fromAll(final Collection<Module> modules, final Collection<ModuleBuilder> moduleBuilders) {
         List<ModuleOrModuleBuilder> result = new ArrayList<>(modules.size() + moduleBuilders.size());
         for(Module m: modules){
             result.add(new ModuleOrModuleBuilder(m));
index 30c46efc752a6d2fb0d1ae738fd9247f555d10bc..b20c9780875c3729a7219fd9cf7f0ae15f7816ed 100644 (file)
@@ -19,10 +19,12 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -86,7 +88,7 @@ public class AugmentTest {
         expectedSchemaPath = SchemaPath.create(qnames, true);
         assertEquals(expectedSchemaPath, augment.getTargetPath());
 
-        Set<DataSchemaNode> augmentChildren = augment.getChildNodes();
+        Collection<DataSchemaNode> augmentChildren = augment.getChildNodes();
         assertEquals(4, augmentChildren.size());
         for (DataSchemaNode dsn : augmentChildren) {
             TestUtils.checkIsAugmenting(dsn, false);
@@ -285,7 +287,7 @@ public class AugmentTest {
         qnames.add(qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, id.getPath());
-        Set<DataSchemaNode> idChildren = id.getChildNodes();
+        Collection<DataSchemaNode> idChildren = id.getChildNodes();
         assertEquals(1, idChildren.size());
 
         // case node1
@@ -294,7 +296,7 @@ public class AugmentTest {
         qnames.set(4, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, node1.getPath());
-        Set<DataSchemaNode> node1Children = node1.getChildNodes();
+        Collection<DataSchemaNode> node1Children = node1.getChildNodes();
         assertTrue(node1Children.isEmpty());
 
         // case node2
@@ -303,7 +305,7 @@ public class AugmentTest {
         qnames.set(4, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, node2.getPath());
-        Set<DataSchemaNode> node2Children = node2.getChildNodes();
+        Collection<DataSchemaNode> node2Children = node2.getChildNodes();
         assertTrue(node2Children.isEmpty());
 
         // case node3
@@ -312,7 +314,7 @@ public class AugmentTest {
         qnames.set(4, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, node3.getPath());
-        Set<DataSchemaNode> node3Children = node3.getChildNodes();
+        Collection<DataSchemaNode> node3Children = node3.getChildNodes();
         assertEquals(1, node3Children.size());
 
         // test cases
@@ -402,7 +404,7 @@ public class AugmentTest {
         assertEquals(qnames[3], attach.getQName());
         expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
         assertEquals(expectedPath, attach.getPath());
-        Set<DataSchemaNode> attachChildren = attach.getChildNodes();
+        Collection<DataSchemaNode> attachChildren = attach.getChildNodes();
         assertEquals(1, attachChildren.size());
 
         // case create
@@ -410,7 +412,7 @@ public class AugmentTest {
         assertEquals(qnames[3], create.getQName());
         expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
         assertEquals(expectedPath, create.getPath());
-        Set<DataSchemaNode> createChildren = create.getChildNodes();
+        Collection<DataSchemaNode> createChildren = create.getChildNodes();
         assertEquals(1, createChildren.size());
 
         // case attach
@@ -418,7 +420,7 @@ public class AugmentTest {
         assertEquals(qnames[3], destroy.getQName());
         expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
         assertEquals(expectedPath, destroy.getPath());
-        Set<DataSchemaNode> destroyChildren = destroy.getChildNodes();
+        Collection<DataSchemaNode> destroyChildren = destroy.getChildNodes();
         assertEquals(1, destroyChildren.size());
     }
 
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1413Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug1413Test.java
new file mode 100644 (file)
index 0000000..4241414
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Set;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.Module;
+
+/**
+ * Test antlr grammar capability to parse unknown node in extension argument
+ * declaration.
+ *
+ * Not that everything under unknown node is unknown node.
+ */
+public class Bug1413Test {
+
+    @Test
+    public void test() throws Exception {
+        Set<Module> modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1413").toURI());
+        Module bug1413 = TestUtils.findModule(modules, "bug1413");
+        assertNotNull(bug1413);
+
+        List<ExtensionDefinition> extensions = bug1413.getExtensionSchemaNodes();
+        assertEquals(1, extensions.size());
+
+        ExtensionDefinition info = extensions.get(0);
+        assertEquals("text", info.getArgument());
+        assertTrue(info.isYinElement());
+    }
+
+}
index 043c3c7f2944d006aa354734f4205f8d20ed581d..03dc0663de7ba5910a5f54bc294e1d09afe55cfe 100644 (file)
@@ -18,6 +18,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -122,7 +123,7 @@ public class GroupingTest {
         Set<GroupingDefinition> groupings = testModule.getGroupings();
         assertEquals(1, groupings.size());
         GroupingDefinition grouping = groupings.iterator().next();
-        Set<DataSchemaNode> children = grouping.getChildNodes();
+        Collection<DataSchemaNode> children = grouping.getChildNodes();
         assertEquals(5, children.size());
     }
 
@@ -352,7 +353,7 @@ public class GroupingTest {
         assertEquals(1, usesAugments.size());
         AugmentationSchema augment = usesAugments.iterator().next();
         assertEquals("inner augment", augment.getDescription());
-        Set<DataSchemaNode> children = augment.getChildNodes();
+        Collection<DataSchemaNode> children = augment.getChildNodes();
         assertEquals(1, children.size());
         DataSchemaNode leaf = children.iterator().next();
         assertTrue(leaf instanceof LeafSchemaNode);
@@ -411,7 +412,7 @@ public class GroupingTest {
         SchemaPath expectedPath;
 
         // grouping-U
-        Set<DataSchemaNode> childNodes = gu.getChildNodes();
+        Collection<DataSchemaNode> childNodes = gu.getChildNodes();
         assertEquals(7, childNodes.size());
 
         LeafSchemaNode leafGroupingU = (LeafSchemaNode) gu.getDataChildByName("leaf-grouping-U");
index dbdde51e265899e66730686aada2db05645917c7..0ea41a074465192dbb3b076215a0dc58e8527934 100644 (file)
@@ -13,7 +13,9 @@ import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.util.Collection;
 import java.util.Set;
+
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -71,7 +73,7 @@ public class OrderingTest {
         Set<Module> modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
         Module foo = TestUtils.findModule(modules, "foo");
 
-        Set<DataSchemaNode> childNodes = foo.getChildNodes();
+        Collection<DataSchemaNode> childNodes = foo.getChildNodes();
         String[] expectedOrder = new String[] { "int32-leaf", "string-leaf", "length-leaf", "decimal-leaf",
                 "decimal-leaf2", "ext", "union-leaf", "custom-union-leaf", "transfer", "datas", "mycont", "data",
                 "how", "address", "port", "addresses", "peer" };
@@ -93,7 +95,7 @@ public class OrderingTest {
         assertEquals(1, groupings.size());
         GroupingDefinition target = groupings.iterator().next();
 
-        Set<DataSchemaNode> childNodes = target.getChildNodes();
+        Collection<DataSchemaNode> childNodes = target.getChildNodes();
         String[] expectedOrder = new String[] { "data", "how", "address", "port", "addresses" };
         String[] actualOrder = new String[childNodes.size()];
 
@@ -109,10 +111,9 @@ public class OrderingTest {
     public void testOrderingNestedChildNodes3() throws Exception {
         Module baz = TestUtils.loadModule(getClass().getResourceAsStream("/ordering/foo.yang"));
         ContainerSchemaNode x = (ContainerSchemaNode) baz.getDataChildByName("x");
-        Set<DataSchemaNode> childNodes = x.getChildNodes();
+        Collection<DataSchemaNode> childNodes = x.getChildNodes();
 
-        String[] expectedOrder = new String[] { "x15", "x10", "x5", "x1", "a5", "a1", "x2", "b5", "b1", "x3", "ax15",
-                "ax5" };
+        String[] expectedOrder = new String[] { "x15", "x10", "x5", "x1", "a5", "a1", "x2", "b5", "b1", "x3", "ax15", "ax5" };
         String[] actualOrder = new String[childNodes.size()];
 
         int i = 0;
index 79136aa5fc49dc48a51f88a751ed507729257aed..010570dc10b9d4d8d2402f10cefb77e1f38ac653 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Lists;
+
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URI;
@@ -20,10 +21,12 @@ import java.net.URISyntaxException;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -130,7 +133,7 @@ public class UsesAugmentTest {
         path.offer(expectedQName);
         SchemaPath expectedPath = SchemaPath.create(path, true);
         assertEquals(expectedPath, pcreq.getPath());
-        Set<DataSchemaNode> childNodes = pcreq.getChildNodes();
+        Collection<DataSchemaNode> childNodes = pcreq.getChildNodes();
         assertEquals(4, childNodes.size());
         // * |-- leaf version
         LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName("version");
diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug1413/bug1413.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug1413/bug1413.yang
new file mode 100644 (file)
index 0000000..b691ef8
--- /dev/null
@@ -0,0 +1,19 @@
+module bug1413 {
+    yang-version 1;
+    namespace "odl:test:bug1413";
+    prefix "b1413";
+
+    revision "2014-07-25" {
+    }
+
+
+    extension info {
+        argument text {
+            yin-element true;
+            ext:arg-type {
+                type string;
+            }
+        }
+    }
+
+}