Fixing sonar issues 3 13/1113/2
authorJozef Gloncak <jgloncak@cisco.com>
Wed, 4 Sep 2013 12:54:03 +0000 (14:54 +0200)
committerJozef Gloncak <jgloncak@cisco.com>
Mon, 9 Sep 2013 06:39:50 +0000 (08:39 +0200)
Change-Id: I4331f6a3374dbb54e7bfa0856d8a3c166dff42a5
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
35 files changed:
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingTypes.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifier.java
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/RpcError.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/MutableCompositeNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/NodeModificationBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/CompositeNodeTOImpl.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AbstractContainerNode.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/Nodes.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/Builder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/AugmentationSchemaBuilderImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ChoiceBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ConstraintsBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/IdentityrefTypeBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/RpcDefinitionBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/UnionTypeBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/UsesNodeBuilderImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/CopyUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/GroupingUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySort.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ParserListenerUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/RefineHolder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TopologicalSort.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TypeConstraints.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TypeUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/validator/BasicValidations.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/validator/YangModelBasicValidationListener.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/validator/YangModelBasicValidator.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySortTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/validator/YangModelValidationTest.java

index e4e532fba91a22b0f8b8a4207e3f0ab3baf96feb..27961a9065f8f12820aae6ffb06d09ccf2b8e328 100644 (file)
-package org.opendaylight.yangtools.binding.generator.util;\r
-\r
-import java.text.DateFormat;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Arrays;\r
-import java.util.Calendar;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.model.api.Module;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
-\r
-/**\r
- * Contains the methods for converting strings to valid JAVA language strings\r
- * (package names, class names, attribute names).\r
- * \r
- * \r
- */\r
-public final class BindingGeneratorUtil {\r
-\r
-    private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyMMdd");\r
-    \r
-    /**\r
-     * Array of strings values which represents JAVA reserved words.\r
-     */\r
-    private static final String[] SET_VALUES = new String[] { "abstract", "assert", "boolean", "break", "byte", "case",\r
-            "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends",\r
-            "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",\r
-            "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return",\r
-            "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient",\r
-            "true", "try", "void", "volatile", "while" };\r
-\r
-    /**\r
-     * Impossible to instantiate this class. All of the methods or attributes\r
-     * are static.\r
-     */\r
-    private BindingGeneratorUtil() {\r
-    }\r
-\r
-    /**\r
-     * Hash set of words which are reserved in JAVA language.\r
-     */\r
-    private static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(Arrays.asList(SET_VALUES));\r
-\r
-    /**\r
-     * Converts string <code>packageName</code> to valid JAVA package name.\r
-     * \r
-     * If some words of package name are digits of JAVA reserved words they are\r
-     * prefixed with underscore character.\r
-     * \r
-     * @param packageName\r
-     *            string which contains words separated by point.\r
-     * @return package name which contains words separated by point.\r
-     */\r
-    private static String validateJavaPackage(final String packageName) {\r
-        if (packageName != null) {\r
-            final String[] packNameParts = packageName.split("\\.");\r
-            if (packNameParts != null) {\r
-                final StringBuilder builder = new StringBuilder();\r
-                for (int i = 0; i < packNameParts.length; ++i) {\r
-                    final String packNamePart = packNameParts[i];\r
-                    if (Character.isDigit(packNamePart.charAt(0))) {\r
-                        packNameParts[i] = "_" + packNamePart;\r
-                    } else if (JAVA_RESERVED_WORDS.contains(packNamePart)) {\r
-                        packNameParts[i] = "_" + packNamePart;\r
-                    }\r
-                    if (i > 0) {\r
-                        builder.append(".");\r
-                    }\r
-                    builder.append(packNameParts[i]);\r
-                }\r
-                return builder.toString();\r
-            }\r
-        }\r
-        return packageName;\r
-    }\r
-\r
-    /**\r
-     * Converts <code>parameterName</code> to valid JAVA parameter name.\r
-     * \r
-     * If the <code>parameterName</code> is one of the JAVA reserved words then\r
-     * it is prefixed with underscore character.\r
-     * \r
-     * @param parameterName\r
-     *            string with the parameter name\r
-     * @return string with the admissible parameter name\r
-     */\r
-    public static String validateParameterName(final String parameterName) {\r
-        if (parameterName != null && JAVA_RESERVED_WORDS.contains(parameterName)) {\r
-            return "_" + parameterName;\r
-        }\r
-        return parameterName;\r
-    }\r
-\r
-    /**\r
-     * Converts module name to valid JAVA package name.\r
-     * \r
-     * The package name consists of:\r
-     * <ul>\r
-     * <li>prefix - <i>org.opendaylight.yang.gen.v</i></li>\r
-     * <li>module YANG version - <i>org.opendaylight.yang.gen.v</i></li>\r
-     * <li>module namespace - invalid characters are replaced with dots</li>\r
-     * <li>revision prefix - <i>.rev</i></li>\r
-     * <li>revision - YYYYMMDD (MM and DD aren't spread to the whole length)</li>\r
-     * </ul>\r
-     * \r
-     * @param module\r
-     *            module which contains data about namespace and revision date\r
-     * @return string with the valid JAVA package name\r
-     * @throws IllegalArgumentException\r
-     *             if the revision date of the <code>module</code> equals\r
-     *             <code>null</code>\r
-     */\r
-    public static String moduleNamespaceToPackageName(final Module module) {\r
-        final StringBuilder packageNameBuilder = new StringBuilder();\r
-\r
-        if (module.getRevision() == null) {\r
-            throw new IllegalArgumentException("Module " + module.getName() + " does not specify revision date!");\r
-        }\r
-        packageNameBuilder.append("org.opendaylight.yang.gen.v");\r
-        packageNameBuilder.append(module.getYangVersion());\r
-        packageNameBuilder.append(".");\r
-\r
-        String namespace = module.getNamespace().toString();\r
-        namespace = namespace.replace("://", ".");\r
-        namespace = namespace.replace("/", ".");\r
-        namespace = namespace.replace(":", ".");\r
-        namespace = namespace.replace("-", ".");\r
-        namespace = namespace.replace("@", ".");\r
-        namespace = namespace.replace("$", ".");\r
-        namespace = namespace.replace("#", ".");\r
-        namespace = namespace.replace("'", ".");\r
-        namespace = namespace.replace("*", ".");\r
-        namespace = namespace.replace("+", ".");\r
-        namespace = namespace.replace(",", ".");\r
-        namespace = namespace.replace(";", ".");\r
-        namespace = namespace.replace("=", ".");\r
-\r
-        packageNameBuilder.append(namespace);\r
-        packageNameBuilder.append(".rev");\r
-        packageNameBuilder.append(DATE_FORMAT.format(module.getRevision()));\r
-        \r
-        return validateJavaPackage(packageNameBuilder.toString());\r
-    }\r
-\r
-    /**\r
-     * Creates package name from specified <code>basePackageName</code> (package\r
-     * name for module) and <code>schemaPath</code>.\r
-     * \r
-     * Resulting package name is concatenation of <code>basePackageName</code>\r
-     * and all local names of YANG nodes which are parents of some node for\r
-     * which <code>schemaPath</code> is specified.\r
-     * \r
-     * @param basePackageName\r
-     *            string with package name of the module\r
-     * @param schemaPath\r
-     *            list of names of YANG nodes which are parents of some node +\r
-     *            name of this node\r
-     * @return string with valid JAVA package name\r
-     */\r
-    public static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath) {\r
-        if (basePackageName == null) {\r
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");\r
-        }\r
-        if (schemaPath == null) {\r
-            throw new IllegalArgumentException("Schema Path cannot be NULL!");\r
-        }\r
-\r
-        final StringBuilder builder = new StringBuilder();\r
-        builder.append(basePackageName);\r
-        final List<QName> pathToNode = schemaPath.getPath();\r
-        final int traversalSteps = (pathToNode.size() - 1);\r
-        for (int i = 0; i < traversalSteps; ++i) {\r
-            builder.append(".");\r
-            String nodeLocalName = pathToNode.get(i).getLocalName();\r
-\r
-            nodeLocalName = nodeLocalName.replace(":", ".");\r
-            nodeLocalName = nodeLocalName.replace("-", ".");\r
-            builder.append(nodeLocalName);\r
-        }\r
-        return validateJavaPackage(builder.toString());\r
-    }\r
-\r
-    /**\r
-     * Generates the package name for type definition from\r
-     * <code>typeDefinition</code> and <code>basePackageName</code>.\r
-     * \r
-     * @param basePackageName\r
-     *            string with the package name of the module\r
-     * @param typeDefinition\r
-     *            type definition for which the package name will be generated *\r
-     * @return string with valid JAVA package name\r
-     * @throws IllegalArgumentException\r
-     *             <ul>\r
-     *             <li>if <code>basePackageName</code> equals <code>null</code></li>\r
-     *             <li>if <code>typeDefinition</code> equals <code>null</code></li>\r
-     *             </ul>\r
-     */\r
-    public static String packageNameForTypeDefinition(final String basePackageName,\r
-            final TypeDefinition<?> typeDefinition) {\r
-        if (basePackageName == null) {\r
-            throw new IllegalArgumentException("Base Package Name cannot be NULL!");\r
-        }\r
-        if (typeDefinition == null) {\r
-            throw new IllegalArgumentException("Type Definition reference cannot be NULL!");\r
-        }\r
-\r
-        final StringBuilder builder = new StringBuilder();\r
-        builder.append(basePackageName);\r
-        return validateJavaPackage(builder.toString());\r
-    }\r
-\r
-    /**\r
-     * Converts <code>token</code> to string which is in accordance with best\r
-     * practices for JAVA class names.\r
-     * \r
-     * @param token\r
-     *            string which contains characters which should be converted to\r
-     *            JAVA class name\r
-     * @return string which is in accordance with best practices for JAVA class\r
-     *         name.\r
-     */\r
-    public static String parseToClassName(String token) {\r
-        String correctStr = token.replace(".", "");\r
-        correctStr = parseToCamelCase(correctStr);\r
-\r
-        // make first char upper-case\r
-        char first = Character.toUpperCase(correctStr.charAt(0));\r
-        if (first >= '0' && first <= '9') {\r
-\r
-            correctStr = "_" + correctStr;\r
-        } else {\r
-            correctStr = first + correctStr.substring(1);\r
-        }\r
-        return correctStr;\r
-    }\r
-\r
-    /**\r
-     * Converts <code>token</code> to string which is in accordance with best\r
-     * practices for JAVA parameter names.\r
-     * \r
-     * @param token\r
-     *            string which contains characters which should be converted to\r
-     *            JAVA parameter name\r
-     * @return string which is in accordance with best practices for JAVA\r
-     *         parameter name.\r
-     */\r
-    public static String parseToValidParamName(final String token) {\r
-        final String validToken = token.replace(".", "");\r
-        String correctStr = parseToCamelCase(validToken);\r
-\r
-        // make first char lower-case\r
-        char first = Character.toLowerCase(correctStr.charAt(0));\r
-        correctStr = first + correctStr.substring(1);\r
-        return validateParameterName(correctStr);\r
-    }\r
-\r
-    /**\r
-     * Converts <code>token</code> to capital letters and removes invalid\r
-     * characters.\r
-     * \r
-     * @param token\r
-     *            string with characters which should be conversed to capital\r
-     * @return string with capital letters\r
-     */\r
-    public static String convertToCapitalLetters(final String token) {\r
-        String convertedStr = token.replace(" ", "_");\r
-        convertedStr = convertedStr.replace(".", "_");\r
-        convertedStr = convertedStr.toUpperCase();\r
-        return convertedStr;\r
-    }\r
-\r
-    /**\r
-     * \r
-     * Converts string <code>token</code> to the cammel case format.\r
-     * \r
-     * @param token\r
-     *            string which should be converted to the cammel case format\r
-     * @return string in the cammel case format\r
-     * @throws IllegalArgumentException\r
-     *             <ul>\r
-     *             <li>if <code>token</code> without white spaces is empty</li>\r
-     *             <li>if <code>token</code> equals null</li>\r
-     *             </ul>\r
-     */\r
-    private static String parseToCamelCase(String token) {\r
-        if (token == null) {\r
-            throw new IllegalArgumentException("Name can not be null");\r
-        }\r
-\r
-        String correctStr = token.trim();\r
-        if (correctStr.isEmpty()) {\r
-            throw new IllegalArgumentException("Name can not be emty");\r
-        }\r
-\r
-        correctStr = replaceWithCamelCase(correctStr, ' ');\r
-        correctStr = replaceWithCamelCase(correctStr, '-');\r
-        correctStr = replaceWithCamelCase(correctStr, '_');\r
-        return correctStr;\r
-    }\r
-\r
-    /**\r
-     * Replaces all the occurances of the <code>removalChar</code> in the\r
-     * <code>text</code> with empty string and converts following character to\r
-     * upper case.\r
-     * \r
-     * @param text\r
-     *            string with source text which should be converted\r
-     * @param removalChar\r
-     *            character which is sought in the <code>text</code>\r
-     * @return string which doesn't contain <code>removalChar</code> and has\r
-     *         following characters converted to upper case\r
-     * @throws IllegalArgumentException\r
-     *             if the length of the returning string has length 0\r
-     */\r
-    private static String replaceWithCamelCase(String text, char removalChar) {\r
-        StringBuilder sb = new StringBuilder(text);\r
-        String toBeRemoved = String.valueOf(removalChar);\r
-\r
-        int toBeRemovedPos = sb.indexOf(toBeRemoved);\r
-        while (toBeRemovedPos != -1) {\r
-            sb.replace(toBeRemovedPos, toBeRemovedPos + 1, "");\r
-            // check if 'toBeRemoved' character is not the only character in\r
-            // 'text'\r
-            if (sb.length() == 0) {\r
-                throw new IllegalArgumentException("The resulting string can not be empty");\r
-            }\r
-            String replacement = String.valueOf(sb.charAt(toBeRemovedPos)).toUpperCase();\r
-            sb.setCharAt(toBeRemovedPos, replacement.charAt(0));\r
-            toBeRemovedPos = sb.indexOf(toBeRemoved);\r
-        }\r
-        return sb.toString();\r
-    }\r
-}\r
+package org.opendaylight.yangtools.binding.generator.util;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+
+/**
+ * Contains the methods for converting strings to valid JAVA language strings
+ * (package names, class names, attribute names).
+ * 
+ * 
+ */
+public final class BindingGeneratorUtil {
+
+    private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyMMdd");
+    
+    /**
+     * Array of strings values which represents JAVA reserved words.
+     */
+    private static final String[] SET_VALUES = new String[] { "abstract", "assert", "boolean", "break", "byte", "case",
+            "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum", "extends",
+            "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",
+            "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return",
+            "short", "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient",
+            "true", "try", "void", "volatile", "while" };
+
+    /**
+     * Impossible to instantiate this class. All of the methods or attributes
+     * are static.
+     */
+    private BindingGeneratorUtil() {
+    }
+
+    /**
+     * Hash set of words which are reserved in JAVA language.
+     */
+    private static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(Arrays.asList(SET_VALUES));
+
+    /**
+     * Converts string <code>packageName</code> to valid JAVA package name.
+     * 
+     * If some words of package name are digits of JAVA reserved words they are
+     * prefixed with underscore character.
+     * 
+     * @param packageName
+     *            string which contains words separated by point.
+     * @return package name which contains words separated by point.
+     */
+    private static String validateJavaPackage(final String packageName) {
+        if (packageName != null) {
+            final String[] packNameParts = packageName.split("\\.");
+            if (packNameParts != null) {
+                final StringBuilder builder = new StringBuilder();
+                for (int i = 0; i < packNameParts.length; ++i) {
+                    final String packNamePart = packNameParts[i];
+                    if (Character.isDigit(packNamePart.charAt(0))) {
+                        packNameParts[i] = "_" + packNamePart;
+                    } else if (JAVA_RESERVED_WORDS.contains(packNamePart)) {
+                        packNameParts[i] = "_" + packNamePart;
+                    }
+                    if (i > 0) {
+                        builder.append(".");
+                    }
+                    builder.append(packNameParts[i]);
+                }
+                return builder.toString();
+            }
+        }
+        return packageName;
+    }
+
+    /**
+     * Converts <code>parameterName</code> to valid JAVA parameter name.
+     * 
+     * If the <code>parameterName</code> is one of the JAVA reserved words then
+     * it is prefixed with underscore character.
+     * 
+     * @param parameterName
+     *            string with the parameter name
+     * @return string with the admissible parameter name
+     */
+    public static String validateParameterName(final String parameterName) {
+        if (parameterName != null && JAVA_RESERVED_WORDS.contains(parameterName)) {
+            return "_" + parameterName;
+        }
+        return parameterName;
+    }
+
+    /**
+     * Converts module name to valid JAVA package name.
+     * 
+     * The package name consists of:
+     * <ul>
+     * <li>prefix - <i>org.opendaylight.yang.gen.v</i></li>
+     * <li>module YANG version - <i>org.opendaylight.yang.gen.v</i></li>
+     * <li>module namespace - invalid characters are replaced with dots</li>
+     * <li>revision prefix - <i>.rev</i></li>
+     * <li>revision - YYYYMMDD (MM and DD aren't spread to the whole length)</li>
+     * </ul>
+     * 
+     * @param module
+     *            module which contains data about namespace and revision date
+     * @return string with the valid JAVA package name
+     * @throws IllegalArgumentException
+     *             if the revision date of the <code>module</code> equals
+     *             <code>null</code>
+     */
+    public static String moduleNamespaceToPackageName(final Module module) {
+        final StringBuilder packageNameBuilder = new StringBuilder();
+
+        if (module.getRevision() == null) {
+            throw new IllegalArgumentException("Module " + module.getName() + " does not specify revision date!");
+        }
+        packageNameBuilder.append("org.opendaylight.yang.gen.v");
+        packageNameBuilder.append(module.getYangVersion());
+        packageNameBuilder.append(".");
+
+        String namespace = module.getNamespace().toString();
+        namespace = namespace.replace("://", ".");
+        namespace = namespace.replace("/", ".");
+        namespace = namespace.replace(":", ".");
+        namespace = namespace.replace("-", ".");
+        namespace = namespace.replace("@", ".");
+        namespace = namespace.replace("$", ".");
+        namespace = namespace.replace("#", ".");
+        namespace = namespace.replace("'", ".");
+        namespace = namespace.replace("*", ".");
+        namespace = namespace.replace("+", ".");
+        namespace = namespace.replace(",", ".");
+        namespace = namespace.replace(";", ".");
+        namespace = namespace.replace("=", ".");
+
+        packageNameBuilder.append(namespace);
+        packageNameBuilder.append(".rev");
+        packageNameBuilder.append(DATE_FORMAT.format(module.getRevision()));
+        
+        return validateJavaPackage(packageNameBuilder.toString());
+    }
+
+    /**
+     * Creates package name from specified <code>basePackageName</code> (package
+     * name for module) and <code>schemaPath</code>.
+     * 
+     * Resulting package name is concatenation of <code>basePackageName</code>
+     * and all local names of YANG nodes which are parents of some node for
+     * which <code>schemaPath</code> is specified.
+     * 
+     * @param basePackageName
+     *            string with package name of the module
+     * @param schemaPath
+     *            list of names of YANG nodes which are parents of some node +
+     *            name of this node
+     * @return string with valid JAVA package name
+     */
+    public static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath) {
+        if (basePackageName == null) {
+            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+        }
+        if (schemaPath == null) {
+            throw new IllegalArgumentException("Schema Path cannot be NULL!");
+        }
+
+        final StringBuilder builder = new StringBuilder();
+        builder.append(basePackageName);
+        final List<QName> pathToNode = schemaPath.getPath();
+        final int traversalSteps = (pathToNode.size() - 1);
+        for (int i = 0; i < traversalSteps; ++i) {
+            builder.append(".");
+            String nodeLocalName = pathToNode.get(i).getLocalName();
+
+            nodeLocalName = nodeLocalName.replace(":", ".");
+            nodeLocalName = nodeLocalName.replace("-", ".");
+            builder.append(nodeLocalName);
+        }
+        return validateJavaPackage(builder.toString());
+    }
+
+    /**
+     * Generates the package name for type definition from
+     * <code>typeDefinition</code> and <code>basePackageName</code>.
+     * 
+     * @param basePackageName
+     *            string with the package name of the module
+     * @param typeDefinition
+     *            type definition for which the package name will be generated *
+     * @return string with valid JAVA package name
+     * @throws IllegalArgumentException
+     *             <ul>
+     *             <li>if <code>basePackageName</code> equals <code>null</code></li>
+     *             <li>if <code>typeDefinition</code> equals <code>null</code></li>
+     *             </ul>
+     */
+    public static String packageNameForTypeDefinition(final String basePackageName,
+            final TypeDefinition<?> typeDefinition) {
+        if (basePackageName == null) {
+            throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+        }
+        if (typeDefinition == null) {
+            throw new IllegalArgumentException("Type Definition reference cannot be NULL!");
+        }
+
+        final StringBuilder builder = new StringBuilder();
+        builder.append(basePackageName);
+        return validateJavaPackage(builder.toString());
+    }
+
+    /**
+     * Converts <code>token</code> to string which is in accordance with best
+     * practices for JAVA class names.
+     * 
+     * @param token
+     *            string which contains characters which should be converted to
+     *            JAVA class name
+     * @return string which is in accordance with best practices for JAVA class
+     *         name.
+     */
+    public static String parseToClassName(String token) {
+        String correctStr = token.replace(".", "");
+        correctStr = parseToCamelCase(correctStr);
+
+        // make first char upper-case
+        char first = Character.toUpperCase(correctStr.charAt(0));
+        if (first >= '0' && first <= '9') {
+
+            correctStr = "_" + correctStr;
+        } else {
+            correctStr = first + correctStr.substring(1);
+        }
+        return correctStr;
+    }
+
+    /**
+     * Converts <code>token</code> to string which is in accordance with best
+     * practices for JAVA parameter names.
+     * 
+     * @param token
+     *            string which contains characters which should be converted to
+     *            JAVA parameter name
+     * @return string which is in accordance with best practices for JAVA
+     *         parameter name.
+     */
+    public static String parseToValidParamName(final String token) {
+        final String validToken = token.replace(".", "");
+        String correctStr = parseToCamelCase(validToken);
+
+        // make first char lower-case
+        char first = Character.toLowerCase(correctStr.charAt(0));
+        correctStr = first + correctStr.substring(1);
+        return validateParameterName(correctStr);
+    }
+
+    /**
+     * Converts <code>token</code> to capital letters and removes invalid
+     * characters.
+     * 
+     * @param token
+     *            string with characters which should be conversed to capital
+     * @return string with capital letters
+     */
+    public static String convertToCapitalLetters(final String token) {
+        String convertedStr = token.replace(" ", "_");
+        convertedStr = convertedStr.replace(".", "_");
+        convertedStr = convertedStr.toUpperCase();
+        return convertedStr;
+    }
+
+    /**
+     * 
+     * Converts string <code>token</code> to the cammel case format.
+     * 
+     * @param token
+     *            string which should be converted to the cammel case format
+     * @return string in the cammel case format
+     * @throws IllegalArgumentException
+     *             <ul>
+     *             <li>if <code>token</code> without white spaces is empty</li>
+     *             <li>if <code>token</code> equals null</li>
+     *             </ul>
+     */
+    private static String parseToCamelCase(String token) {
+        if (token == null) {
+            throw new IllegalArgumentException("Name can not be null");
+        }
+
+        String correctStr = token.trim();
+        if (correctStr.isEmpty()) {
+            throw new IllegalArgumentException("Name can not be emty");
+        }
+
+        correctStr = replaceWithCamelCase(correctStr, ' ');
+        correctStr = replaceWithCamelCase(correctStr, '-');
+        correctStr = replaceWithCamelCase(correctStr, '_');
+        return correctStr;
+    }
+
+    /**
+     * Replaces all the occurances of the <code>removalChar</code> in the
+     * <code>text</code> with empty string and converts following character to
+     * upper case.
+     * 
+     * @param text
+     *            string with source text which should be converted
+     * @param removalChar
+     *            character which is sought in the <code>text</code>
+     * @return string which doesn't contain <code>removalChar</code> and has
+     *         following characters converted to upper case
+     * @throws IllegalArgumentException
+     *             if the length of the returning string has length 0
+     */
+    private static String replaceWithCamelCase(String text, char removalChar) {
+        StringBuilder sb = new StringBuilder(text);
+        String toBeRemoved = String.valueOf(removalChar);
+
+        int toBeRemovedPos = sb.indexOf(toBeRemoved);
+        while (toBeRemovedPos != -1) {
+            sb.replace(toBeRemovedPos, toBeRemovedPos + 1, "");
+            // check if 'toBeRemoved' character is not the only character in
+            // 'text'
+            if (sb.length() == 0) {
+                throw new IllegalArgumentException("The resulting string can not be empty");
+            }
+            String replacement = String.valueOf(sb.charAt(toBeRemovedPos)).toUpperCase();
+            sb.setCharAt(toBeRemovedPos, replacement.charAt(0));
+            toBeRemovedPos = sb.indexOf(toBeRemoved);
+        }
+        return sb.toString();
+    }
+}
index 82ffacfa53d47bf7f1b3522edb0a71ffb0fb5eba..eb5ff850dbc32b19e5f71e51f2a2d2e294b124c6 100644 (file)
@@ -24,7 +24,7 @@ public final class BindingTypes {
 
     }
 
-    public static final ParameterizedType augmentable(Type t) {
+    public static ParameterizedType augmentable(Type t) {
         return parameterizedTypeFor(AUGMENTABLE, t);
     }
 }
index 90d42a74018a55278f44f95b35f159277290c62d..ed90626f29b44eb0a4ebbd3b5e8ad6647ba5eb62 100644 (file)
@@ -1,81 +1,77 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.binding;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-/**\r
- * Uniquely identifies instance of data tree. \r
- *\r
- *\r
- */\r
-public class InstanceIdentifier {\r
-\r
-    \r
-    private final List<PathArgument> path;\r
-    private final Class<? extends DataObject> targetType;\r
-    \r
-    public InstanceIdentifier(Class<? extends DataObject> type) {\r
-        path = Collections.emptyList();\r
-        this.targetType = type;\r
-    }\r
-    \r
-    \r
-    public InstanceIdentifier(List<PathArgument> path,Class<? extends DataObject> type) {\r
-        this.path = Collections.<PathArgument>unmodifiableList(new ArrayList<>(path));\r
-        this.targetType = type;\r
-    }\r
-    \r
-\r
-    /**\r
-     * \r
-     * @return\r
-     */\r
-    public List<PathArgument> getPath() {\r
-        return this.path;\r
-    }\r
-    \r
-    public Class<?> getTargetType() {\r
-        return this.targetType;\r
-    }\r
-    \r
-    \r
-    /**\r
-     * Path argument of instance identifier.\r
-     * \r
-     * Interface which implementations are used as path components\r
-     * of the instance path.\r
-     * \r
-     * @author ttkacik\r
-     *\r
-     */\r
-    public static interface PathArgument {\r
-        \r
-    }\r
-    \r
-    public static class IdentifiableItem<I extends Identifiable<T>,T extends Identifier<I>>  implements PathArgument {\r
-           \r
-        private final T key;\r
-        private final Class<? extends I> type;\r
-\r
-        public IdentifiableItem(Class<I> type, T key) {\r
-            this.type = type;\r
-            this.key = key;\r
-        }\r
-        \r
-        T getKey() {\r
-            return this.key;\r
-        }\r
-        \r
-        Class<? extends I> getType() {\r
-            return this.type;\r
-        }\r
-    }\r
-}\r
+/*
+ * 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.binding;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Uniquely identifies instance of data tree.
+ * 
+ * 
+ */
+public class InstanceIdentifier {
+
+    private final List<PathArgument> path;
+    private final Class<? extends DataObject> targetType;
+
+    public InstanceIdentifier(Class<? extends DataObject> type) {
+        path = Collections.emptyList();
+        this.targetType = type;
+    }
+
+    public InstanceIdentifier(List<PathArgument> path, Class<? extends DataObject> type) {
+        this.path = Collections.<PathArgument> unmodifiableList(new ArrayList<>(path));
+        this.targetType = type;
+    }
+
+    /**
+     * 
+     * @return
+     */
+    public List<PathArgument> getPath() {
+        return this.path;
+    }
+
+    public Class<?> getTargetType() {
+        return this.targetType;
+    }
+
+    /**
+     * Path argument of instance identifier.
+     * 
+     * Interface which implementations are used as path components of the
+     * instance path.
+     * 
+     * @author ttkacik
+     * 
+     */
+    interface PathArgument {
+
+    }
+
+    public static class IdentifiableItem<I extends Identifiable<T>, T extends Identifier<I>> implements PathArgument {
+
+        private final T key;
+        private final Class<? extends I> type;
+
+        public IdentifiableItem(Class<I> type, T key) {
+            this.type = type;
+            this.key = key;
+        }
+
+        T getKey() {
+            return this.key;
+        }
+
+        Class<? extends I> getType() {
+            return this.type;
+        }
+    }
+}
index 0d17c76eb9d6184a7343c850c50d43ef81dafa26..99069d27bde67c685c0ba65fceac32ffaeb80d41 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.common;\r
-\r
-import java.net.URI;\r
-import java.net.URISyntaxException;\r
-\r
-import java.text.SimpleDateFormat;\r
-import java.util.Date;\r
-\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * The QName from XML consists of local name of element and XML namespace, but\r
- * for our use, we added module revision to it.\r
- * \r
- * In YANG context QName is full name of defined node, type, procedure or\r
- * notification. QName consists of XML namespace, YANG model revision and local\r
- * name of defined type. It is used to prevent name clashes between nodes with\r
- * same local name, but from different schemas.\r
- * \r
- * <ul>\r
- * <li><b>XMLNamespace</b> - the namespace assigned to the YANG module which\r
- * defined element, type, procedure or notification.</li>\r
- * <li><b>Revision</b> - the revision of the YANG module which describes the\r
- * element</li>\r
- * <li><b>LocalName</b> - the YANG schema identifier which were defined for this\r
- * node in the YANG module</li>\r
- * </ul>\r
- * \r
- * \r
- */\r
-public final class QName {\r
-    protected static final Logger logger = LoggerFactory\r
-        .getLogger(QName.class);\r
-\r
-    private SimpleDateFormat revisionFormat = new SimpleDateFormat("yyyy-MM-dd");\r
-\r
-    final URI namespace;\r
-    final String localName;\r
-    final String prefix;\r
-    final Date revision;\r
-\r
-    /**\r
-     * QName Constructor.\r
-     * \r
-     * @param namespace\r
-     *            the namespace assigned to the YANG module\r
-     * @param revision\r
-     *            the revision of the YANG module\r
-     * @param prefix\r
-     *            locally defined prefix assigned to local name\r
-     * @param localName\r
-     *            YANG schema identifier\r
-     */\r
-    public QName(URI namespace, Date revision, String prefix, String localName) {\r
-        this.namespace = namespace;\r
-        this.localName = localName;\r
-        this.revision = revision;\r
-        this.prefix = prefix;\r
-    }\r
-\r
-    /**\r
-     * QName Constructor.\r
-     * \r
-     * @param namespace\r
-     *            the namespace assigned to the YANG module\r
-     * @param localName\r
-     *            YANG schema identifier\r
-     */\r
-    public QName(URI namespace, String localName) {\r
-        this(namespace, null, "", localName);\r
-    }\r
-\r
-    /**\r
-     * QName Constructor.\r
-     * \r
-     * @param namespace\r
-     *            the namespace assigned to the YANG module\r
-     * @param revision\r
-     *            the revision of the YANG module\r
-     * @param localName\r
-     *            YANG schema identifier\r
-     */\r
-    public QName(URI namespace, Date revision, String localName) {\r
-        this(namespace, revision, null, localName);\r
-    }\r
-\r
-    public QName(QName base, String localName) {\r
-        this(base.getNamespace(), base.getRevision(), base.getPrefix(),\r
-                localName);\r
-    }\r
-\r
-    /**\r
-     * Returns XMLNamespace assigned to the YANG module.\r
-     * \r
-     * @return XMLNamespace assigned to the YANG module.\r
-     */\r
-    public URI getNamespace() {\r
-        return namespace;\r
-    }\r
-\r
-    /**\r
-     * Returns YANG schema identifier which were defined for this node in the\r
-     * YANG module\r
-     * \r
-     * @return YANG schema identifier which were defined for this node in the\r
-     *         YANG module\r
-     */\r
-    public String getLocalName() {\r
-        return localName;\r
-    }\r
-\r
-    /**\r
-     * Returns revision of the YANG module if the module has defined revision,\r
-     * otherwise returns <code>null</code>\r
-     * \r
-     * @return revision of the YANG module if the module has defined revision,\r
-     *         otherwise returns <code>null</code>\r
-     */\r
-    public Date getRevision() {\r
-        return revision;\r
-    }\r
-\r
-    /**\r
-     * Returns locally defined prefix assigned to local name\r
-     * \r
-     * @return locally defined prefix assigned to local name\r
-     */\r
-    public String getPrefix() {\r
-        return prefix;\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        final int prime = 31;\r
-        int result = 1;\r
-        result = prime * result\r
-                + ((localName == null) ? 0 : localName.hashCode());\r
-        result = prime * result\r
-                + ((namespace == null) ? 0 : namespace.hashCode());\r
-        result = prime * result\r
-                + ((revision == null) ? 0 : revision.hashCode());\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (this == obj)\r
-            return true;\r
-        if (obj == null)\r
-            return false;\r
-        if (getClass() != obj.getClass())\r
-            return false;\r
-        QName other = (QName) obj;\r
-        if (localName == null) {\r
-            if (other.localName != null)\r
-                return false;\r
-        } else if (!localName.equals(other.localName))\r
-            return false;\r
-        if (namespace == null) {\r
-            if (other.namespace != null)\r
-                return false;\r
-        } else if (!namespace.equals(other.namespace))\r
-            return false;\r
-        if (revision == null) {\r
-            if (other.revision != null)\r
-                return false;\r
-        } else if (!revision.equals(other.revision))\r
-            return false;\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        StringBuilder sb = new StringBuilder();\r
-        if (namespace != null) {\r
-            sb.append("(" + namespace);\r
-\r
-            if (revision != null) {\r
-                sb.append("?revision=" + revisionFormat.format(revision));\r
-            }\r
-            sb.append(")");\r
-        }\r
-        sb.append(localName);\r
-        return sb.toString();\r
-    }\r
-\r
-    /**\r
-     * Returns a namespace in form defined by section 5.6.4. of {@link https\r
-     * ://tools.ietf.org/html/rfc6020}, if namespace is not correctly defined,\r
-     * the method will return <code>null</code> <br>\r
-     * example "http://example.acme.com/system?revision=2008-04-01"\r
-     * \r
-     * @return namespace in form defined by section 5.6.4. of {@link https\r
-     *         ://tools.ietf.org/html/rfc6020}, if namespace is not correctly\r
-     *         defined, the method will return <code>null</code>\r
-     * \r
-     */\r
-    URI getRevisionNamespace() {\r
-\r
-        if (namespace == null)\r
-            return null;\r
-\r
-        String query = "";\r
-        if (revision != null) {\r
-            query = "revision=" + revisionFormat.format(revision);\r
-        }\r
-\r
-        URI compositeURI = null;\r
-        try {\r
-            compositeURI = new URI(namespace.getScheme(),\r
-                    namespace.getUserInfo(), namespace.getHost(),\r
-                    namespace.getPort(), namespace.getPath(), query,\r
-                    namespace.getFragment());\r
-        } catch (URISyntaxException e) {\r
-            logger.error("",e);\r
-        }\r
-        return compositeURI;\r
-    }\r
-}\r
+/*
+ * 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.common;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The QName from XML consists of local name of element and XML namespace, but
+ * for our use, we added module revision to it.
+ * 
+ * In YANG context QName is full name of defined node, type, procedure or
+ * notification. QName consists of XML namespace, YANG model revision and local
+ * name of defined type. It is used to prevent name clashes between nodes with
+ * same local name, but from different schemas.
+ * 
+ * <ul>
+ * <li><b>XMLNamespace</b> - the namespace assigned to the YANG module which
+ * defined element, type, procedure or notification.</li>
+ * <li><b>Revision</b> - the revision of the YANG module which describes the
+ * element</li>
+ * <li><b>LocalName</b> - the YANG schema identifier which were defined for this
+ * node in the YANG module</li>
+ * </ul>
+ * 
+ * 
+ */
+public final class QName {
+    protected static final Logger LOGGER = LoggerFactory.getLogger(QName.class);
+
+    private SimpleDateFormat revisionFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+    private final URI namespace;
+    private final String localName;
+    private final String prefix;
+    private final Date revision;
+
+    /**
+     * QName Constructor.
+     * 
+     * @param namespace
+     *            the namespace assigned to the YANG module
+     * @param revision
+     *            the revision of the YANG module
+     * @param prefix
+     *            locally defined prefix assigned to local name
+     * @param localName
+     *            YANG schema identifier
+     */
+    public QName(URI namespace, Date revision, String prefix, String localName) {
+        this.namespace = namespace;
+        this.localName = localName;
+        this.revision = revision;
+        this.prefix = prefix;
+    }
+
+    /**
+     * QName Constructor.
+     * 
+     * @param namespace
+     *            the namespace assigned to the YANG module
+     * @param localName
+     *            YANG schema identifier
+     */
+    public QName(URI namespace, String localName) {
+        this(namespace, null, "", localName);
+    }
+
+    /**
+     * QName Constructor.
+     * 
+     * @param namespace
+     *            the namespace assigned to the YANG module
+     * @param revision
+     *            the revision of the YANG module
+     * @param localName
+     *            YANG schema identifier
+     */
+    public QName(URI namespace, Date revision, String localName) {
+        this(namespace, revision, null, localName);
+    }
+
+    public QName(QName base, String localName) {
+        this(base.getNamespace(), base.getRevision(), base.getPrefix(), localName);
+    }
+
+    /**
+     * Returns XMLNamespace assigned to the YANG module.
+     * 
+     * @return XMLNamespace assigned to the YANG module.
+     */
+    public URI getNamespace() {
+        return namespace;
+    }
+
+    /**
+     * Returns YANG schema identifier which were defined for this node in the
+     * YANG module
+     * 
+     * @return YANG schema identifier which were defined for this node in the
+     *         YANG module
+     */
+    public String getLocalName() {
+        return localName;
+    }
+
+    /**
+     * Returns revision of the YANG module if the module has defined revision,
+     * otherwise returns <code>null</code>
+     * 
+     * @return revision of the YANG module if the module has defined revision,
+     *         otherwise returns <code>null</code>
+     */
+    public Date getRevision() {
+        return revision;
+    }
+
+    /**
+     * Returns locally defined prefix assigned to local name
+     * 
+     * @return locally defined prefix assigned to local name
+     */
+    public String getPrefix() {
+        return prefix;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((localName == null) ? 0 : localName.hashCode());
+        result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
+        result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        QName other = (QName) obj;
+        if (localName == null) {
+            if (other.localName != null) {
+                return false;
+            }
+        } else if (!localName.equals(other.localName)) {
+            return false;
+        }
+        if (namespace == null) {
+            if (other.namespace != null) {
+                return false;
+            }
+        } else if (!namespace.equals(other.namespace)) {
+            return false;
+        }
+        if (revision == null) {
+            if (other.revision != null) {
+                return false;
+            }
+        } else if (!revision.equals(other.revision)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        if (namespace != null) {
+            sb.append("(" + namespace);
+
+            if (revision != null) {
+                sb.append("?revision=" + revisionFormat.format(revision));
+            }
+            sb.append(")");
+        }
+        sb.append(localName);
+        return sb.toString();
+    }
+
+    /**
+     * Returns a namespace in form defined by section 5.6.4. of {@link https
+     * ://tools.ietf.org/html/rfc6020}, if namespace is not correctly defined,
+     * the method will return <code>null</code> <br>
+     * example "http://example.acme.com/system?revision=2008-04-01"
+     * 
+     * @return namespace in form defined by section 5.6.4. of {@link https
+     *         ://tools.ietf.org/html/rfc6020}, if namespace is not correctly
+     *         defined, the method will return <code>null</code>
+     * 
+     */
+    URI getRevisionNamespace() {
+
+        if (namespace == null) {
+            return null;
+        }
+
+        String query = "";
+        if (revision != null) {
+            query = "revision=" + revisionFormat.format(revision);
+        }
+
+        URI compositeURI = null;
+        try {
+            compositeURI = new URI(namespace.getScheme(), namespace.getUserInfo(), namespace.getHost(),
+                    namespace.getPort(), namespace.getPath(), query, namespace.getFragment());
+        } catch (URISyntaxException e) {
+            LOGGER.error("", e);
+        }
+        return compositeURI;
+    }
+}
index 8b6ef47beb037f9862457423e882a31ffd9c697b..775fa8eb76e5769a13060bc9ed47f45db0c260a5 100644 (file)
@@ -1,32 +1,28 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.common;\r
-\r
-//import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;\r
-\r
-public interface RpcError {\r
-    ErrorSeverity getSeverity();\r
-\r
-    String getTag();\r
-\r
-    String getApplicationTag();\r
-\r
-    String getMessage();\r
-\r
-    String getInfo();\r
-\r
-    // RevisionAwareXPath getPath();\r
-\r
-    public enum ErrorSeverity {\r
-        ERROR, WARNING,\r
-    }\r
-\r
-    public enum ErrorType {\r
-        TRANSPORT, RPC, PROTOCOL, APPLICATION\r
-    }\r
-}\r
+/*
+ * 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.common;
+
+public interface RpcError {
+    ErrorSeverity getSeverity();
+
+    String getTag();
+
+    String getApplicationTag();
+
+    String getMessage();
+
+    String getInfo();
+
+    public enum ErrorSeverity {
+        ERROR, WARNING,
+    }
+
+    public enum ErrorType {
+        TRANSPORT, RPC, PROTOCOL, APPLICATION
+    }
+}
index f9f5a030aaa8237d7b93bc4b21b0d0d4d0b9de19..105981ac2a6d2bf071761221fbf7e880e93c035b 100755 (executable)
@@ -1,28 +1,28 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.data.api;\r
-\r
-import java.util.List;\r
-\r
-\r
-/**\r
- * @author michal.rehak\r
- *\r
- */\r
-public interface MutableCompositeNode extends MutableNode<List<Node<?>>>, CompositeNode {\r
-    \r
-    /**\r
-     * update internal map\r
-     */\r
-    public void init();\r
-    \r
-    /**\r
-     * @return original node, if available\r
-     */\r
-    CompositeNode getOriginal();\r
-}\r
+/*
+ * 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.data.api;
+
+import java.util.List;
+
+
+/**
+ * @author michal.rehak
+ *
+ */
+public interface MutableCompositeNode extends MutableNode<List<Node<?>>>, CompositeNode {
+    
+    /**
+     * update internal map
+     */
+    void init();
+    
+    /**
+     * @return original node, if available
+     */
+    CompositeNode getOriginal();
+}
index 13ad7a953c6187e761492a2e059842901903dfe7..1d349b82ad1c67d267803f2f628edbc220c2edff 100755 (executable)
@@ -1,39 +1,38 @@
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.data.api;\r
-\r
-\r
-/**\r
- * @author michal.rehak\r
- *\r
- */\r
-public interface NodeModificationBuilder {\r
-\r
-    public abstract Node<?> getMutableEquivalent(Node<?> originalNode);\r
-\r
-    public abstract CompositeNode buildDiffTree();\r
-\r
-    public abstract void mergeNode(MutableCompositeNode alteredNode);\r
-\r
-    public abstract void removeNode(MutableCompositeNode deadNode);\r
-\r
-    public abstract void removeNode(MutableSimpleNode<?> deadNode);\r
-\r
-    public abstract void deleteNode(MutableSimpleNode<?> deadNode);\r
-\r
-    public abstract void deleteNode(MutableCompositeNode deadNode);\r
-\r
-    public abstract void replaceNode(MutableCompositeNode replacementNode);\r
-\r
-    public abstract void replaceNode(MutableSimpleNode<?> replacementNode);\r
-\r
-    public abstract void addNode(MutableCompositeNode newNode);\r
-\r
-    public abstract void addNode(MutableSimpleNode<?> newNode);\r
-\r
-}\r
+/*
+ * 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.data.api;
+
+/**
+ * @author michal.rehak
+ * 
+ */
+public interface NodeModificationBuilder {
+
+    abstract Node<?> getMutableEquivalent(Node<?> originalNode);
+
+    abstract CompositeNode buildDiffTree();
+
+    abstract void mergeNode(MutableCompositeNode alteredNode);
+
+    abstract void removeNode(MutableCompositeNode deadNode);
+
+    abstract void removeNode(MutableSimpleNode<?> deadNode);
+
+    abstract void deleteNode(MutableSimpleNode<?> deadNode);
+
+    abstract void deleteNode(MutableCompositeNode deadNode);
+
+    abstract void replaceNode(MutableCompositeNode replacementNode);
+
+    abstract void replaceNode(MutableSimpleNode<?> replacementNode);
+
+    abstract void addNode(MutableCompositeNode newNode);
+
+    abstract void addNode(MutableSimpleNode<?> newNode);
+
+}
index 1fdf28e12a79800cfe8d79ea1da428957a6abac7..5ba7ed8b3c2853c3fc2f4786a8faa2ea7e58c25f 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.data.impl;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;\r
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;\r
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;\r
-import org.opendaylight.yangtools.yang.data.api.Node;\r
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;\r
-\r
-/**\r
- * @author michal.rehak\r
- *\r
- */\r
-public class CompositeNodeTOImpl extends AbstractNodeTO<List<Node<?>>>\r
-        implements CompositeNode {\r
-\r
-    private Map<QName, List<Node<?>>> nodeMap;\r
-\r
-    /**\r
-     * @param qname\r
-     * @param parent use null to create top composite node (without parent)\r
-     * @param value\r
-     */\r
-    public CompositeNodeTOImpl(QName qname, CompositeNode parent,\r
-            List<Node<?>> value) {\r
-        super(qname, parent, value);\r
-        if (value != null) {\r
-            nodeMap = NodeUtils.buildNodeMap(getValue());\r
-        }\r
-        init();\r
-    }\r
-\r
-    /**\r
-     * @param qname\r
-     * @param parent use null to create top composite node (without parent)\r
-     * @param value\r
-     * @param modifyAction\r
-     */\r
-    public CompositeNodeTOImpl(QName qname, CompositeNode parent,\r
-            List<Node<?>> value, ModifyAction modifyAction) {\r
-        super(qname, parent, value, modifyAction);\r
-        init();\r
-    }\r
-\r
-\r
-    /**\r
-     * @return the nodeMap\r
-     */\r
-    protected Map<QName, List<Node<?>>> getNodeMap() {\r
-        return nodeMap;\r
-    }\r
-\r
-    @Override\r
-    public List<Node<?>> getChildren() {\r
-        return getValue();\r
-    }\r
-\r
-    @Override\r
-    public SimpleNode<?> getFirstSimpleByName(QName leafQName) {\r
-        List<SimpleNode<?>> list = getSimpleNodesByName(leafQName);\r
-        if (list.isEmpty())\r
-            return null;\r
-        return list.get(0);\r
-    }\r
-\r
-    @Override\r
-    public List<CompositeNode> getCompositesByName(QName children) {\r
-        List<Node<?>> toFilter = getNodeMap().get(children);\r
-        List<CompositeNode> list = new ArrayList<CompositeNode>();\r
-        for (Node<?> node : toFilter) {\r
-            if (node instanceof CompositeNode)\r
-                list.add((CompositeNode) node);\r
-        }\r
-        return list;\r
-    }\r
-\r
-    @Override\r
-    public List<SimpleNode<?>> getSimpleNodesByName(QName children) {\r
-        List<Node<?>> toFilter = getNodeMap().get(children);\r
-        List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();\r
-\r
-        for (Node<?> node : toFilter) {\r
-            if (node instanceof SimpleNode<?>)\r
-                list.add((SimpleNode<?>) node);\r
-        }\r
-        return list;\r
-    }\r
-\r
-    @Override\r
-    public CompositeNode getFirstCompositeByName(QName container) {\r
-        List<CompositeNode> list = getCompositesByName(container);\r
-        if (list.isEmpty()) {\r
-            return null;\r
-        }\r
-        return list.get(0);\r
-    }\r
-\r
-    /**\r
-     * @param leaf\r
-     * @return TODO:: do we need this method?\r
-     */\r
-    public SimpleNode<?> getFirstLeafByName(QName leaf) {\r
-        List<SimpleNode<?>> list = getSimpleNodesByName(leaf);\r
-        if (list.isEmpty()) {\r
-            return null;\r
-        }\r
-        return list.get(0);\r
-    }\r
-\r
-    @Override\r
-    public List<CompositeNode> getCompositesByName(String children) {\r
-        return getCompositesByName(new QName(getNodeType(), children));\r
-    }\r
-\r
-    @Override\r
-    public List<SimpleNode<?>> getSimpleNodesByName(String children) {\r
-        return getSimpleNodesByName(new QName(getNodeType(), children));\r
-    }\r
-\r
-    /**\r
-     * @param value\r
-     */\r
-    protected void init() {\r
-        if (getValue() != null) {\r
-            nodeMap = NodeUtils.buildNodeMap(getValue());\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public MutableCompositeNode asMutable() {\r
-        throw new IllegalAccessError("cast to mutable is not supported - "+getClass().getSimpleName());\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return super.toString() + ", children.size = "\r
-                + (getChildren() != null ? getChildren().size() : "n/a");\r
-    }\r
-\r
-\r
-\r
-}\r
+/*
+ * 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.data.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+
+/**
+ * @author michal.rehak
+ * 
+ */
+public class CompositeNodeTOImpl extends AbstractNodeTO<List<Node<?>>> implements CompositeNode {
+
+    private Map<QName, List<Node<?>>> nodeMap;
+
+    /**
+     * @param qname
+     * @param parent
+     *            use null to create top composite node (without parent)
+     * @param value
+     */
+    public CompositeNodeTOImpl(QName qname, CompositeNode parent, List<Node<?>> value) {
+        super(qname, parent, value);
+        if (value != null) {
+            nodeMap = NodeUtils.buildNodeMap(getValue());
+        }
+        init();
+    }
+
+    /**
+     * @param qname
+     * @param parent
+     *            use null to create top composite node (without parent)
+     * @param value
+     * @param modifyAction
+     */
+    public CompositeNodeTOImpl(QName qname, CompositeNode parent, List<Node<?>> value, ModifyAction modifyAction) {
+        super(qname, parent, value, modifyAction);
+        init();
+    }
+
+    /**
+     * @return the nodeMap
+     */
+    protected Map<QName, List<Node<?>>> getNodeMap() {
+        return nodeMap;
+    }
+
+    @Override
+    public List<Node<?>> getChildren() {
+        return getValue();
+    }
+
+    @Override
+    public SimpleNode<?> getFirstSimpleByName(QName leafQName) {
+        List<SimpleNode<?>> list = getSimpleNodesByName(leafQName);
+        if (list.isEmpty()) {
+            return null;
+        }
+        return list.get(0);
+    }
+
+    @Override
+    public List<CompositeNode> getCompositesByName(QName children) {
+        List<Node<?>> toFilter = getNodeMap().get(children);
+        List<CompositeNode> list = new ArrayList<CompositeNode>();
+        for (Node<?> node : toFilter) {
+            if (node instanceof CompositeNode) {
+                list.add((CompositeNode) node);
+            }
+        }
+        return list;
+    }
+
+    @Override
+    public List<SimpleNode<?>> getSimpleNodesByName(QName children) {
+        List<Node<?>> toFilter = getNodeMap().get(children);
+        List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
+
+        for (Node<?> node : toFilter) {
+            if (node instanceof SimpleNode<?>)
+                list.add((SimpleNode<?>) node);
+        }
+        return list;
+    }
+
+    @Override
+    public CompositeNode getFirstCompositeByName(QName container) {
+        List<CompositeNode> list = getCompositesByName(container);
+        if (list.isEmpty()) {
+            return null;
+        }
+        return list.get(0);
+    }
+
+    /**
+     * @param leaf
+     * @return TODO:: do we need this method?
+     */
+    public SimpleNode<?> getFirstLeafByName(QName leaf) {
+        List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
+        if (list.isEmpty()) {
+            return null;
+        }
+        return list.get(0);
+    }
+
+    @Override
+    public List<CompositeNode> getCompositesByName(String children) {
+        return getCompositesByName(new QName(getNodeType(), children));
+    }
+
+    @Override
+    public List<SimpleNode<?>> getSimpleNodesByName(String children) {
+        return getSimpleNodesByName(new QName(getNodeType(), children));
+    }
+
+    /**
+     * @param value
+     */
+    protected void init() {
+        if (getValue() != null) {
+            nodeMap = NodeUtils.buildNodeMap(getValue());
+        }
+    }
+
+    @Override
+    public MutableCompositeNode asMutable() {
+        throw new IllegalAccessError("cast to mutable is not supported - " + getClass().getSimpleName());
+    }
+
+    @Override
+    public String toString() {
+        return super.toString() + ", children.size = " + (getChildren() != null ? getChildren().size() : "n/a");
+    }
+
+}
index 7b3649a504ec7a597906f9f214823374f3455977..d7650e530915c9da3c83015056b999182fe3f769 100644 (file)
@@ -17,13 +17,13 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 
-public abstract class AbstractContainerNode extends AbstractNode<List<Node<?>>>
-        implements CompositeNode {
+public abstract class AbstractContainerNode extends AbstractNode<List<Node<?>>> implements CompositeNode {
 
     public SimpleNode<?> getFirstSimpleByName(QName leaf) {
         List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
-        if (list.size() == 0)
+        if (list.size() == 0) {
             return null;
+        }
         return list.get(0);
     }
 
@@ -41,8 +41,9 @@ public abstract class AbstractContainerNode extends AbstractNode<List<Node<?>>>
 
     public List<Node<?>> getValue() {
         Map<QName, List<Node<?>>> map = getNodeMap();
-        if (map == null)
+        if (map == null) {
             throw new IllegalStateException("nodeMap should not be null");
+        }
         List<Node<?>> ret = new ArrayList<Node<?>>();
         Collection<List<Node<?>>> values = map.values();
         for (List<Node<?>> list : values) {
@@ -55,42 +56,48 @@ public abstract class AbstractContainerNode extends AbstractNode<List<Node<?>>>
 
     public List<CompositeNode> getCompositesByName(QName children) {
         Map<QName, List<Node<?>>> map = getNodeMap();
-        if (map == null)
+        if (map == null) {
             throw new IllegalStateException("nodeMap should not be null");
+        }
         List<Node<?>> toFilter = map.get(children);
         List<CompositeNode> list = new ArrayList<CompositeNode>();
         for (Node<?> node : toFilter) {
-            if (node instanceof CompositeNode)
+            if (node instanceof CompositeNode) {
                 list.add((CompositeNode) node);
+            }
         }
         return list;
     }
 
     public List<SimpleNode<?>> getSimpleNodesByName(QName children) {
         Map<QName, List<Node<?>>> map = getNodeMap();
-        if (map == null)
+        if (map == null) {
             throw new IllegalStateException("nodeMap should not be null");
+        }
         List<Node<?>> toFilter = map.get(children);
         List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
 
         for (Node<?> node : toFilter) {
-            if (node instanceof SimpleNode<?>)
+            if (node instanceof SimpleNode<?>) {
                 list.add((SimpleNode<?>) node);
+            }
         }
         return list;
     }
 
     public CompositeNode getFirstCompositeByName(QName container) {
         List<CompositeNode> list = getCompositesByName(container);
-        if (list.size() == 0)
+        if (list.size() == 0) {
             return null;
+        }
         return list.get(0);
     }
 
     public SimpleNode<?> getFirstLeafByName(QName leaf) {
         List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
-        if (list.size() == 0)
+        if (list.size() == 0) {
             return null;
+        }
         return list.get(0);
     }
 
index 6626e1ba0fb01385b67fe849495d1036d44bfeb8..ec029163348b73874d890a1a1f3602672423fbe4 100644 (file)
@@ -19,7 +19,7 @@ import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 
-public class Nodes {
+public final class Nodes {
 
     private Nodes() {
     }
@@ -32,13 +32,11 @@ public class Nodes {
         return containerNode(name, children, null);
     }
 
-    public static CompositeNode containerNode(QName name,
-            List<Node<?>> children, CompositeNode parent) {
+    public static CompositeNode containerNode(QName name, List<Node<?>> children, CompositeNode parent) {
         return new ContainerNodeTO(name, parent, nodeMapFromList(children));
     }
 
-    public static Map<QName, List<Node<?>>> nodeMapFromList(
-            List<Node<?>> children) {
+    public static Map<QName, List<Node<?>>> nodeMapFromList(List<Node<?>> children) {
         Map<QName, List<Node<?>>> map = new HashMap<QName, List<Node<?>>>();
         for (Node<?> node : children) {
 
@@ -62,8 +60,7 @@ public class Nodes {
             this.nodeMap = nodeMap;
         }
 
-        public ContainerNodeTO(QName name, CompositeNode parent,
-                Map<QName, List<Node<?>>> nodeMap) {
+        public ContainerNodeTO(QName name, CompositeNode parent, Map<QName, List<Node<?>>> nodeMap) {
             super(name, parent);
             this.nodeMap = nodeMap;
         }
@@ -74,8 +71,11 @@ public class Nodes {
             return nodeMap;
         }
 
-        /* (non-Javadoc)
-         * @see org.opendaylight.yangtools.yang.data.api.CompositeNode#asMutable()
+        /*
+         * (non-Javadoc)
+         * 
+         * @see
+         * org.opendaylight.yangtools.yang.data.api.CompositeNode#asMutable()
          */
         @Override
         public MutableCompositeNode asMutable() {
@@ -85,8 +85,7 @@ public class Nodes {
 
     }
 
-    private static class SimpleNodeTO<T> extends AbstractNode<T> implements
-            SimpleNode<T> {
+    private static class SimpleNodeTO<T> extends AbstractNode<T> implements SimpleNode<T> {
 
         private final T value;
 
@@ -101,7 +100,9 @@ public class Nodes {
             return value;
         }
 
-        /* (non-Javadoc)
+        /*
+         * (non-Javadoc)
+         * 
          * @see org.opendaylight.yangtools.yang.data.api.SimpleNode#asMutable()
          */
         @Override
index 9f534ad192daf18b61e3e63c91bae7c48a841e44..05ff7dbf8e1b6695797c6d7724986e8bc34f3b0b 100644 (file)
@@ -18,35 +18,35 @@ public interface Builder {
 
     /**
      * Get name of module in which this node is declared.
-     *
+     * 
      * @return module name
      */
     String getModuleName();
 
     /**
      * Set name of module in which this node is declared.
-     *
+     * 
      * @param moduleName
      */
     void setModuleName(String moduleName);
 
     /**
      * Get current line in yang file.
-     *
+     * 
      * @return current line in yang file
      */
     int getLine();
 
     /**
      * Get parent node of this node.
-     *
+     * 
      * @return parent node builder or null if this is top level node
      */
     Builder getParent();
 
     /**
      * Set parent of this node.
-     *
+     * 
      * @param parent
      *            parent node builder
      */
@@ -54,31 +54,30 @@ public interface Builder {
 
     /**
      * Add unknown node to this builder.
-     *
+     * 
      * @param unknownNode
      */
     void addUnknownNodeBuilder(UnknownSchemaNodeBuilder unknownNode);
 
     /**
      * Get builders of unknown nodes defined in this node.
-     *
+     * 
      * @return collection of UnknownSchemaNodeBuilder objects
      */
     List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders();
 
     /**
      * Build YANG data model node.
-     *
+     * 
      * This method should create an instance of YANG data model node. After
      * creating an instance, this instance should be returned for each call
      * without repeating build process.
-     *
+     * 
      * @return YANG data model node
      */
     Object build();
 
-    
-    public interface Rebuildable<T extends Builder> {
+    interface Rebuildable<T extends Builder> {
         T toBuilder();
     }
 }
index 8dd0d15035aec5208619aa5872a6ded202f6adb8..ceae0f73a404508028ebcd3847bf5a851c70f0ce 100644 (file)
@@ -54,7 +54,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
     private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
     private boolean resolved;
 
-    private final static SchemaPath path = new SchemaPath(Collections.<QName> emptyList(), true);
+    private static final SchemaPath PATH = new SchemaPath(Collections.<QName> emptyList(), true);
 
     public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr) {
         super(moduleName, line, null);
@@ -91,7 +91,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
 
     @Override
     public SchemaPath getPath() {
-        return path;
+        return PATH;
     }
 
     @Override
index 05095fe93680b6031f735ec5461e4c9dbf8628ad..f4202343fa757916a5850bc4ad30f24d6e07c762 100644 (file)
@@ -394,10 +394,8 @@ public final class ChoiceBuilder extends AbstractSchemaNodeBuilder implements Da
                 throw new IllegalArgumentException("Choice Case QName cannot be NULL!");
             }
             for (final ChoiceCaseNode caseNode : cases) {
-                if (caseNode != null) {
-                    if (name.equals(caseNode.getQName())) {
-                        return caseNode;
-                    }
+                if (caseNode != null && name.equals(caseNode.getQName())) {
+                    return caseNode;
                 }
             }
             return null;
@@ -409,10 +407,9 @@ public final class ChoiceBuilder extends AbstractSchemaNodeBuilder implements Da
                 throw new IllegalArgumentException("Choice Case string Name cannot be NULL!");
             }
             for (final ChoiceCaseNode caseNode : cases) {
-                if (caseNode != null && (caseNode.getQName() != null)) {
-                    if (name.equals(caseNode.getQName().getLocalName())) {
-                        return caseNode;
-                    }
+                if (caseNode != null && (caseNode.getQName() != null)
+                        && name.equals(caseNode.getQName().getLocalName())) {
+                    return caseNode;
                 }
             }
             return null;
index 6d5c9513c3d86f4c50a67c5a55a440f8b2c5fe9c..b1084e1659e6eb87ab14b9710b05295f09747ead 100644 (file)
@@ -20,6 +20,9 @@ import org.opendaylight.yangtools.yang.parser.builder.api.AbstractBuilder;
 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 
 public final class ConstraintsBuilder extends AbstractBuilder {
+    private static final int HASH_IF_BOOL_TRUE = 1231;
+    private static final int HASH_IF_BOOL_FALSE = 1237;
+
     private final ConstraintDefinitionImpl instance;
     private final Set<MustDefinition> mustDefinitions;
     private String whenCondition;
@@ -175,7 +178,7 @@ public final class ConstraintsBuilder extends AbstractBuilder {
             result = prime * result + ((mustConstraints == null) ? 0 : mustConstraints.hashCode());
             result = prime * result + ((minElements == null) ? 0 : minElements.hashCode());
             result = prime * result + ((maxElements == null) ? 0 : maxElements.hashCode());
-            result = prime * result + (mandatory ? 1231 : 1237);
+            result = prime * result + (mandatory ? HASH_IF_BOOL_TRUE : HASH_IF_BOOL_FALSE);
             return result;
         }
 
index 0030b91d0b8590f3499eb32102afe47f5ca149c4..bdc10b3054d39f6a8de85d426a0827c1bff35b7d 100644 (file)
@@ -206,8 +206,10 @@ public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder imple
 
     @Override
     public String toString() {
-        final StringBuilder result = new StringBuilder(IdentityrefTypeBuilder.class.getSimpleName() + "[");
-        result.append(", base=" + baseQName);
+        final StringBuilder result = new StringBuilder(IdentityrefTypeBuilder.class.getSimpleName());
+        result.append("[");
+        result.append(", base=");
+        result.append(baseQName);
         result.append("]");
         return result.toString();
     }
index cab518c329f035567f33cf77681e8b3431b0dad4..655b99a64a075db67189f23f05bb3337633a5490 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.parser.builder.impl;\r
-\r
-import java.net.URI;\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.Date;\r
-import java.util.HashSet;\r
-import java.util.LinkedHashSet;\r
-import java.util.LinkedList;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.TreeMap;\r
-import java.util.TreeSet;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;\r
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.Deviation;\r
-import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.Module;\r
-import org.opendaylight.yangtools.yang.model.api.ModuleImport;\r
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.UsesNode;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.AbstractDataNodeContainerBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.Builder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;\r
-import org.opendaylight.yangtools.yang.parser.util.Comparators;\r
-import org.opendaylight.yangtools.yang.parser.util.RefineHolder;\r
-import org.opendaylight.yangtools.yang.parser.util.YangParseException;\r
-\r
-/**\r
- * Builder of Module object. If this module is dependent on external\r
- * module/modules, these dependencies must be resolved before module is built,\r
- * otherwise result may not be valid.\r
- */\r
-public class ModuleBuilder extends AbstractDataNodeContainerBuilder {\r
-    private final ModuleImpl instance;\r
-    private final String name;\r
-    private final SchemaPath schemaPath;\r
-    private URI namespace;\r
-    private String prefix;\r
-    private Date revision;\r
-\r
-    private final LinkedList<Builder> actualPath = new LinkedList<Builder>();\r
-    private final Set<TypeAwareBuilder> dirtyNodes = new HashSet<TypeAwareBuilder>();\r
-\r
-    private final Set<ModuleImport> imports = new HashSet<ModuleImport>();\r
-    private final List<AugmentationSchemaBuilder> addedAugments = new ArrayList<AugmentationSchemaBuilder>();\r
-    private final List<AugmentationSchemaBuilder> allAugments = new ArrayList<AugmentationSchemaBuilder>();\r
-    private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();\r
-    private final List<UsesNodeBuilder> allUsesNodes = new ArrayList<UsesNodeBuilder>();\r
-    private final Set<RpcDefinitionBuilder> addedRpcs = new HashSet<RpcDefinitionBuilder>();\r
-    private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();\r
-    private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();\r
-    private final Set<FeatureBuilder> addedFeatures = new HashSet<FeatureBuilder>();\r
-    private final Set<DeviationBuilder> addedDeviations = new HashSet<DeviationBuilder>();\r
-    private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();\r
-    private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();\r
-    private final List<UnknownSchemaNodeBuilder> allUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();\r
-\r
-    public ModuleBuilder(final String name) {\r
-        super(name, 0, null);\r
-        this.name = name;\r
-        schemaPath = new SchemaPath(Collections.<QName>emptyList(), true);\r
-        instance = new ModuleImpl(name);\r
-        actualPath.push(this);\r
-    }\r
-\r
-    /**\r
-     * Build new Module object based on this builder.\r
-     */\r
-    @Override\r
-    public Module build() {\r
-        instance.setPrefix(prefix);\r
-        instance.setRevision(revision);\r
-        instance.setImports(imports);\r
-        instance.setNamespace(namespace);\r
-\r
-        // TYPEDEFS\r
-        final Set<TypeDefinition<?>> typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);\r
-        for (TypeDefinitionBuilder tdb : addedTypedefs) {\r
-            typedefs.add(tdb.build());\r
-        }\r
-        instance.setTypeDefinitions(typedefs);\r
-\r
-        // CHILD NODES\r
-        final Map<QName, DataSchemaNode> children = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);\r
-        for (DataSchemaNodeBuilder child : addedChildNodes) {\r
-            children.put(child.getQName(), child.build());\r
-        }\r
-        instance.setChildNodes(children);\r
-\r
-        // GROUPINGS\r
-        final Set<GroupingDefinition> groupings = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);\r
-        for (GroupingBuilder gb : addedGroupings) {\r
-            groupings.add(gb.build());\r
-        }\r
-        instance.setGroupings(groupings);\r
-\r
-        // USES\r
-        final Set<UsesNode> usesDefinitions = new HashSet<UsesNode>();\r
-        for (UsesNodeBuilder unb : addedUsesNodes) {\r
-            usesDefinitions.add(unb.build());\r
-        }\r
-        instance.setUses(usesDefinitions);\r
-\r
-        // FEATURES\r
-        final Set<FeatureDefinition> features = new TreeSet<FeatureDefinition>(Comparators.SCHEMA_NODE_COMP);\r
-        for (FeatureBuilder fb : addedFeatures) {\r
-            features.add(fb.build());\r
-        }\r
-        instance.setFeatures(features);\r
-\r
-        // NOTIFICATIONS\r
-        final Set<NotificationDefinition> notifications = new TreeSet<NotificationDefinition>(\r
-                Comparators.SCHEMA_NODE_COMP);\r
-        for (NotificationBuilder entry : addedNotifications) {\r
-            notifications.add(entry.build());\r
-        }\r
-        instance.setNotifications(notifications);\r
-\r
-        // AUGMENTATIONS\r
-        final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();\r
-        for (AugmentationSchemaBuilder builder : addedAugments) {\r
-            augmentations.add(builder.build());\r
-        }\r
-        instance.setAugmentations(augmentations);\r
-\r
-        // RPCs\r
-        final Set<RpcDefinition> rpcs = new TreeSet<RpcDefinition>(Comparators.SCHEMA_NODE_COMP);\r
-        for (RpcDefinitionBuilder rpc : addedRpcs) {\r
-            rpcs.add(rpc.build());\r
-        }\r
-        instance.setRpcs(rpcs);\r
-\r
-        // DEVIATIONS\r
-        final Set<Deviation> deviations = new HashSet<Deviation>();\r
-        for (DeviationBuilder entry : addedDeviations) {\r
-            deviations.add(entry.build());\r
-        }\r
-        instance.setDeviations(deviations);\r
-\r
-        // EXTENSIONS\r
-        final List<ExtensionDefinition> extensions = new ArrayList<ExtensionDefinition>();\r
-        for (ExtensionBuilder eb : addedExtensions) {\r
-            extensions.add(eb.build());\r
-        }\r
-        Collections.sort(extensions, Comparators.SCHEMA_NODE_COMP);\r
-        instance.setExtensionSchemaNodes(extensions);\r
-\r
-        // IDENTITIES\r
-        final Set<IdentitySchemaNode> identities = new TreeSet<IdentitySchemaNode>(Comparators.SCHEMA_NODE_COMP);\r
-        for (IdentitySchemaNodeBuilder id : addedIdentities) {\r
-            identities.add(id.build());\r
-        }\r
-        instance.setIdentities(identities);\r
-\r
-        // UNKNOWN NODES\r
-        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();\r
-        for (UnknownSchemaNodeBuilder unb : addedUnknownNodes) {\r
-            unknownNodes.add(unb.build());\r
-        }\r
-        instance.setUnknownSchemaNodes(unknownNodes);\r
-\r
-        return instance;\r
-    }\r
-\r
-    public boolean isAllUsesDataCollected() {\r
-        for(UsesNodeBuilder usesNode : allUsesNodes) {\r
-            if(!usesNode.isDataCollected()) {\r
-                return false;\r
-            }\r
-        }\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public void setParent(Builder parent) {\r
-        throw new YangParseException(name, 0, "Can not set parent to module");\r
-    }\r
-\r
-    @Override\r
-    public SchemaPath getPath() {\r
-        return schemaPath;\r
-    }\r
-\r
-    @Override\r
-    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {\r
-        return addedTypedefs;\r
-    }\r
-\r
-    public void enterNode(final Builder node) {\r
-        actualPath.push(node);\r
-    }\r
-\r
-    public void exitNode() {\r
-        actualPath.pop();\r
-    }\r
-\r
-    public Builder getActualNode() {\r
-        if (actualPath.isEmpty()) {\r
-            return null;\r
-        } else {\r
-            return actualPath.get(0);\r
-        }\r
-    }\r
-\r
-    public Builder getActualParent() {\r
-        if (actualPath.size() < 2) {\r
-            return null;\r
-        } else {\r
-            return actualPath.get(1);\r
-        }\r
-    }\r
-\r
-    public Set<TypeAwareBuilder> getDirtyNodes() {\r
-        return dirtyNodes;\r
-    }\r
-\r
-    public List<AugmentationSchemaBuilder> getAllAugments() {\r
-        return allAugments;\r
-    }\r
-\r
-    public Set<IdentitySchemaNodeBuilder> getIdentities() {\r
-        return addedIdentities;\r
-    }\r
-\r
-    public List<UsesNodeBuilder> getAllUsesNodes() {\r
-        return allUsesNodes;\r
-    }\r
-\r
-    public Set<DeviationBuilder> getDeviations() {\r
-        return addedDeviations;\r
-    }\r
-\r
-    public List<ExtensionBuilder> getExtensions() {\r
-        return addedExtensions;\r
-    }\r
-\r
-    public List<UnknownSchemaNodeBuilder> getAllUnknownNodes() {\r
-        return allUnknownNodes;\r
-    }\r
-\r
-    public String getName() {\r
-        return name;\r
-    }\r
-\r
-    public URI getNamespace() {\r
-        return namespace;\r
-    }\r
-\r
-    public void setNamespace(final URI namespace) {\r
-        this.namespace = namespace;\r
-    }\r
-\r
-    public String getPrefix() {\r
-        return prefix;\r
-    }\r
-\r
-    public Date getRevision() {\r
-        return revision;\r
-    }\r
-\r
-    public void markActualNodeDirty() {\r
-        final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) getActualNode();\r
-        dirtyNodes.add(nodeBuilder);\r
-    }\r
-\r
-    public void setRevision(final Date revision) {\r
-        this.revision = revision;\r
-    }\r
-\r
-    public void setPrefix(final String prefix) {\r
-        this.prefix = prefix;\r
-    }\r
-\r
-    public void setYangVersion(final String yangVersion) {\r
-        instance.setYangVersion(yangVersion);\r
-    }\r
-\r
-    public void setDescription(final String description) {\r
-        instance.setDescription(description);\r
-    }\r
-\r
-    public void setReference(final String reference) {\r
-        instance.setReference(reference);\r
-    }\r
-\r
-    public void setOrganization(final String organization) {\r
-        instance.setOrganization(organization);\r
-    }\r
-\r
-    public void setContact(final String contact) {\r
-        instance.setContact(contact);\r
-    }\r
-\r
-    public boolean addModuleImport(final String moduleName, final Date revision, final String prefix) {\r
-        final ModuleImport moduleImport = createModuleImport(moduleName, revision, prefix);\r
-        return imports.add(moduleImport);\r
-    }\r
-\r
-    public Set<ModuleImport> getModuleImports() {\r
-        return imports;\r
-    }\r
-\r
-    public ExtensionBuilder addExtension(final QName qname, final int line) {\r
-        final String extName = qname.getLocalName();\r
-        for (ExtensionBuilder addedExtension : addedExtensions) {\r
-            if (addedExtension.getQName().getLocalName().equals(extName)) {\r
-                throw new YangParseException(moduleName, line, "Can not add extension '" + extName\r
-                        + "': extension with same name already declared at line " + addedExtension.getLine());\r
-            }\r
-        }\r
-        final ExtensionBuilder builder = new ExtensionBuilder(name, line, qname);\r
-        addedExtensions.add(builder);\r
-        return builder;\r
-    }\r
-\r
-    public ContainerSchemaNodeBuilder addContainerNode(final int line, final QName qname, final SchemaPath schemaPath) {\r
-        final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);\r
-\r
-        Builder parent = getActualNode();\r
-        builder.setParent(parent);\r
-        addChildToParent(parent, builder, qname.getLocalName());\r
-\r
-        return builder;\r
-    }\r
-\r
-    public ListSchemaNodeBuilder addListNode(final int line, final QName qname, final SchemaPath schemaPath) {\r
-        final ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(name, line, qname, schemaPath);\r
-\r
-        Builder parent = getActualNode();\r
-        builder.setParent(parent);\r
-        addChildToParent(parent, builder, qname.getLocalName());\r
-\r
-        return builder;\r
-    }\r
-\r
-    public LeafSchemaNodeBuilder addLeafNode(final int line, final QName qname, final SchemaPath schemaPath) {\r
-        final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(name, line, qname, schemaPath);\r
-\r
-        Builder parent = getActualNode();\r
-        builder.setParent(parent);\r
-        addChildToParent(parent, builder, qname.getLocalName());\r
-\r
-        return builder;\r
-    }\r
-\r
-    public LeafListSchemaNodeBuilder addLeafListNode(final int line, final QName qname, final SchemaPath schemaPath) {\r
-        final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(name, line, qname, schemaPath);\r
-\r
-        Builder parent = getActualNode();\r
-        builder.setParent(parent);\r
-        addChildToParent(parent, builder, qname.getLocalName());\r
-\r
-        return builder;\r
-    }\r
-\r
-    public GroupingBuilder addGrouping(final int line, final QName qname) {\r
-        final GroupingBuilder builder = new GroupingBuilderImpl(name, line, qname);\r
-\r
-        Builder parent = getActualNode();\r
-        builder.setParent(parent);\r
-\r
-        String groupingName = qname.getLocalName();\r
-        if (parent.equals(this)) {\r
-            for (GroupingBuilder addedGrouping : addedGroupings) {\r
-                if (addedGrouping.getQName().getLocalName().equals(groupingName)) {\r
-                    throw new YangParseException(name, line, "grouping with same name '" + groupingName\r
-                            + "' already declared at line " + addedGrouping.getLine());\r
-                }\r
-            }\r
-            addedGroupings.add(builder);\r
-        } else {\r
-            if (parent instanceof DataNodeContainerBuilder) {\r
-                DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;\r
-                for (GroupingBuilder addedGrouping : parentNode.getGroupingBuilders()) {\r
-                    if (addedGrouping.getQName().getLocalName().equals(groupingName)) {\r
-                        throw new YangParseException(name, line, "grouping with same name '" + groupingName\r
-                                + "' already declared at line " + addedGrouping.getLine());\r
-                    }\r
-                }\r
-                parentNode.addGrouping(builder);\r
-            } else if (parent instanceof RpcDefinitionBuilder) {\r
-                RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parent;\r
-                for (GroupingBuilder child : parentNode.getGroupings()) {\r
-                    if (child.getQName().getLocalName().equals(groupingName)) {\r
-                        throw new YangParseException(name, line, "grouping with same name '" + groupingName\r
-                                + "' already declared at line " + child.getLine());\r
-                    }\r
-                }\r
-                parentNode.addGrouping(builder);\r
-            } else {\r
-                throw new YangParseException(name, line, "Unresolved parent of grouping " + groupingName);\r
-            }\r
-        }\r
-\r
-        return builder;\r
-    }\r
-\r
-    public AugmentationSchemaBuilder addAugment(final int line, final String augmentTargetStr) {\r
-        final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr);\r
-\r
-        Builder parent = getActualNode();\r
-        builder.setParent(parent);\r
-\r
-        if (parent.equals(this)) {\r
-            // augment can be declared only under 'module' ...\r
-            addedAugments.add(builder);\r
-        } else {\r
-            // ... or 'uses' statement\r
-            if (parent instanceof UsesNodeBuilder) {\r
-                ((UsesNodeBuilder) parent).addAugment(builder);\r
-            } else {\r
-                throw new YangParseException(name, line, "Augment can be declared only under module or uses statement.");\r
-            }\r
-        }\r
-        allAugments.add(builder);\r
-\r
-        return builder;\r
-    }\r
-\r
-    @Override\r
-    public Set<UsesNodeBuilder> getUsesNodes() {\r
-        return addedUsesNodes;\r
-    }\r
-\r
-    @Override\r
-    public void addUsesNode(UsesNodeBuilder usesBuilder) {\r
-        addedUsesNodes.add(usesBuilder);\r
-        allUsesNodes.add(usesBuilder);\r
-    }\r
-\r
-    public UsesNodeBuilder addUsesNode(final int line, final String groupingPathStr) {\r
-        final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(name, line, groupingPathStr);\r
-\r
-        Builder parent = getActualNode();\r
-        usesBuilder.setParent(parent);\r
-\r
-        if (parent.equals(this)) {\r
-            addedUsesNodes.add(usesBuilder);\r
-        } else {\r
-            if (!(parent instanceof DataNodeContainerBuilder)) {\r
-                throw new YangParseException(name, line, "Unresolved parent of uses '" + groupingPathStr + "'.");\r
-            }\r
-            ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);\r
-        }\r
-        allUsesNodes.add(usesBuilder);\r
-        return usesBuilder;\r
-    }\r
-\r
-    public void addRefine(final RefineHolder refine) {\r
-        final Builder parent = getActualNode();\r
-        if (!(parent instanceof UsesNodeBuilder)) {\r
-            throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement");\r
-        }\r
-        ((UsesNodeBuilder) parent).addRefine(refine);\r
-        refine.setParent(parent);\r
-    }\r
-\r
-    public RpcDefinitionBuilder addRpc(final int line, final QName qname) {\r
-        Builder parent = getActualNode();\r
-        if (!(parent.equals(this))) {\r
-            throw new YangParseException(name, line, "rpc can be defined only in module or submodule");\r
-        }\r
-\r
-        final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(name, line, qname);\r
-        rpcBuilder.setParent(parent);\r
-\r
-        String rpcName = qname.getLocalName();\r
-        for (RpcDefinitionBuilder rpc : addedRpcs) {\r
-            if (rpc.getQName().getLocalName().equals(rpcName)) {\r
-                throw new YangParseException(name, line, "rpc with same name '" + rpcName\r
-                        + "' already declared at line " + rpc.getLine());\r
-            }\r
-        }\r
-        for (DataSchemaNodeBuilder addedChild : addedChildNodes) {\r
-            if (addedChild.getQName().getLocalName().equals(rpcName)) {\r
-                throw new YangParseException(name, line, "Can not add rpc: node with same name '" + rpcName\r
-                        + "' already declared at line " + addedChild.getLine());\r
-            }\r
-        }\r
-        for (NotificationBuilder addedNotification : addedNotifications) {\r
-            if (addedNotification.getQName().getLocalName().equals(rpcName)) {\r
-                throw new YangParseException(name, line, "Can not add rpc: notification with same name '" + rpcName\r
-                        + "' already declared at line " + addedNotification.getLine());\r
-            }\r
-        }\r
-        addedRpcs.add(rpcBuilder);\r
-        return rpcBuilder;\r
-    }\r
-\r
-    public ContainerSchemaNodeBuilder addRpcInput(final int line, final QName qname, final SchemaPath schemaPath) {\r
-        final Builder parent = getActualNode();\r
-        if (!(parent instanceof RpcDefinitionBuilder)) {\r
-            throw new YangParseException(name, line, "input can be defined only in rpc statement");\r
-        }\r
-        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;\r
-\r
-        final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);\r
-        inputBuilder.setParent(rpc);\r
-\r
-        rpc.setInput(inputBuilder);\r
-        return inputBuilder;\r
-    }\r
-\r
-    public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName qname, final int line) {\r
-        final Builder parent = getActualNode();\r
-        if (!(parent instanceof RpcDefinitionBuilder)) {\r
-            throw new YangParseException(name, line, "output can be defined only in rpc statement");\r
-        }\r
-        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;\r
-\r
-        final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);\r
-        outputBuilder.setParent(rpc);\r
-\r
-        rpc.setOutput(outputBuilder);\r
-        return outputBuilder;\r
-    }\r
-\r
-    public NotificationBuilder addNotification(final int line, final QName qname) {\r
-        final Builder parent = getActualNode();\r
-        if (!(parent.equals(this))) {\r
-            throw new YangParseException(name, line, "notification can be defined only in module or submodule");\r
-        }\r
-\r
-        String notificationName = qname.getLocalName();\r
-        for (NotificationBuilder nb : addedNotifications) {\r
-            if (nb.getQName().equals(qname)) {\r
-                throw new YangParseException(name, line, "notification with same name '" + notificationName\r
-                        + "' already declared at line " + nb.getLine());\r
-            }\r
-        }\r
-        for (RpcDefinitionBuilder rpc : addedRpcs) {\r
-            if (rpc.getQName().getLocalName().equals(notificationName)) {\r
-                throw new YangParseException(name, line, "Can not add notification: rpc with same name '"\r
-                        + notificationName + "' already declared at line " + rpc.getLine());\r
-            }\r
-        }\r
-        for (DataSchemaNodeBuilder addedChild : addedChildNodes) {\r
-            if (addedChild.getQName().getLocalName().equals(notificationName)) {\r
-                throw new YangParseException(name, line, "Can not add notification: node with same name '"\r
-                        + notificationName + "' already declared at line " + addedChild.getLine());\r
-            }\r
-        }\r
-\r
-        final NotificationBuilder builder = new NotificationBuilder(name, line, qname);\r
-        builder.setParent(parent);\r
-        addedNotifications.add(builder);\r
-\r
-        return builder;\r
-    }\r
-\r
-    public FeatureBuilder addFeature(final int line, final QName qname) {\r
-        Builder parent = getActualNode();\r
-        if (!(parent.equals(this))) {\r
-            throw new YangParseException(name, line, "feature can be defined only in module or submodule");\r
-        }\r
-\r
-        final FeatureBuilder builder = new FeatureBuilder(name, line, qname);\r
-        builder.setParent(parent);\r
-\r
-        String featureName = qname.getLocalName();\r
-        for (FeatureBuilder addedFeature : addedFeatures) {\r
-            if (addedFeature.getQName().getLocalName().equals(featureName)) {\r
-                throw new YangParseException(name, line, "feature with same name '" + featureName\r
-                        + "' already declared at line " + addedFeature.getLine());\r
-            }\r
-        }\r
-        addedFeatures.add(builder);\r
-        return builder;\r
-    }\r
-\r
-    public ChoiceBuilder addChoice(final int line, final QName qname) {\r
-        final ChoiceBuilder builder = new ChoiceBuilder(name, line, qname);\r
-\r
-        Builder parent = getActualNode();\r
-        builder.setParent(parent);\r
-        addChildToParent(parent, builder, qname.getLocalName());\r
-\r
-        return builder;\r
-    }\r
-\r
-    public ChoiceCaseBuilder addCase(final int line, final QName qname) {\r
-        Builder parent = getActualNode();\r
-        if (parent == null || parent.equals(this)) {\r
-            throw new YangParseException(name, line, "'case' parent not found");\r
-        }\r
-\r
-        final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(name, line, qname);\r
-        builder.setParent(parent);\r
-\r
-        if (parent instanceof ChoiceBuilder) {\r
-            ((ChoiceBuilder) parent).addCase(builder);\r
-        } else if (parent instanceof AugmentationSchemaBuilder) {\r
-            ((AugmentationSchemaBuilder) parent).addChildNode(builder);\r
-        } else {\r
-            throw new YangParseException(name, line, "Unresolved parent of 'case' " + qname.getLocalName());\r
-        }\r
-\r
-        return builder;\r
-    }\r
-\r
-    public AnyXmlBuilder addAnyXml(final int line, final QName qname, final SchemaPath schemaPath) {\r
-        final AnyXmlBuilder builder = new AnyXmlBuilder(name, line, qname, schemaPath);\r
-\r
-        Builder parent = getActualNode();\r
-        builder.setParent(parent);\r
-        addChildToParent(parent, builder, qname.getLocalName());\r
-\r
-        return builder;\r
-    }\r
-\r
-    @Override\r
-    public void addTypedef(TypeDefinitionBuilder typedefBuilder) {\r
-        String nodeName = typedefBuilder.getQName().getLocalName();\r
-        for (TypeDefinitionBuilder tdb : addedTypedefs) {\r
-            if (tdb.getQName().getLocalName().equals(nodeName)) {\r
-                throw new YangParseException(name, typedefBuilder.getLine(), "typedef with same name '" + nodeName\r
-                        + "' already declared at line " + tdb.getLine());\r
-            }\r
-        }\r
-        addedTypedefs.add(typedefBuilder);\r
-    }\r
-\r
-    public TypeDefinitionBuilderImpl addTypedef(final int line, final QName qname) {\r
-        final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(name, line, qname);\r
-\r
-        Builder parent = getActualNode();\r
-        builder.setParent(parent);\r
-\r
-        String typedefName = qname.getLocalName();\r
-        if (parent.equals(this)) {\r
-            for (TypeDefinitionBuilder tdb : addedTypedefs) {\r
-                if (tdb.getQName().getLocalName().equals(typedefName)) {\r
-                    throw new YangParseException(name, line, "typedef with same name '" + typedefName\r
-                            + "' already declared at line " + tdb.getLine());\r
-                }\r
-            }\r
-            addedTypedefs.add(builder);\r
-        } else {\r
-            if (parent instanceof DataNodeContainerBuilder) {\r
-                DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;\r
-                for (TypeDefinitionBuilder child : parentNode.getTypeDefinitionBuilders()) {\r
-                    if (child.getQName().getLocalName().equals(typedefName)) {\r
-                        throw new YangParseException(name, line, "typedef with same name '" + typedefName\r
-                                + "' already declared at line " + child.getLine());\r
-                    }\r
-                }\r
-                parentNode.addTypedef(builder);\r
-            } else if (parent instanceof RpcDefinitionBuilder) {\r
-                RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parent;\r
-                for (TypeDefinitionBuilder tdb : rpcParent.getTypeDefinitions()) {\r
-                    if (tdb.getQName().getLocalName().equals(builder.getQName().getLocalName())) {\r
-                        throw new YangParseException(name, line, "typedef with same name '" + typedefName\r
-                                + "' already declared at line " + tdb.getLine());\r
-                    }\r
-                }\r
-                rpcParent.addTypedef(builder);\r
-            } else {\r
-                throw new YangParseException(name, line, "Unresolved parent of typedef " + typedefName);\r
-            }\r
-        }\r
-\r
-        return builder;\r
-    }\r
-\r
-    public void setType(final TypeDefinition<?> type) {\r
-        Builder parent = getActualNode();\r
-        if (parent == null || !(parent instanceof TypeAwareBuilder)) {\r
-            throw new YangParseException("Failed to set type '" + type.getQName().getLocalName()\r
-                    + "'. Invalid parent node: " + parent);\r
-        }\r
-        ((TypeAwareBuilder) parent).setType(type);\r
-    }\r
-\r
-    public UnionTypeBuilder addUnionType(final int line, final URI namespace, final Date revision) {\r
-        final Builder parent = getActualNode();\r
-        if (parent == null) {\r
-            throw new YangParseException(name, line, "Unresolved parent of union type");\r
-        } else {\r
-            final UnionTypeBuilder union = new UnionTypeBuilder(name, line);\r
-            if (parent instanceof TypeAwareBuilder) {\r
-                ((TypeAwareBuilder) parent).setTypedef(union);\r
-                return union;\r
-            } else {\r
-                throw new YangParseException(name, line, "Invalid parent of union type.");\r
-            }\r
-        }\r
-    }\r
-\r
-    public void addIdentityrefType(final int line, final SchemaPath schemaPath, final String baseString) {\r
-        final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(name, line, baseString, schemaPath);\r
-\r
-        final Builder parent = getActualNode();\r
-        if (parent == null) {\r
-            throw new YangParseException(name, line, "Unresolved parent of identityref type.");\r
-        } else {\r
-            if (parent instanceof TypeAwareBuilder) {\r
-                final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent;\r
-                typeParent.setTypedef(identityref);\r
-                dirtyNodes.add(typeParent);\r
-            } else {\r
-                throw new YangParseException(name, line, "Invalid parent of identityref type.");\r
-            }\r
-        }\r
-    }\r
-\r
-    public DeviationBuilder addDeviation(final int line, final String targetPath) {\r
-        Builder parent = getActualNode();\r
-        if (!(parent.equals(this))) {\r
-            throw new YangParseException(name, line, "deviation can be defined only in module or submodule");\r
-        }\r
-\r
-        final DeviationBuilder builder = new DeviationBuilder(name, line, targetPath);\r
-        builder.setParent(parent);\r
-        addedDeviations.add(builder);\r
-        return builder;\r
-    }\r
-\r
-    public IdentitySchemaNodeBuilder addIdentity(final QName qname, final int line) {\r
-        Builder parent = getActualNode();\r
-        if (!(parent.equals(this))) {\r
-            throw new YangParseException(name, line, "identity can be defined only in module or submodule");\r
-        }\r
-        String identityName = qname.getLocalName();\r
-        for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) {\r
-            if (idBuilder.getQName().equals(qname)) {\r
-                throw new YangParseException(name, line, "identity with same name '" + identityName\r
-                        + "' already declared at line " + idBuilder.getLine());\r
-            }\r
-        }\r
-\r
-        final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(name, line, qname);\r
-        builder.setParent(parent);\r
-        addedIdentities.add(builder);\r
-        return builder;\r
-    }\r
-\r
-    @Override\r
-    public void addUnknownNodeBuilder(final UnknownSchemaNodeBuilder builder) {\r
-        addedUnknownNodes.add(builder);\r
-        allUnknownNodes.add(builder);\r
-    }\r
-\r
-    public UnknownSchemaNodeBuilder addUnknownSchemaNode(final int line, final QName qname) {\r
-        final Builder parent = getActualNode();\r
-        final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(name, line, qname);\r
-        builder.setParent(parent);\r
-        allUnknownNodes.add(builder);\r
-\r
-        if (parent.equals(this)) {\r
-            addedUnknownNodes.add(builder);\r
-        } else {\r
-            if (parent instanceof SchemaNodeBuilder) {\r
-                ((SchemaNodeBuilder) parent).addUnknownNodeBuilder(builder);\r
-            } else if (parent instanceof DataNodeContainerBuilder) {\r
-                ((DataNodeContainerBuilder) parent).addUnknownNodeBuilder(builder);\r
-            } else if (parent instanceof RefineHolder) {\r
-                ((RefineHolder) parent).addUnknownNodeBuilder(builder);\r
-            } else {\r
-                throw new YangParseException(name, line, "Unresolved parent of unknown node '" + qname.getLocalName()\r
-                        + "'");\r
-            }\r
-        }\r
-\r
-        return builder;\r
-    }\r
-    \r
-    public Set<RpcDefinitionBuilder> getRpcs() {\r
-        return addedRpcs;\r
-    }\r
-\r
-    public Set<NotificationBuilder> getNotifications() {\r
-        return addedNotifications;\r
-    }\r
-    \r
-    @Override\r
-    public String toString() {\r
-        return "module " + name;\r
-    }\r
-\r
-    private final class ModuleImpl implements Module {\r
-        private URI namespace;\r
-        private final String name;\r
-        private Date revision;\r
-        private String prefix;\r
-        private String yangVersion;\r
-        private String description;\r
-        private String reference;\r
-        private String organization;\r
-        private String contact;\r
-        private Set<ModuleImport> imports = Collections.emptySet();\r
-        private Set<FeatureDefinition> features = Collections.emptySet();\r
-        private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();\r
-        private Set<NotificationDefinition> notifications = Collections.emptySet();\r
-        private Set<AugmentationSchema> augmentations = Collections.emptySet();\r
-        private Set<RpcDefinition> rpcs = Collections.emptySet();\r
-        private Set<Deviation> deviations = Collections.emptySet();\r
-        private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();\r
-        private Set<GroupingDefinition> groupings = Collections.emptySet();\r
-        private Set<UsesNode> uses = Collections.emptySet();\r
-        private List<ExtensionDefinition> extensionNodes = Collections.emptyList();\r
-        private Set<IdentitySchemaNode> identities = Collections.emptySet();\r
-        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();\r
-\r
-        private ModuleImpl(String name) {\r
-            this.name = name;\r
-        }\r
-\r
-        @Override\r
-        public URI getNamespace() {\r
-            return namespace;\r
-        }\r
-\r
-        private void setNamespace(URI namespace) {\r
-            this.namespace = namespace;\r
-        }\r
-\r
-        @Override\r
-        public String getName() {\r
-            return name;\r
-        }\r
-\r
-        @Override\r
-        public Date getRevision() {\r
-            return revision;\r
-        }\r
-\r
-        private void setRevision(Date revision) {\r
-            this.revision = revision;\r
-        }\r
-\r
-        @Override\r
-        public String getPrefix() {\r
-            return prefix;\r
-        }\r
-\r
-        private void setPrefix(String prefix) {\r
-            this.prefix = prefix;\r
-        }\r
-\r
-        @Override\r
-        public String getYangVersion() {\r
-            return yangVersion;\r
-        }\r
-\r
-        private void setYangVersion(String yangVersion) {\r
-            this.yangVersion = yangVersion;\r
-        }\r
-\r
-        @Override\r
-        public String getDescription() {\r
-            return description;\r
-        }\r
-\r
-        private void setDescription(String description) {\r
-            this.description = description;\r
-        }\r
-\r
-        @Override\r
-        public String getReference() {\r
-            return reference;\r
-        }\r
-\r
-        private void setReference(String reference) {\r
-            this.reference = reference;\r
-        }\r
-\r
-        @Override\r
-        public String getOrganization() {\r
-            return organization;\r
-        }\r
-\r
-        private void setOrganization(String organization) {\r
-            this.organization = organization;\r
-        }\r
-\r
-        @Override\r
-        public String getContact() {\r
-            return contact;\r
-        }\r
-\r
-        private void setContact(String contact) {\r
-            this.contact = contact;\r
-        }\r
-\r
-        @Override\r
-        public Set<ModuleImport> getImports() {\r
-            return imports;\r
-        }\r
-\r
-        private void setImports(Set<ModuleImport> imports) {\r
-            if (imports != null) {\r
-                this.imports = imports;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<FeatureDefinition> getFeatures() {\r
-            return features;\r
-        }\r
-\r
-        private void setFeatures(Set<FeatureDefinition> features) {\r
-            if (features != null) {\r
-                this.features = features;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<TypeDefinition<?>> getTypeDefinitions() {\r
-            return typeDefinitions;\r
-        }\r
-\r
-        private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {\r
-            if (typeDefinitions != null) {\r
-                this.typeDefinitions = typeDefinitions;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<NotificationDefinition> getNotifications() {\r
-            return notifications;\r
-        }\r
-\r
-        private void setNotifications(Set<NotificationDefinition> notifications) {\r
-            if (notifications != null) {\r
-                this.notifications = notifications;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<AugmentationSchema> getAugmentations() {\r
-            return augmentations;\r
-        }\r
-\r
-        private void setAugmentations(Set<AugmentationSchema> augmentations) {\r
-            if (augmentations != null) {\r
-                this.augmentations = augmentations;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<RpcDefinition> getRpcs() {\r
-            return rpcs;\r
-        }\r
-\r
-        private void setRpcs(Set<RpcDefinition> rpcs) {\r
-            if (rpcs != null) {\r
-                this.rpcs = rpcs;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<Deviation> getDeviations() {\r
-            return deviations;\r
-        }\r
-\r
-        private void setDeviations(Set<Deviation> deviations) {\r
-            if (deviations != null) {\r
-                this.deviations = deviations;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<DataSchemaNode> getChildNodes() {\r
-            return new LinkedHashSet<DataSchemaNode>(childNodes.values());\r
-        }\r
-\r
-        private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {\r
-            if (childNodes != null) {\r
-                this.childNodes = childNodes;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<GroupingDefinition> getGroupings() {\r
-            return groupings;\r
-        }\r
-\r
-        private void setGroupings(Set<GroupingDefinition> groupings) {\r
-            if (groupings != null) {\r
-                this.groupings = groupings;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<UsesNode> getUses() {\r
-            return uses;\r
-        }\r
-\r
-        private void setUses(Set<UsesNode> uses) {\r
-            if (uses != null) {\r
-                this.uses = uses;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public List<ExtensionDefinition> getExtensionSchemaNodes() {\r
-            return extensionNodes;\r
-        }\r
-\r
-        private void setExtensionSchemaNodes(final List<ExtensionDefinition> extensionNodes) {\r
-            if (extensionNodes != null) {\r
-                this.extensionNodes = extensionNodes;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public Set<IdentitySchemaNode> getIdentities() {\r
-            return identities;\r
-        }\r
-\r
-        private void setIdentities(final Set<IdentitySchemaNode> identities) {\r
-            if (identities != null) {\r
-                this.identities = identities;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
-            return unknownNodes;\r
-        }\r
-\r
-        private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {\r
-            if (unknownNodes != null) {\r
-                this.unknownNodes = unknownNodes;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public DataSchemaNode getDataChildByName(QName name) {\r
-            return childNodes.get(name);\r
-        }\r
-\r
-        @Override\r
-        public DataSchemaNode getDataChildByName(String name) {\r
-            DataSchemaNode result = null;\r
-            for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {\r
-                if (entry.getKey().getLocalName().equals(name)) {\r
-                    result = entry.getValue();\r
-                    break;\r
-                }\r
-            }\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            final int prime = 31;\r
-            int result = 1;\r
-            result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());\r
-            result = prime * result + ((name == null) ? 0 : name.hashCode());\r
-            result = prime * result + ((revision == null) ? 0 : revision.hashCode());\r
-            result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());\r
-            result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj) {\r
-                return true;\r
-            }\r
-            if (obj == null) {\r
-                return false;\r
-            }\r
-            if (getClass() != obj.getClass()) {\r
-                return false;\r
-            }\r
-            ModuleImpl other = (ModuleImpl) obj;\r
-            if (namespace == null) {\r
-                if (other.namespace != null) {\r
-                    return false;\r
-                }\r
-            } else if (!namespace.equals(other.namespace)) {\r
-                return false;\r
-            }\r
-            if (name == null) {\r
-                if (other.name != null) {\r
-                    return false;\r
-                }\r
-            } else if (!name.equals(other.name)) {\r
-                return false;\r
-            }\r
-            if (revision == null) {\r
-                if (other.revision != null) {\r
-                    return false;\r
-                }\r
-            } else if (!revision.equals(other.revision)) {\r
-                return false;\r
-            }\r
-            if (prefix == null) {\r
-                if (other.prefix != null) {\r
-                    return false;\r
-                }\r
-            } else if (!prefix.equals(other.prefix)) {\r
-                return false;\r
-            }\r
-            if (yangVersion == null) {\r
-                if (other.yangVersion != null) {\r
-                    return false;\r
-                }\r
-            } else if (!yangVersion.equals(other.yangVersion)) {\r
-                return false;\r
-            }\r
-            return true;\r
-        }\r
-\r
-        @Override\r
-        public String toString() {\r
-            StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());\r
-            sb.append("[");\r
-            sb.append("name=" + name);\r
-            sb.append(", namespace=" + namespace);\r
-            sb.append(", revision=" + revision);\r
-            sb.append(", prefix=" + prefix);\r
-            sb.append(", yangVersion=" + yangVersion);\r
-            sb.append("]");\r
-            return sb.toString();\r
-        }\r
-    }\r
-\r
-    /**\r
-     * Add child to parent. Method checks for duplicates and add given child\r
-     * node to parent. If node with same name is found, throws exception. If\r
-     * parent is null, child node will be added directly to module.\r
-     *\r
-     * @param parent\r
-     * @param child\r
-     * @param childName\r
-     */\r
-    private void addChildToParent(final Builder parent, final DataSchemaNodeBuilder child, final String childName) {\r
-        final int line = child.getLine();\r
-        if (parent.equals(this)) {\r
-            // if parent == null => node is defined under module\r
-            // All leafs, leaf-lists, lists, containers, choices, rpcs,\r
-            // notifications, and anyxmls defined within a parent node or at the\r
-            // top level of the module or its submodules share the same\r
-            // identifier namespace.\r
-            for (DataSchemaNodeBuilder childNode : addedChildNodes) {\r
-                if (childNode.getQName().getLocalName().equals(childName)) {\r
-                    throw new YangParseException(name, line, "Can not add '" + child\r
-                            + "': node with same name already declared at line " + childNode.getLine());\r
-                }\r
-            }\r
-            for (RpcDefinitionBuilder rpc : addedRpcs) {\r
-                if (rpc.getQName().getLocalName().equals(childName)) {\r
-                    throw new YangParseException(name, line, "Can not add '" + child\r
-                            + "': rpc with same name already declared at line " + rpc.getLine());\r
-                }\r
-            }\r
-            for (NotificationBuilder notification : addedNotifications) {\r
-                if (notification.getQName().getLocalName().equals(childName)) {\r
-                    throw new YangParseException(name, line, "Can not add '" + child\r
-                            + "': notification with same name already declared at line " + notification.getLine());\r
-                }\r
-            }\r
-            addedChildNodes.add(child);\r
-        } else {\r
-            if(parent instanceof AugmentationSchemaBuilder) {\r
-                child.setAugmenting(true);\r
-            }\r
-            // no need for checking rpc and notification because they can be\r
-            // defined only under module or submodule\r
-            if (parent instanceof DataNodeContainerBuilder) {\r
-                DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;\r
-                for (DataSchemaNodeBuilder childNode : parentNode.getChildNodeBuilders()) {\r
-                    if (childNode.getQName().getLocalName().equals(childName)) {\r
-                        throw new YangParseException(name, line, "Can not add '" + child + "': node with same name '"\r
-                                + childName + "' already declared at line " + childNode.getLine());\r
-                    }\r
-                }\r
-                parentNode.addChildNode(child);\r
-            } else if (parent instanceof ChoiceBuilder) {\r
-                ChoiceBuilder parentNode = (ChoiceBuilder) parent;\r
-                for (ChoiceCaseBuilder caseBuilder : parentNode.getCases()) {\r
-                    if (caseBuilder.getQName().getLocalName().equals(childName)) {\r
-                        throw new YangParseException(name, line, "Can not add '" + child + "': case with same name '"\r
-                                + childName + "' already declared at line " + caseBuilder.getLine());\r
-                    }\r
-                }\r
-                parentNode.addCase(child);\r
-            } else {\r
-                throw new YangParseException(name, line, "Unresolved parent of node '" + childName + "'.");\r
-            }\r
-        }\r
-    }\r
-\r
-    private ModuleImport createModuleImport(final String moduleName, final Date revision, final String prefix) {\r
-        final ModuleImport moduleImport = new ModuleImport() {\r
-            @Override\r
-            public String getModuleName() {\r
-                return moduleName;\r
-            }\r
-\r
-            @Override\r
-            public Date getRevision() {\r
-                return revision;\r
-            }\r
-\r
-            @Override\r
-            public String getPrefix() {\r
-                return prefix;\r
-            }\r
-\r
-            @Override\r
-            public int hashCode() {\r
-                final int prime = 31;\r
-                int result = 1;\r
-                result = prime * result + ((moduleName == null) ? 0 : moduleName.hashCode());\r
-                result = prime * result + ((revision == null) ? 0 : revision.hashCode());\r
-                result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());\r
-                return result;\r
-            }\r
-\r
-            @Override\r
-            public boolean equals(Object obj) {\r
-                if (this == obj) {\r
-                    return true;\r
-                }\r
-                if (obj == null) {\r
-                    return false;\r
-                }\r
-                if (getClass() != obj.getClass()) {\r
-                    return false;\r
-                }\r
-                ModuleImport other = (ModuleImport) obj;\r
-                if (getModuleName() == null) {\r
-                    if (other.getModuleName() != null) {\r
-                        return false;\r
-                    }\r
-                } else if (!getModuleName().equals(other.getModuleName())) {\r
-                    return false;\r
-                }\r
-                if (getRevision() == null) {\r
-                    if (other.getRevision() != null) {\r
-                        return false;\r
-                    }\r
-                } else if (!getRevision().equals(other.getRevision())) {\r
-                    return false;\r
-                }\r
-                if (getPrefix() == null) {\r
-                    if (other.getPrefix() != null) {\r
-                        return false;\r
-                    }\r
-                } else if (!getPrefix().equals(other.getPrefix())) {\r
-                    return false;\r
-                }\r
-                return true;\r
-            }\r
-\r
-            @Override\r
-            public String toString() {\r
-                return "ModuleImport[moduleName=" + moduleName + ", revision=" + revision + ", prefix=" + prefix + "]";\r
-            }\r
-        };\r
-        return moduleImport;\r
-    }\r
-\r
-}\r
+/*
+ * 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.builder.impl;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.util.Comparators;
+import org.opendaylight.yangtools.yang.parser.util.RefineHolder;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Builder of Module object. If this module is dependent on external
+ * module/modules, these dependencies must be resolved before module is built,
+ * otherwise result may not be valid.
+ */
+public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
+
+    private final ModuleImpl instance;
+    private final String name;
+    private final SchemaPath schemaPath;
+    private URI namespace;
+    private String prefix;
+    private Date revision;
+
+    private final Deque<Builder> actualPath = new LinkedList<Builder>();
+    private final Set<TypeAwareBuilder> dirtyNodes = new HashSet<TypeAwareBuilder>();
+
+    private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
+    private final List<AugmentationSchemaBuilder> addedAugments = new ArrayList<AugmentationSchemaBuilder>();
+    private final List<AugmentationSchemaBuilder> allAugments = new ArrayList<AugmentationSchemaBuilder>();
+    private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+    private final List<UsesNodeBuilder> allUsesNodes = new ArrayList<UsesNodeBuilder>();
+    private final Set<RpcDefinitionBuilder> addedRpcs = new HashSet<RpcDefinitionBuilder>();
+    private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
+    private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();
+    private final Set<FeatureBuilder> addedFeatures = new HashSet<FeatureBuilder>();
+    private final Set<DeviationBuilder> addedDeviations = new HashSet<DeviationBuilder>();
+    private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
+    private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
+    private final List<UnknownSchemaNodeBuilder> allUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+
+    public ModuleBuilder(final String name) {
+        super(name, 0, null);
+        this.name = name;
+        schemaPath = new SchemaPath(Collections.<QName> emptyList(), true);
+        instance = new ModuleImpl(name);
+        actualPath.push(this);
+    }
+
+    /**
+     * Build new Module object based on this builder.
+     */
+    @Override
+    public Module build() {
+        instance.setPrefix(prefix);
+        instance.setRevision(revision);
+        instance.setImports(imports);
+        instance.setNamespace(namespace);
+
+        // TYPEDEFS
+        final Set<TypeDefinition<?>> typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);
+        for (TypeDefinitionBuilder tdb : addedTypedefs) {
+            typedefs.add(tdb.build());
+        }
+        instance.setTypeDefinitions(typedefs);
+
+        // CHILD NODES
+        final Map<QName, DataSchemaNode> children = new TreeMap<QName, DataSchemaNode>(Comparators.QNAME_COMP);
+        for (DataSchemaNodeBuilder child : addedChildNodes) {
+            children.put(child.getQName(), child.build());
+        }
+        instance.setChildNodes(children);
+
+        // GROUPINGS
+        final Set<GroupingDefinition> groupings = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);
+        for (GroupingBuilder gb : addedGroupings) {
+            groupings.add(gb.build());
+        }
+        instance.setGroupings(groupings);
+
+        // USES
+        final Set<UsesNode> usesDefinitions = new HashSet<UsesNode>();
+        for (UsesNodeBuilder unb : addedUsesNodes) {
+            usesDefinitions.add(unb.build());
+        }
+        instance.setUses(usesDefinitions);
+
+        // FEATURES
+        final Set<FeatureDefinition> features = new TreeSet<FeatureDefinition>(Comparators.SCHEMA_NODE_COMP);
+        for (FeatureBuilder fb : addedFeatures) {
+            features.add(fb.build());
+        }
+        instance.setFeatures(features);
+
+        // NOTIFICATIONS
+        final Set<NotificationDefinition> notifications = new TreeSet<NotificationDefinition>(
+                Comparators.SCHEMA_NODE_COMP);
+        for (NotificationBuilder entry : addedNotifications) {
+            notifications.add(entry.build());
+        }
+        instance.setNotifications(notifications);
+
+        // AUGMENTATIONS
+        final Set<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
+        for (AugmentationSchemaBuilder builder : addedAugments) {
+            augmentations.add(builder.build());
+        }
+        instance.setAugmentations(augmentations);
+
+        // RPCs
+        final Set<RpcDefinition> rpcs = new TreeSet<RpcDefinition>(Comparators.SCHEMA_NODE_COMP);
+        for (RpcDefinitionBuilder rpc : addedRpcs) {
+            rpcs.add(rpc.build());
+        }
+        instance.setRpcs(rpcs);
+
+        // DEVIATIONS
+        final Set<Deviation> deviations = new HashSet<Deviation>();
+        for (DeviationBuilder entry : addedDeviations) {
+            deviations.add(entry.build());
+        }
+        instance.setDeviations(deviations);
+
+        // EXTENSIONS
+        final List<ExtensionDefinition> extensions = new ArrayList<ExtensionDefinition>();
+        for (ExtensionBuilder eb : addedExtensions) {
+            extensions.add(eb.build());
+        }
+        Collections.sort(extensions, Comparators.SCHEMA_NODE_COMP);
+        instance.setExtensionSchemaNodes(extensions);
+
+        // IDENTITIES
+        final Set<IdentitySchemaNode> identities = new TreeSet<IdentitySchemaNode>(Comparators.SCHEMA_NODE_COMP);
+        for (IdentitySchemaNodeBuilder id : addedIdentities) {
+            identities.add(id.build());
+        }
+        instance.setIdentities(identities);
+
+        // UNKNOWN NODES
+        final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+        for (UnknownSchemaNodeBuilder unb : addedUnknownNodes) {
+            unknownNodes.add(unb.build());
+        }
+        instance.setUnknownSchemaNodes(unknownNodes);
+
+        return instance;
+    }
+
+    public boolean isAllUsesDataCollected() {
+        for (UsesNodeBuilder usesNode : allUsesNodes) {
+            if (!usesNode.isDataCollected()) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public void setParent(Builder parent) {
+        throw new YangParseException(name, 0, "Can not set parent to module");
+    }
+
+    @Override
+    public SchemaPath getPath() {
+        return schemaPath;
+    }
+
+    @Override
+    public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
+        return addedTypedefs;
+    }
+
+    public void enterNode(final Builder node) {
+        actualPath.push(node);
+    }
+
+    public void exitNode() {
+        actualPath.pop();
+    }
+
+    public Builder getActualNode() {
+        if (actualPath.isEmpty()) {
+            return null;
+        } else {
+            return actualPath.peekFirst();
+        }
+    }
+
+    public Builder getActualParent() {
+        if (actualPath.size() < 2) {
+            return null;
+        } else {
+            Builder builderChild = actualPath.removeFirst();
+            Builder builderParent = actualPath.peekFirst();
+            actualPath.addFirst(builderChild);
+            return builderParent;
+        }
+    }
+
+    public Set<TypeAwareBuilder> getDirtyNodes() {
+        return dirtyNodes;
+    }
+
+    public List<AugmentationSchemaBuilder> getAllAugments() {
+        return allAugments;
+    }
+
+    public Set<IdentitySchemaNodeBuilder> getIdentities() {
+        return addedIdentities;
+    }
+
+    public List<UsesNodeBuilder> getAllUsesNodes() {
+        return allUsesNodes;
+    }
+
+    public Set<DeviationBuilder> getDeviations() {
+        return addedDeviations;
+    }
+
+    public List<ExtensionBuilder> getExtensions() {
+        return addedExtensions;
+    }
+
+    public List<UnknownSchemaNodeBuilder> getAllUnknownNodes() {
+        return allUnknownNodes;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public URI getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(final URI namespace) {
+        this.namespace = namespace;
+    }
+
+    public String getPrefix() {
+        return prefix;
+    }
+
+    public Date getRevision() {
+        return revision;
+    }
+
+    public void markActualNodeDirty() {
+        final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) getActualNode();
+        dirtyNodes.add(nodeBuilder);
+    }
+
+    public void setRevision(final Date revision) {
+        this.revision = revision;
+    }
+
+    public void setPrefix(final String prefix) {
+        this.prefix = prefix;
+    }
+
+    public void setYangVersion(final String yangVersion) {
+        instance.setYangVersion(yangVersion);
+    }
+
+    public void setDescription(final String description) {
+        instance.setDescription(description);
+    }
+
+    public void setReference(final String reference) {
+        instance.setReference(reference);
+    }
+
+    public void setOrganization(final String organization) {
+        instance.setOrganization(organization);
+    }
+
+    public void setContact(final String contact) {
+        instance.setContact(contact);
+    }
+
+    public boolean addModuleImport(final String moduleName, final Date revision, final String prefix) {
+        final ModuleImport moduleImport = createModuleImport(moduleName, revision, prefix);
+        return imports.add(moduleImport);
+    }
+
+    public Set<ModuleImport> getModuleImports() {
+        return imports;
+    }
+
+    public ExtensionBuilder addExtension(final QName qname, final int line) {
+        final String extName = qname.getLocalName();
+        for (ExtensionBuilder addedExtension : addedExtensions) {
+            if (addedExtension.getQName().getLocalName().equals(extName)) {
+                raiseYangParserException("extension", "node", extName, line, addedExtension.getLine());
+            }
+        }
+        final ExtensionBuilder builder = new ExtensionBuilder(name, line, qname);
+        addedExtensions.add(builder);
+        return builder;
+    }
+
+    public ContainerSchemaNodeBuilder addContainerNode(final int line, final QName qname, final SchemaPath schemaPath) {
+        final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
+
+        Builder parent = getActualNode();
+        builder.setParent(parent);
+        addChildToParent(parent, builder, qname.getLocalName());
+
+        return builder;
+    }
+
+    public ListSchemaNodeBuilder addListNode(final int line, final QName qname, final SchemaPath schemaPath) {
+        final ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(name, line, qname, schemaPath);
+
+        Builder parent = getActualNode();
+        builder.setParent(parent);
+        addChildToParent(parent, builder, qname.getLocalName());
+
+        return builder;
+    }
+
+    public LeafSchemaNodeBuilder addLeafNode(final int line, final QName qname, final SchemaPath schemaPath) {
+        final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(name, line, qname, schemaPath);
+
+        Builder parent = getActualNode();
+        builder.setParent(parent);
+        addChildToParent(parent, builder, qname.getLocalName());
+
+        return builder;
+    }
+
+    public LeafListSchemaNodeBuilder addLeafListNode(final int line, final QName qname, final SchemaPath schemaPath) {
+        final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(name, line, qname, schemaPath);
+
+        Builder parent = getActualNode();
+        builder.setParent(parent);
+        addChildToParent(parent, builder, qname.getLocalName());
+
+        return builder;
+    }
+
+    public GroupingBuilder addGrouping(final int line, final QName qname) {
+        final GroupingBuilder builder = new GroupingBuilderImpl(name, line, qname);
+
+        Builder parent = getActualNode();
+        builder.setParent(parent);
+
+        String groupingName = qname.getLocalName();
+        if (parent.equals(this)) {
+            for (GroupingBuilder addedGrouping : addedGroupings) {
+                if (addedGrouping.getQName().getLocalName().equals(groupingName)) {
+                    raiseYangParserException("", "Grouping", groupingName, line, addedGrouping.getLine());
+                }
+            }
+            addedGroupings.add(builder);
+        } else {
+            if (parent instanceof DataNodeContainerBuilder) {
+                DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+                for (GroupingBuilder addedGrouping : parentNode.getGroupingBuilders()) {
+                    if (addedGrouping.getQName().getLocalName().equals(groupingName)) {
+                        raiseYangParserException("", "Grouping", groupingName, line, addedGrouping.getLine());
+                    }
+                }
+                parentNode.addGrouping(builder);
+            } else if (parent instanceof RpcDefinitionBuilder) {
+                RpcDefinitionBuilder parentNode = (RpcDefinitionBuilder) parent;
+                for (GroupingBuilder child : parentNode.getGroupings()) {
+                    if (child.getQName().getLocalName().equals(groupingName)) {
+                        raiseYangParserException("", "Grouping", groupingName, line, child.getLine());
+                    }
+                }
+                parentNode.addGrouping(builder);
+            } else {
+                throw new YangParseException(name, line, "Unresolved parent of grouping " + groupingName);
+            }
+        }
+
+        return builder;
+    }
+
+    public AugmentationSchemaBuilder addAugment(final int line, final String augmentTargetStr) {
+        final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr);
+
+        Builder parent = getActualNode();
+        builder.setParent(parent);
+
+        if (parent.equals(this)) {
+            // augment can be declared only under 'module' ...
+            addedAugments.add(builder);
+        } else {
+            // ... or 'uses' statement
+            if (parent instanceof UsesNodeBuilder) {
+                ((UsesNodeBuilder) parent).addAugment(builder);
+            } else {
+                throw new YangParseException(name, line, "Augment can be declared only under module or uses statement.");
+            }
+        }
+        allAugments.add(builder);
+
+        return builder;
+    }
+
+    @Override
+    public Set<UsesNodeBuilder> getUsesNodes() {
+        return addedUsesNodes;
+    }
+
+    @Override
+    public void addUsesNode(UsesNodeBuilder usesBuilder) {
+        addedUsesNodes.add(usesBuilder);
+        allUsesNodes.add(usesBuilder);
+    }
+
+    public UsesNodeBuilder addUsesNode(final int line, final String groupingPathStr) {
+        final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(name, line, groupingPathStr);
+
+        Builder parent = getActualNode();
+        usesBuilder.setParent(parent);
+
+        if (parent.equals(this)) {
+            addedUsesNodes.add(usesBuilder);
+        } else {
+            if (!(parent instanceof DataNodeContainerBuilder)) {
+                throw new YangParseException(name, line, "Unresolved parent of uses '" + groupingPathStr + "'.");
+            }
+            ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
+        }
+        allUsesNodes.add(usesBuilder);
+        return usesBuilder;
+    }
+
+    public void addRefine(final RefineHolder refine) {
+        final Builder parent = getActualNode();
+        if (!(parent instanceof UsesNodeBuilder)) {
+            throw new YangParseException(name, refine.getLine(), "refine can be defined only in uses statement");
+        }
+        ((UsesNodeBuilder) parent).addRefine(refine);
+        refine.setParent(parent);
+    }
+
+    public RpcDefinitionBuilder addRpc(final int line, final QName qname) {
+        Builder parent = getActualNode();
+        if (!(parent.equals(this))) {
+            throw new YangParseException(name, line, "rpc can be defined only in module or submodule");
+        }
+
+        final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(name, line, qname);
+        rpcBuilder.setParent(parent);
+
+        String rpcName = qname.getLocalName();
+        for (RpcDefinitionBuilder rpc : addedRpcs) {
+            if (rpc.getQName().getLocalName().equals(rpcName)) {
+                raiseYangParserException("", "rpc", rpcName, line, rpc.getLine());
+            }
+        }
+        for (DataSchemaNodeBuilder addedChild : addedChildNodes) {
+            if (addedChild.getQName().getLocalName().equals(rpcName)) {
+                raiseYangParserException("rpc", "node", rpcName, line, addedChild.getLine());
+            }
+        }
+        for (NotificationBuilder addedNotification : addedNotifications) {
+            if (addedNotification.getQName().getLocalName().equals(rpcName)) {
+                raiseYangParserException("rpc", "notification", rpcName, line, addedNotification.getLine());
+            }
+        }
+        addedRpcs.add(rpcBuilder);
+        return rpcBuilder;
+    }
+
+    public ContainerSchemaNodeBuilder addRpcInput(final int line, final QName qname, final SchemaPath schemaPath) {
+        final Builder parent = getActualNode();
+        if (!(parent instanceof RpcDefinitionBuilder)) {
+            throw new YangParseException(name, line, "input can be defined only in rpc statement");
+        }
+        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
+
+        final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
+        inputBuilder.setParent(rpc);
+
+        rpc.setInput(inputBuilder);
+        return inputBuilder;
+    }
+
+    public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName qname, final int line) {
+        final Builder parent = getActualNode();
+        if (!(parent instanceof RpcDefinitionBuilder)) {
+            throw new YangParseException(name, line, "output can be defined only in rpc statement");
+        }
+        final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
+
+        final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(name, line, qname, schemaPath);
+        outputBuilder.setParent(rpc);
+
+        rpc.setOutput(outputBuilder);
+        return outputBuilder;
+    }
+
+    public NotificationBuilder addNotification(final int line, final QName qname) {
+        final Builder parent = getActualNode();
+        if (!(parent.equals(this))) {
+            throw new YangParseException(name, line, "notification can be defined only in module or submodule");
+        }
+
+        String notificationName = qname.getLocalName();
+        for (NotificationBuilder nb : addedNotifications) {
+            if (nb.getQName().equals(qname)) {
+                raiseYangParserException("", "notification", notificationName, line, nb.getLine());
+            }
+        }
+        for (RpcDefinitionBuilder rpc : addedRpcs) {
+            if (rpc.getQName().getLocalName().equals(notificationName)) {
+                raiseYangParserException("notification", "rpc", notificationName, line, rpc.getLine());
+            }
+        }
+        for (DataSchemaNodeBuilder addedChild : addedChildNodes) {
+            if (addedChild.getQName().getLocalName().equals(notificationName)) {
+                raiseYangParserException("notification", "node", notificationName, line, addedChild.getLine());
+            }
+        }
+
+        final NotificationBuilder builder = new NotificationBuilder(name, line, qname);
+        builder.setParent(parent);
+        addedNotifications.add(builder);
+
+        return builder;
+    }
+
+    public FeatureBuilder addFeature(final int line, final QName qname) {
+        Builder parent = getActualNode();
+        if (!(parent.equals(this))) {
+            throw new YangParseException(name, line, "feature can be defined only in module or submodule");
+        }
+
+        final FeatureBuilder builder = new FeatureBuilder(name, line, qname);
+        builder.setParent(parent);
+
+        String featureName = qname.getLocalName();
+        for (FeatureBuilder addedFeature : addedFeatures) {
+            if (addedFeature.getQName().getLocalName().equals(featureName)) {
+                raiseYangParserException("", "feature", featureName, line, addedFeature.getLine());
+            }
+        }
+        addedFeatures.add(builder);
+        return builder;
+    }
+
+    public ChoiceBuilder addChoice(final int line, final QName qname) {
+        final ChoiceBuilder builder = new ChoiceBuilder(name, line, qname);
+
+        Builder parent = getActualNode();
+        builder.setParent(parent);
+        addChildToParent(parent, builder, qname.getLocalName());
+
+        return builder;
+    }
+
+    public ChoiceCaseBuilder addCase(final int line, final QName qname) {
+        Builder parent = getActualNode();
+        if (parent == null || parent.equals(this)) {
+            throw new YangParseException(name, line, "'case' parent not found");
+        }
+
+        final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(name, line, qname);
+        builder.setParent(parent);
+
+        if (parent instanceof ChoiceBuilder) {
+            ((ChoiceBuilder) parent).addCase(builder);
+        } else if (parent instanceof AugmentationSchemaBuilder) {
+            ((AugmentationSchemaBuilder) parent).addChildNode(builder);
+        } else {
+            throw new YangParseException(name, line, "Unresolved parent of 'case' " + qname.getLocalName());
+        }
+
+        return builder;
+    }
+
+    public AnyXmlBuilder addAnyXml(final int line, final QName qname, final SchemaPath schemaPath) {
+        final AnyXmlBuilder builder = new AnyXmlBuilder(name, line, qname, schemaPath);
+
+        Builder parent = getActualNode();
+        builder.setParent(parent);
+        addChildToParent(parent, builder, qname.getLocalName());
+
+        return builder;
+    }
+
+    @Override
+    public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
+        String nodeName = typedefBuilder.getQName().getLocalName();
+        for (TypeDefinitionBuilder tdb : addedTypedefs) {
+            if (tdb.getQName().getLocalName().equals(nodeName)) {
+                raiseYangParserException("", "typedef", nodeName, typedefBuilder.getLine(), tdb.getLine());
+            }
+        }
+        addedTypedefs.add(typedefBuilder);
+    }
+
+    public TypeDefinitionBuilderImpl addTypedef(final int line, final QName qname) {
+        final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(name, line, qname);
+
+        Builder parent = getActualNode();
+        builder.setParent(parent);
+
+        String typedefName = qname.getLocalName();
+        if (parent.equals(this)) {
+            for (TypeDefinitionBuilder tdb : addedTypedefs) {
+                if (tdb.getQName().getLocalName().equals(typedefName)) {
+                    raiseYangParserException("", "typedef", typedefName, line, tdb.getLine());
+                }
+            }
+            addedTypedefs.add(builder);
+        } else {
+            if (parent instanceof DataNodeContainerBuilder) {
+                DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+                for (TypeDefinitionBuilder child : parentNode.getTypeDefinitionBuilders()) {
+                    if (child.getQName().getLocalName().equals(typedefName)) {
+                        raiseYangParserException("", "typedef", typedefName, line, child.getLine());
+                    }
+                }
+                parentNode.addTypedef(builder);
+            } else if (parent instanceof RpcDefinitionBuilder) {
+                RpcDefinitionBuilder rpcParent = (RpcDefinitionBuilder) parent;
+                for (TypeDefinitionBuilder tdb : rpcParent.getTypeDefinitions()) {
+                    if (tdb.getQName().getLocalName().equals(builder.getQName().getLocalName())) {
+                        raiseYangParserException("", "typedef", typedefName, line, tdb.getLine());
+                    }
+                }
+                rpcParent.addTypedef(builder);
+            } else {
+                throw new YangParseException(name, line, "Unresolved parent of typedef " + typedefName);
+            }
+        }
+
+        return builder;
+    }
+
+    public void setType(final TypeDefinition<?> type) {
+        Builder parent = getActualNode();
+        if (!(parent instanceof TypeAwareBuilder)) {
+            throw new YangParseException("Failed to set type '" + type.getQName().getLocalName()
+                    + "'. Invalid parent node: " + parent);
+        }
+        ((TypeAwareBuilder) parent).setType(type);
+    }
+
+    public UnionTypeBuilder addUnionType(final int line, final URI namespace, final Date revision) {
+        final Builder parent = getActualNode();
+        if (parent == null) {
+            throw new YangParseException(name, line, "Unresolved parent of union type");
+        } else {
+            final UnionTypeBuilder union = new UnionTypeBuilder(name, line);
+            if (parent instanceof TypeAwareBuilder) {
+                ((TypeAwareBuilder) parent).setTypedef(union);
+                return union;
+            } else {
+                throw new YangParseException(name, line, "Invalid parent of union type.");
+            }
+        }
+    }
+
+    public void addIdentityrefType(final int line, final SchemaPath schemaPath, final String baseString) {
+        final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(name, line, baseString, schemaPath);
+
+        final Builder parent = getActualNode();
+        if (parent == null) {
+            throw new YangParseException(name, line, "Unresolved parent of identityref type.");
+        } else {
+            if (parent instanceof TypeAwareBuilder) {
+                final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent;
+                typeParent.setTypedef(identityref);
+                dirtyNodes.add(typeParent);
+            } else {
+                throw new YangParseException(name, line, "Invalid parent of identityref type.");
+            }
+        }
+    }
+
+    public DeviationBuilder addDeviation(final int line, final String targetPath) {
+        Builder parent = getActualNode();
+        if (!(parent.equals(this))) {
+            throw new YangParseException(name, line, "deviation can be defined only in module or submodule");
+        }
+
+        final DeviationBuilder builder = new DeviationBuilder(name, line, targetPath);
+        builder.setParent(parent);
+        addedDeviations.add(builder);
+        return builder;
+    }
+
+    public IdentitySchemaNodeBuilder addIdentity(final QName qname, final int line) {
+        Builder parent = getActualNode();
+        if (!(parent.equals(this))) {
+            throw new YangParseException(name, line, "identity can be defined only in module or submodule");
+        }
+        String identityName = qname.getLocalName();
+        for (IdentitySchemaNodeBuilder idBuilder : addedIdentities) {
+            if (idBuilder.getQName().equals(qname)) {
+                raiseYangParserException("", "identity", identityName, line, idBuilder.getLine());
+            }
+        }
+
+        final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(name, line, qname);
+        builder.setParent(parent);
+        addedIdentities.add(builder);
+        return builder;
+    }
+
+    @Override
+    public void addUnknownNodeBuilder(final UnknownSchemaNodeBuilder builder) {
+        addedUnknownNodes.add(builder);
+        allUnknownNodes.add(builder);
+    }
+
+    public UnknownSchemaNodeBuilder addUnknownSchemaNode(final int line, final QName qname) {
+        final Builder parent = getActualNode();
+        final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(name, line, qname);
+        builder.setParent(parent);
+        allUnknownNodes.add(builder);
+
+        if (parent.equals(this)) {
+            addedUnknownNodes.add(builder);
+        } else {
+            if (parent instanceof SchemaNodeBuilder) {
+                ((SchemaNodeBuilder) parent).addUnknownNodeBuilder(builder);
+            } else if (parent instanceof DataNodeContainerBuilder) {
+                ((DataNodeContainerBuilder) parent).addUnknownNodeBuilder(builder);
+            } else if (parent instanceof RefineHolder) {
+                ((RefineHolder) parent).addUnknownNodeBuilder(builder);
+            } else {
+                throw new YangParseException(name, line, "Unresolved parent of unknown node '" + qname.getLocalName()
+                        + "'");
+            }
+        }
+
+        return builder;
+    }
+
+    public Set<RpcDefinitionBuilder> getRpcs() {
+        return addedRpcs;
+    }
+
+    public Set<NotificationBuilder> getNotifications() {
+        return addedNotifications;
+    }
+
+    @Override
+    public String toString() {
+        return "module " + name;
+    }
+
+    private final class ModuleImpl implements Module {
+        private URI namespace;
+        private final String name;
+        private Date revision;
+        private String prefix;
+        private String yangVersion;
+        private String description;
+        private String reference;
+        private String organization;
+        private String contact;
+        private Set<ModuleImport> imports = Collections.emptySet();
+        private Set<FeatureDefinition> features = Collections.emptySet();
+        private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
+        private Set<NotificationDefinition> notifications = Collections.emptySet();
+        private Set<AugmentationSchema> augmentations = Collections.emptySet();
+        private Set<RpcDefinition> rpcs = Collections.emptySet();
+        private Set<Deviation> deviations = Collections.emptySet();
+        private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
+        private Set<GroupingDefinition> groupings = Collections.emptySet();
+        private Set<UsesNode> uses = Collections.emptySet();
+        private List<ExtensionDefinition> extensionNodes = Collections.emptyList();
+        private Set<IdentitySchemaNode> identities = Collections.emptySet();
+        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
+
+        private ModuleImpl(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public URI getNamespace() {
+            return namespace;
+        }
+
+        private void setNamespace(URI namespace) {
+            this.namespace = namespace;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public Date getRevision() {
+            return revision;
+        }
+
+        private void setRevision(Date revision) {
+            this.revision = revision;
+        }
+
+        @Override
+        public String getPrefix() {
+            return prefix;
+        }
+
+        private void setPrefix(String prefix) {
+            this.prefix = prefix;
+        }
+
+        @Override
+        public String getYangVersion() {
+            return yangVersion;
+        }
+
+        private void setYangVersion(String yangVersion) {
+            this.yangVersion = yangVersion;
+        }
+
+        @Override
+        public String getDescription() {
+            return description;
+        }
+
+        private void setDescription(String description) {
+            this.description = description;
+        }
+
+        @Override
+        public String getReference() {
+            return reference;
+        }
+
+        private void setReference(String reference) {
+            this.reference = reference;
+        }
+
+        @Override
+        public String getOrganization() {
+            return organization;
+        }
+
+        private void setOrganization(String organization) {
+            this.organization = organization;
+        }
+
+        @Override
+        public String getContact() {
+            return contact;
+        }
+
+        private void setContact(String contact) {
+            this.contact = contact;
+        }
+
+        @Override
+        public Set<ModuleImport> getImports() {
+            return imports;
+        }
+
+        private void setImports(Set<ModuleImport> imports) {
+            if (imports != null) {
+                this.imports = imports;
+            }
+        }
+
+        @Override
+        public Set<FeatureDefinition> getFeatures() {
+            return features;
+        }
+
+        private void setFeatures(Set<FeatureDefinition> features) {
+            if (features != null) {
+                this.features = features;
+            }
+        }
+
+        @Override
+        public Set<TypeDefinition<?>> getTypeDefinitions() {
+            return typeDefinitions;
+        }
+
+        private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
+            if (typeDefinitions != null) {
+                this.typeDefinitions = typeDefinitions;
+            }
+        }
+
+        @Override
+        public Set<NotificationDefinition> getNotifications() {
+            return notifications;
+        }
+
+        private void setNotifications(Set<NotificationDefinition> notifications) {
+            if (notifications != null) {
+                this.notifications = notifications;
+            }
+        }
+
+        @Override
+        public Set<AugmentationSchema> getAugmentations() {
+            return augmentations;
+        }
+
+        private void setAugmentations(Set<AugmentationSchema> augmentations) {
+            if (augmentations != null) {
+                this.augmentations = augmentations;
+            }
+        }
+
+        @Override
+        public Set<RpcDefinition> getRpcs() {
+            return rpcs;
+        }
+
+        private void setRpcs(Set<RpcDefinition> rpcs) {
+            if (rpcs != null) {
+                this.rpcs = rpcs;
+            }
+        }
+
+        @Override
+        public Set<Deviation> getDeviations() {
+            return deviations;
+        }
+
+        private void setDeviations(Set<Deviation> deviations) {
+            if (deviations != null) {
+                this.deviations = deviations;
+            }
+        }
+
+        @Override
+        public Set<DataSchemaNode> getChildNodes() {
+            return new LinkedHashSet<DataSchemaNode>(childNodes.values());
+        }
+
+        private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
+            if (childNodes != null) {
+                this.childNodes = childNodes;
+            }
+        }
+
+        @Override
+        public Set<GroupingDefinition> getGroupings() {
+            return groupings;
+        }
+
+        private void setGroupings(Set<GroupingDefinition> groupings) {
+            if (groupings != null) {
+                this.groupings = groupings;
+            }
+        }
+
+        @Override
+        public Set<UsesNode> getUses() {
+            return uses;
+        }
+
+        private void setUses(Set<UsesNode> uses) {
+            if (uses != null) {
+                this.uses = uses;
+            }
+        }
+
+        @Override
+        public List<ExtensionDefinition> getExtensionSchemaNodes() {
+            return extensionNodes;
+        }
+
+        private void setExtensionSchemaNodes(final List<ExtensionDefinition> extensionNodes) {
+            if (extensionNodes != null) {
+                this.extensionNodes = extensionNodes;
+            }
+        }
+
+        @Override
+        public Set<IdentitySchemaNode> getIdentities() {
+            return identities;
+        }
+
+        private void setIdentities(final Set<IdentitySchemaNode> identities) {
+            if (identities != null) {
+                this.identities = identities;
+            }
+        }
+
+        @Override
+        public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+            return unknownNodes;
+        }
+
+        private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
+            if (unknownNodes != null) {
+                this.unknownNodes = unknownNodes;
+            }
+        }
+
+        @Override
+        public DataSchemaNode getDataChildByName(QName name) {
+            return childNodes.get(name);
+        }
+
+        @Override
+        public DataSchemaNode getDataChildByName(String name) {
+            DataSchemaNode result = null;
+            for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
+                if (entry.getKey().getLocalName().equals(name)) {
+                    result = entry.getValue();
+                    break;
+                }
+            }
+            return result;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
+            result = prime * result + ((name == null) ? 0 : name.hashCode());
+            result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+            result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
+            result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            ModuleImpl other = (ModuleImpl) obj;
+            if (namespace == null) {
+                if (other.namespace != null) {
+                    return false;
+                }
+            } else if (!namespace.equals(other.namespace)) {
+                return false;
+            }
+            if (name == null) {
+                if (other.name != null) {
+                    return false;
+                }
+            } else if (!name.equals(other.name)) {
+                return false;
+            }
+            if (revision == null) {
+                if (other.revision != null) {
+                    return false;
+                }
+            } else if (!revision.equals(other.revision)) {
+                return false;
+            }
+            if (prefix == null) {
+                if (other.prefix != null) {
+                    return false;
+                }
+            } else if (!prefix.equals(other.prefix)) {
+                return false;
+            }
+            if (yangVersion == null) {
+                if (other.yangVersion != null) {
+                    return false;
+                }
+            } else if (!yangVersion.equals(other.yangVersion)) {
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
+            sb.append("[");
+            sb.append("name=" + name);
+            sb.append(", namespace=" + namespace);
+            sb.append(", revision=" + revision);
+            sb.append(", prefix=" + prefix);
+            sb.append(", yangVersion=" + yangVersion);
+            sb.append("]");
+            return sb.toString();
+        }
+    }
+
+    /**
+     * Add child to parent. Method checks for duplicates and add given child
+     * node to parent. If node with same name is found, throws exception. If
+     * parent is null, child node will be added directly to module.
+     * 
+     * @param parent
+     * @param child
+     * @param childName
+     */
+    private void addChildToParent(final Builder parent, final DataSchemaNodeBuilder child, final String childName) {
+        final int lineNum = child.getLine();
+        if (parent.equals(this)) {
+            addChildToModule(child, childName, lineNum);
+        } else {
+            addChildToSubnodeOfModule(parent, child, childName, lineNum);
+        }
+    }
+
+    /**
+     * Adds child node <code>child</code> to the set of nodes child nodes.
+     * 
+     * The method reduces the complexity of the method
+     * {@link #addChildToParent(Builder, DataSchemaNodeBuilder, String)
+     * addChildToParent}.
+     * 
+     * @param child
+     *            data schema node builder for child node
+     * @param childName
+     *            string with name of child node
+     * @param lineNum
+     *            line number in YANG file where is the node with the name equal
+     *            to <code>childName</code> is defined
+     */
+    private void addChildToModule(final DataSchemaNodeBuilder child, final String childName, final int lineNum) {
+        // if parent == null => node is defined under module
+        // All leafs, leaf-lists, lists, containers, choices, rpcs,
+        // notifications, and anyxmls defined within a parent node or at the
+        // top level of the module or its submodules share the same
+        // identifier namespace.
+        for (DataSchemaNodeBuilder childNode : addedChildNodes) {
+            if (childNode.getQName().getLocalName().equals(childName)) {
+                raiseYangParserException("'"+child+"'", "node", childName, lineNum, childNode.getLine());
+            }
+        }
+        for (RpcDefinitionBuilder rpc : addedRpcs) {
+            if (rpc.getQName().getLocalName().equals(childName)) {
+                raiseYangParserException("'"+child+"'", "rpc", childName, lineNum, rpc.getLine());
+            }
+        }
+        for (NotificationBuilder notification : addedNotifications) {
+            if (notification.getQName().getLocalName().equals(childName)) {
+                raiseYangParserException("'"+child+"'", "notification", childName, lineNum, notification.getLine());
+            }
+        }
+        addedChildNodes.add(child);
+    }
+
+    /**
+     * Adds child node <code>child</code> to the group of child nodes of the
+     * <code>parent</code>
+     * 
+     * The method reduces the complexity of the method
+     * {@link #addChildToParent(Builder, DataSchemaNodeBuilder, String)
+     * addChildToParent}. *
+     * 
+     * @param parent
+     *            builder of node which is parent for <code>child</code>
+     * @param child
+     *            data schema node builder for child node
+     * @param childName
+     *            string with name of child node
+     * @param lineNum
+     *            line number in YANG file where is the node with the name equal
+     *            to <code>childName</code> is defined
+     */
+    private void addChildToSubnodeOfModule(final Builder parent, final DataSchemaNodeBuilder child,
+            final String childName, final int lineNum) {
+        if (parent instanceof AugmentationSchemaBuilder) {
+            child.setAugmenting(true);
+        }
+        // no need for checking rpc and notification because they can be
+        // defined only under module or submodule
+        if (parent instanceof DataNodeContainerBuilder) {
+            DataNodeContainerBuilder parentNode = (DataNodeContainerBuilder) parent;
+            for (DataSchemaNodeBuilder childNode : parentNode.getChildNodeBuilders()) {
+                if (childNode.getQName().getLocalName().equals(childName)) {
+                    raiseYangParserException("'"+child+"'", "node", childName, lineNum, childNode.getLine());
+                }
+            }
+            parentNode.addChildNode(child);
+        } else if (parent instanceof ChoiceBuilder) {
+            ChoiceBuilder parentNode = (ChoiceBuilder) parent;
+            for (ChoiceCaseBuilder caseBuilder : parentNode.getCases()) {
+                if (caseBuilder.getQName().getLocalName().equals(childName)) {
+                    raiseYangParserException("'"+child+"'", "node", childName, lineNum, caseBuilder.getLine());
+                }
+            }
+            parentNode.addCase(child);
+        } else {
+            throw new YangParseException(name, lineNum, "Unresolved parent of node '" + childName + "'.");
+        }
+    }
+
+    /**
+     * 
+     * Implementation of <code>ModuleImport</code> interface only for the method
+     * {@link ModuleBuilder#createModuleImport(String, Date, String)
+     * createModuleImport}.
+     * 
+     */
+    private class ModuleImportImpl implements ModuleImport {
+        final String moduleName;
+        final Date revision;
+        final String prefix;
+
+        private ModuleImportImpl(final String moduleName, final Date revision, final String prefix) {
+            this.moduleName = moduleName;
+            this.revision = revision;
+            this.prefix = prefix;
+        }
+
+        @Override
+        public String getModuleName() {
+            return moduleName;
+        }
+
+        @Override
+        public Date getRevision() {
+            return revision;
+        }
+
+        @Override
+        public String getPrefix() {
+            return prefix;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((moduleName == null) ? 0 : moduleName.hashCode());
+            result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+            result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            ModuleImport other = (ModuleImport) obj;
+            if (getModuleName() == null) {
+                if (other.getModuleName() != null) {
+                    return false;
+                }
+            } else if (!getModuleName().equals(other.getModuleName())) {
+                return false;
+            }
+            if (getRevision() == null) {
+                if (other.getRevision() != null) {
+                    return false;
+                }
+            } else if (!getRevision().equals(other.getRevision())) {
+                return false;
+            }
+            if (getPrefix() == null) {
+                if (other.getPrefix() != null) {
+                    return false;
+                }
+            } else if (!getPrefix().equals(other.getPrefix())) {
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public String toString() {
+            return "ModuleImport[moduleName=" + moduleName + ", revision=" + revision + ", prefix=" + prefix + "]";
+        }
+    }
+
+    private ModuleImport createModuleImport(final String moduleName, final Date revision, final String prefix) {
+        final ModuleImport moduleImport = new ModuleImportImpl(moduleName, revision, prefix);
+        return moduleImport;
+    }
+
+    private void raiseYangParserException(final String cantAddType, final String type, final String name,
+            final int currentLine, final int duplicateLine) {
+
+        StringBuilder msgPrefix = new StringBuilder("");
+        if (cantAddType != null && !cantAddType.isEmpty()) {
+            msgPrefix.append("Can not add ");
+            msgPrefix.append(cantAddType);
+            msgPrefix.append(": ");
+        }
+
+        String msg = String.format("%s%s with same name '%s' already declared at line %d.", msgPrefix, type, name,
+                duplicateLine);
+        throw new YangParseException(moduleName, currentLine, msg);
+    }
+}
index 04af1d3e92982b7c31247aa013e3ec009ea58600..b9a43a838658b7417a0fcaaf90f5f857931cefed 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.parser.builder.impl;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-import java.util.TreeSet;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
-import org.opendaylight.yangtools.yang.model.api.Status;\r
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.AbstractSchemaNodeBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;\r
-import org.opendaylight.yangtools.yang.parser.util.Comparators;\r
-\r
-public final class RpcDefinitionBuilder extends AbstractSchemaNodeBuilder {\r
-    private boolean isBuilt;\r
-    private final RpcDefinitionImpl instance;\r
-    private ContainerSchemaNodeBuilder inputBuilder;\r
-    private ContainerSchemaNodeBuilder outputBuilder;\r
-    private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();\r
-    private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();\r
-\r
-    public ContainerSchemaNodeBuilder getInput() {\r
-        return inputBuilder;\r
-    }\r
-    \r
-    public ContainerSchemaNodeBuilder getOutput() {\r
-        return outputBuilder;\r
-    }\r
-    \r
-    RpcDefinitionBuilder(final String moduleName, final int line, final QName qname) {\r
-        super(moduleName, line, qname);\r
-        this.instance = new RpcDefinitionImpl(qname);\r
-    }\r
-\r
-    @Override\r
-    public RpcDefinition build() {\r
-        if (!isBuilt) {\r
-            instance.setDescription(description);\r
-            instance.setReference(reference);\r
-            instance.setStatus(status);\r
-\r
-            final ContainerSchemaNode input = inputBuilder == null ? null : inputBuilder.build();\r
-            final ContainerSchemaNode output = outputBuilder == null ? null : outputBuilder.build();\r
-            instance.setInput(input);\r
-            instance.setOutput(output);\r
-\r
-            instance.setPath(schemaPath);\r
-\r
-            // TYPEDEFS\r
-            final Set<TypeDefinition<?>> typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);\r
-            for (TypeDefinitionBuilder entry : addedTypedefs) {\r
-                typedefs.add(entry.build());\r
-            }\r
-            instance.setTypeDefinitions(typedefs);\r
-\r
-            // GROUPINGS\r
-            final Set<GroupingDefinition> groupings = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);\r
-            for (GroupingBuilder entry : addedGroupings) {\r
-                groupings.add(entry.build());\r
-            }\r
-            instance.setGroupings(groupings);\r
-\r
-            // UNKNOWN NODES\r
-            if (unknownNodes == null) {\r
-                unknownNodes = new ArrayList<UnknownSchemaNode>();\r
-                for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {\r
-                    unknownNodes.add(b.build());\r
-                }\r
-                Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);\r
-            }\r
-            instance.setUnknownSchemaNodes(unknownNodes);\r
-\r
-            isBuilt = true;\r
-        }\r
-        return instance;\r
-    }\r
-\r
-    void setInput(final ContainerSchemaNodeBuilder inputBuilder) {\r
-        this.inputBuilder = inputBuilder;\r
-    }\r
-\r
-    void setOutput(final ContainerSchemaNodeBuilder outputBuilder) {\r
-        this.outputBuilder = outputBuilder;\r
-    }\r
-\r
-    public Set<TypeDefinitionBuilder> getTypeDefinitions() {\r
-        return addedTypedefs;\r
-    }\r
-\r
-    public void addTypedef(final TypeDefinitionBuilder type) {\r
-        addedTypedefs.add(type);\r
-    }\r
-\r
-    public Set<GroupingBuilder> getGroupings() {\r
-        return addedGroupings;\r
-    }\r
-\r
-    public void addGrouping(GroupingBuilder grouping) {\r
-        addedGroupings.add(grouping);\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        final int prime = 31;\r
-        int result = 1;\r
-        result = prime * result + ((qname == null) ? 0 : qname.hashCode());\r
-        result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (obj == null) {\r
-            return false;\r
-        }\r
-        if (!(obj instanceof RpcDefinitionBuilder)) {\r
-            return false;\r
-        }\r
-        final RpcDefinitionBuilder other = (RpcDefinitionBuilder) obj;\r
-        if (other.qname == null) {\r
-            if (this.qname != null) {\r
-                return false;\r
-            }\r
-        } else if (!other.qname.equals(this.qname)) {\r
-            return false;\r
-        }\r
-        if (other.schemaPath == null) {\r
-            if (this.schemaPath != null) {\r
-                return false;\r
-            }\r
-        } else if (!other.schemaPath.equals(this.schemaPath)) {\r
-            return false;\r
-        }\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return "rpc " + qname.getLocalName();\r
-    }\r
-\r
-    private final class RpcDefinitionImpl implements RpcDefinition {\r
-        private final QName qname;\r
-        private SchemaPath path;\r
-        private String description;\r
-        private String reference;\r
-        private Status status;\r
-        private ContainerSchemaNode input;\r
-        private ContainerSchemaNode output;\r
-        private Set<TypeDefinition<?>> typeDefinitions;\r
-        private Set<GroupingDefinition> groupings;\r
-        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();\r
-\r
-        private RpcDefinitionImpl(final QName qname) {\r
-            this.qname = qname;\r
-        }\r
-\r
-        @Override\r
-        public QName getQName() {\r
-            return qname;\r
-        }\r
-\r
-        @Override\r
-        public SchemaPath getPath() {\r
-            return path;\r
-        }\r
-\r
-        private void setPath(SchemaPath path) {\r
-            this.path = path;\r
-        }\r
-\r
-        @Override\r
-        public String getDescription() {\r
-            return description;\r
-        }\r
-\r
-        private void setDescription(String description) {\r
-            this.description = description;\r
-        }\r
-\r
-        @Override\r
-        public String getReference() {\r
-            return reference;\r
-        }\r
-\r
-        private void setReference(String reference) {\r
-            this.reference = reference;\r
-        }\r
-\r
-        @Override\r
-        public Status getStatus() {\r
-            return status;\r
-        }\r
-\r
-        private void setStatus(Status status) {\r
-            this.status = status;\r
-        }\r
-\r
-        @Override\r
-        public ContainerSchemaNode getInput() {\r
-            return input;\r
-        }\r
-\r
-        private void setInput(ContainerSchemaNode input) {\r
-            this.input = input;\r
-        }\r
-\r
-        @Override\r
-        public ContainerSchemaNode getOutput() {\r
-            return output;\r
-        }\r
-\r
-        private void setOutput(ContainerSchemaNode output) {\r
-            this.output = output;\r
-        }\r
-\r
-        @Override\r
-        public Set<TypeDefinition<?>> getTypeDefinitions() {\r
-            return typeDefinitions;\r
-        }\r
-\r
-        private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {\r
-            this.typeDefinitions = typeDefinitions;\r
-        }\r
-\r
-        @Override\r
-        public Set<GroupingDefinition> getGroupings() {\r
-            return groupings;\r
-        }\r
-\r
-        private void setGroupings(Set<GroupingDefinition> groupings) {\r
-            this.groupings = groupings;\r
-        }\r
-\r
-        @Override\r
-        public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
-            return unknownNodes;\r
-        }\r
-\r
-        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {\r
-            if (unknownNodes != null) {\r
-                this.unknownNodes = unknownNodes;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            final int prime = 31;\r
-            int result = 1;\r
-            result = prime * result + ((qname == null) ? 0 : qname.hashCode());\r
-            result = prime * result + ((path == null) ? 0 : path.hashCode());\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj) {\r
-                return true;\r
-            }\r
-            if (obj == null) {\r
-                return false;\r
-            }\r
-            if (getClass() != obj.getClass()) {\r
-                return false;\r
-            }\r
-            final RpcDefinitionImpl other = (RpcDefinitionImpl) obj;\r
-            if (qname == null) {\r
-                if (other.qname != null) {\r
-                    return false;\r
-                }\r
-            } else if (!qname.equals(other.qname)) {\r
-                return false;\r
-            }\r
-            if (path == null) {\r
-                if (other.path != null) {\r
-                    return false;\r
-                }\r
-            } else if (!path.equals(other.path)) {\r
-                return false;\r
-            }\r
-            return true;\r
-        }\r
-\r
-        @Override\r
-        public String toString() {\r
-            StringBuilder sb = new StringBuilder(RpcDefinitionImpl.class.getSimpleName() + "[");\r
-            sb.append("qname=" + qname);\r
-            sb.append(", path=" + path);\r
-            sb.append(", input=" + input);\r
-            sb.append(", output=" + output + "]");\r
-            return sb.toString();\r
-        }\r
-    }\r
-\r
-}\r
+/*
+ * 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.builder.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.parser.builder.api.AbstractSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.util.Comparators;
+
+public final class RpcDefinitionBuilder extends AbstractSchemaNodeBuilder {
+    private boolean isBuilt;
+    private final RpcDefinitionImpl instance;
+    private ContainerSchemaNodeBuilder inputBuilder;
+    private ContainerSchemaNodeBuilder outputBuilder;
+    private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
+    private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
+
+    public ContainerSchemaNodeBuilder getInput() {
+        return inputBuilder;
+    }
+
+    public ContainerSchemaNodeBuilder getOutput() {
+        return outputBuilder;
+    }
+
+    RpcDefinitionBuilder(final String moduleName, final int line, final QName qname) {
+        super(moduleName, line, qname);
+        this.instance = new RpcDefinitionImpl(qname);
+    }
+
+    @Override
+    public RpcDefinition build() {
+        if (!isBuilt) {
+            instance.setDescription(description);
+            instance.setReference(reference);
+            instance.setStatus(status);
+
+            final ContainerSchemaNode input = inputBuilder == null ? null : inputBuilder.build();
+            final ContainerSchemaNode output = outputBuilder == null ? null : outputBuilder.build();
+            instance.setInput(input);
+            instance.setOutput(output);
+
+            instance.setPath(schemaPath);
+
+            // TYPEDEFS
+            final Set<TypeDefinition<?>> typedefs = new TreeSet<TypeDefinition<?>>(Comparators.SCHEMA_NODE_COMP);
+            for (TypeDefinitionBuilder entry : addedTypedefs) {
+                typedefs.add(entry.build());
+            }
+            instance.setTypeDefinitions(typedefs);
+
+            // GROUPINGS
+            final Set<GroupingDefinition> groupings = new TreeSet<GroupingDefinition>(Comparators.SCHEMA_NODE_COMP);
+            for (GroupingBuilder entry : addedGroupings) {
+                groupings.add(entry.build());
+            }
+            instance.setGroupings(groupings);
+
+            // UNKNOWN NODES
+            if (unknownNodes == null) {
+                unknownNodes = new ArrayList<UnknownSchemaNode>();
+                for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+                    unknownNodes.add(b.build());
+                }
+                Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
+            }
+            instance.setUnknownSchemaNodes(unknownNodes);
+
+            isBuilt = true;
+        }
+        return instance;
+    }
+
+    void setInput(final ContainerSchemaNodeBuilder inputBuilder) {
+        this.inputBuilder = inputBuilder;
+    }
+
+    void setOutput(final ContainerSchemaNodeBuilder outputBuilder) {
+        this.outputBuilder = outputBuilder;
+    }
+
+    public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+        return addedTypedefs;
+    }
+
+    public void addTypedef(final TypeDefinitionBuilder type) {
+        addedTypedefs.add(type);
+    }
+
+    public Set<GroupingBuilder> getGroupings() {
+        return addedGroupings;
+    }
+
+    public void addGrouping(GroupingBuilder grouping) {
+        addedGroupings.add(grouping);
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+        result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof RpcDefinitionBuilder)) {
+            return false;
+        }
+        final RpcDefinitionBuilder other = (RpcDefinitionBuilder) obj;
+        if (other.qname == null) {
+            if (this.qname != null) {
+                return false;
+            }
+        } else if (!other.qname.equals(this.qname)) {
+            return false;
+        }
+        if (other.schemaPath == null) {
+            if (this.schemaPath != null) {
+                return false;
+            }
+        } else if (!other.schemaPath.equals(this.schemaPath)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "rpc " + qname.getLocalName();
+    }
+
+    private final class RpcDefinitionImpl implements RpcDefinition {
+        private final QName qname;
+        private SchemaPath path;
+        private String description;
+        private String reference;
+        private Status status;
+        private ContainerSchemaNode input;
+        private ContainerSchemaNode output;
+        private Set<TypeDefinition<?>> typeDefinitions;
+        private Set<GroupingDefinition> groupings;
+        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
+
+        private RpcDefinitionImpl(final QName qname) {
+            this.qname = qname;
+        }
+
+        @Override
+        public QName getQName() {
+            return qname;
+        }
+
+        @Override
+        public SchemaPath getPath() {
+            return path;
+        }
+
+        private void setPath(SchemaPath path) {
+            this.path = path;
+        }
+
+        @Override
+        public String getDescription() {
+            return description;
+        }
+
+        private void setDescription(String description) {
+            this.description = description;
+        }
+
+        @Override
+        public String getReference() {
+            return reference;
+        }
+
+        private void setReference(String reference) {
+            this.reference = reference;
+        }
+
+        @Override
+        public Status getStatus() {
+            return status;
+        }
+
+        private void setStatus(Status status) {
+            this.status = status;
+        }
+
+        @Override
+        public ContainerSchemaNode getInput() {
+            return input;
+        }
+
+        private void setInput(ContainerSchemaNode input) {
+            this.input = input;
+        }
+
+        @Override
+        public ContainerSchemaNode getOutput() {
+            return output;
+        }
+
+        private void setOutput(ContainerSchemaNode output) {
+            this.output = output;
+        }
+
+        @Override
+        public Set<TypeDefinition<?>> getTypeDefinitions() {
+            return typeDefinitions;
+        }
+
+        private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
+            this.typeDefinitions = typeDefinitions;
+        }
+
+        @Override
+        public Set<GroupingDefinition> getGroupings() {
+            return groupings;
+        }
+
+        private void setGroupings(Set<GroupingDefinition> groupings) {
+            this.groupings = groupings;
+        }
+
+        @Override
+        public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+            return unknownNodes;
+        }
+
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownNodes) {
+            if (unknownNodes != null) {
+                this.unknownNodes = unknownNodes;
+            }
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+            result = prime * result + ((path == null) ? 0 : path.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            final RpcDefinitionImpl other = (RpcDefinitionImpl) obj;
+            if (qname == null) {
+                if (other.qname != null) {
+                    return false;
+                }
+            } else if (!qname.equals(other.qname)) {
+                return false;
+            }
+            if (path == null) {
+                if (other.path != null) {
+                    return false;
+                }
+            } else if (!path.equals(other.path)) {
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(RpcDefinitionImpl.class.getSimpleName());
+            sb.append("[");
+            sb.append("qname=");
+            sb.append(qname);
+            sb.append(", path=");
+            sb.append(path);
+            sb.append(", input=");
+            sb.append(input);
+            sb.append(", output=");
+            sb.append(output);
+            sb.append("]");
+            return sb.toString();
+        }
+    }
+
+}
index 301a5a3c571bf0f601d7efd0da4eef720f4081b3..ced88fca7191af231c9ec413c4f389228fcf2fdb 100644 (file)
@@ -32,8 +32,8 @@ import org.opendaylight.yangtools.yang.parser.util.YangParseException;
  * types.
  */
 public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
-    private final static String NAME = "union";
-    private final static QName QNAME = BaseTypes.constructQName(NAME);
+    private static final String NAME = "union";
+    private static final QName QNAME = BaseTypes.constructQName(NAME);
 
     private final List<TypeDefinition<?>> types;
     private final List<TypeDefinitionBuilder> typedefs;
@@ -213,9 +213,12 @@ public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
 
     @Override
     public String toString() {
-        final StringBuilder result = new StringBuilder(UnionTypeBuilder.class.getSimpleName() + "[");
-        result.append("types=" + types);
-        result.append(", typedefs=" + typedefs);
+        final StringBuilder result = new StringBuilder(UnionTypeBuilder.class.getSimpleName());
+        result.append("[");
+        result.append("types=");
+        result.append(types);
+        result.append(", typedefs=");
+        result.append(typedefs);
         result.append("]");
         return result.toString();
     }
index c1978e836c79eac220e2bcb3a11401bb1f502d65..abc1fe767a1748ef8363d371590d54dc0785c852 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.parser.builder.impl;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;\r
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.UsesNode;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.AbstractBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.Builder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;\r
-import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;\r
-import org.opendaylight.yangtools.yang.parser.util.RefineHolder;\r
-import org.opendaylight.yangtools.yang.parser.util.YangParseException;\r
-\r
-public final class UsesNodeBuilderImpl extends AbstractBuilder implements UsesNodeBuilder {\r
-    private boolean isBuilt;\r
-    private UsesNodeImpl instance;\r
-    private DataNodeContainerBuilder parent;\r
-    private final String groupingName;\r
-    private SchemaPath groupingPath;\r
-    private GroupingDefinition groupingDefinition;\r
-    private GroupingBuilder groupingBuilder;\r
-    private boolean addedByUses;\r
-    private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();\r
-    private final List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
-    private final List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
-\r
-    private Set<DataSchemaNodeBuilder> targetChildren = new HashSet<>();\r
-    private Set<GroupingBuilder> targetGroupings = new HashSet<>();\r
-    private Set<TypeDefinitionBuilder> targetTypedefs = new HashSet<>();\r
-    private List<UnknownSchemaNodeBuilder> targetUnknownNodes = new ArrayList<>();\r
-\r
-    private final boolean isCopy;\r
-    private boolean dataCollected;\r
-\r
-    @Override\r
-    public boolean isCopy() {\r
-        return isCopy;\r
-    }\r
-\r
-    @Override\r
-    public boolean isDataCollected() {\r
-        return dataCollected;\r
-    }\r
-\r
-    @Override\r
-    public void setDataCollected(boolean dataCollected) {\r
-        this.dataCollected = dataCollected;\r
-    }\r
-\r
-    public UsesNodeBuilderImpl(final String moduleName, final int line, final String groupingName) {\r
-        super(moduleName, line);\r
-        this.groupingName = groupingName;\r
-        isCopy = false;\r
-    }\r
-\r
-    public UsesNodeBuilderImpl(final String moduleName, final int line, final String groupingName, final boolean isCopy) {\r
-        super(moduleName, line);\r
-        this.groupingName = groupingName;\r
-        this.isCopy = isCopy;\r
-    }\r
-\r
-    @Override\r
-    public UsesNode build() {\r
-        if (!isBuilt) {\r
-            instance = new UsesNodeImpl(groupingPath);\r
-            instance.setAddedByUses(addedByUses);\r
-\r
-            // AUGMENTATIONS\r
-            final Set<AugmentationSchema> augments = new HashSet<AugmentationSchema>();\r
-            for (AugmentationSchemaBuilder builder : addedAugments) {\r
-                augments.add(builder.build());\r
-            }\r
-            instance.setAugmentations(augments);\r
-\r
-            // REFINES\r
-            final Map<SchemaPath, SchemaNode> refineNodes = new HashMap<SchemaPath, SchemaNode>();\r
-            for (SchemaNodeBuilder refineBuilder : refineBuilders) {\r
-                SchemaNode refineNode = refineBuilder.build();\r
-                refineNodes.put(refineNode.getPath(), refineNode);\r
-            }\r
-            instance.setRefines(refineNodes);\r
-\r
-            // UNKNOWN NODES\r
-            List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();\r
-            for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {\r
-                unknownNodes.add(b.build());\r
-            }\r
-            instance.setUnknownSchemaNodes(unknownNodes);\r
-\r
-            isBuilt = true;\r
-        }\r
-\r
-        return instance;\r
-    }\r
-\r
-    @Override\r
-    public DataNodeContainerBuilder getParent() {\r
-        return parent;\r
-    }\r
-\r
-    @Override\r
-    public void setParent(Builder parent) {\r
-        if (!(parent instanceof DataNodeContainerBuilder)) {\r
-            throw new YangParseException(moduleName, line,\r
-                    "Parent of 'uses' has to be instance of DataNodeContainerBuilder, but was: '" + parent + "'.");\r
-        }\r
-        this.parent = (DataNodeContainerBuilder) parent;\r
-    }\r
-\r
-    @Override\r
-    public SchemaPath getGroupingPath() {\r
-        return groupingPath;\r
-    }\r
-\r
-    @Override\r
-    public GroupingDefinition getGroupingDefinition() {\r
-        return groupingDefinition;\r
-    }\r
-\r
-    @Override\r
-    public void setGroupingDefinition(GroupingDefinition groupingDefinition) {\r
-        this.groupingDefinition = groupingDefinition;\r
-        if (groupingDefinition != null) {\r
-            this.groupingPath = groupingDefinition.getPath();\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public GroupingBuilder getGroupingBuilder() {\r
-        return groupingBuilder;\r
-    }\r
-\r
-    @Override\r
-    public void setGrouping(GroupingBuilder grouping) {\r
-        this.groupingBuilder = grouping;\r
-        if (groupingBuilder != null) {\r
-            this.groupingPath = groupingBuilder.getPath();\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public String getGroupingPathAsString() {\r
-        return groupingName;\r
-    }\r
-\r
-    @Override\r
-    public Set<AugmentationSchemaBuilder> getAugmentations() {\r
-        return addedAugments;\r
-    }\r
-\r
-    @Override\r
-    public void addAugment(final AugmentationSchemaBuilder augmentBuilder) {\r
-        addedAugments.add(augmentBuilder);\r
-    }\r
-\r
-    @Override\r
-    public boolean isAddedByUses() {\r
-        return addedByUses;\r
-    }\r
-\r
-    @Override\r
-    public void setAddedByUses(final boolean addedByUses) {\r
-        this.addedByUses = addedByUses;\r
-    }\r
-\r
-    @Override\r
-    public List<SchemaNodeBuilder> getRefineNodes() {\r
-        return refineBuilders;\r
-    }\r
-\r
-    @Override\r
-    public void addRefineNode(DataSchemaNodeBuilder refineNode) {\r
-        refineBuilders.add(refineNode);\r
-    }\r
-\r
-    @Override\r
-    public List<RefineHolder> getRefines() {\r
-        return refines;\r
-    }\r
-\r
-    @Override\r
-    public void addRefine(RefineHolder refine) {\r
-        refines.add(refine);\r
-    }\r
-\r
-    @Override\r
-    public Set<DataSchemaNodeBuilder> getTargetChildren() {\r
-        return targetChildren;\r
-    }\r
-\r
-    @Override\r
-    public void setTargetChildren(Set<DataSchemaNodeBuilder> targetChildren) {\r
-        this.targetChildren = targetChildren;\r
-    }\r
-\r
-    @Override\r
-    public Set<GroupingBuilder> getTargetGroupings() {\r
-        return targetGroupings;\r
-    }\r
-\r
-    @Override\r
-    public void setTargetGroupings(Set<GroupingBuilder> targetGroupings) {\r
-        this.targetGroupings = targetGroupings;\r
-    }\r
-\r
-    @Override\r
-    public Set<TypeDefinitionBuilder> getTargetTypedefs() {\r
-        return targetTypedefs;\r
-    }\r
-\r
-    @Override\r
-    public void setTargetTypedefs(Set<TypeDefinitionBuilder> targetTypedefs) {\r
-        this.targetTypedefs = targetTypedefs;\r
-    }\r
-\r
-    @Override\r
-    public List<UnknownSchemaNodeBuilder> getTargetUnknownNodes() {\r
-        return targetUnknownNodes;\r
-    }\r
-\r
-    @Override\r
-    public void setTargetUnknownNodes(List<UnknownSchemaNodeBuilder> targetUnknownNodes) {\r
-        this.targetUnknownNodes = targetUnknownNodes;\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        final int prime = 31;\r
-        int result = 1;\r
-        result = prime * result + ((groupingName == null) ? 0 : groupingName.hashCode());\r
-        result = prime * result + ((parent == null) ? 0 : parent.hashCode());\r
-        result = prime * result + ((refines == null) ? 0 : refines.hashCode());\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (this == obj)\r
-            return true;\r
-        if (obj == null)\r
-            return false;\r
-        if (getClass() != obj.getClass())\r
-            return false;\r
-        UsesNodeBuilderImpl other = (UsesNodeBuilderImpl) obj;\r
-        if (groupingName == null) {\r
-            if (other.groupingName != null)\r
-                return false;\r
-        } else if (!groupingName.equals(other.groupingName))\r
-            return false;\r
-        if (parent == null) {\r
-            if (other.parent != null)\r
-                return false;\r
-        } else if (!parent.equals(other.parent))\r
-            return false;\r
-        if (refines == null) {\r
-            if (other.refines != null)\r
-                return false;\r
-        } else if (!refines.equals(other.refines))\r
-            return false;\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return "uses '" + groupingName + "'";\r
-    }\r
-\r
-    public final class UsesNodeImpl implements UsesNode {\r
-        private final SchemaPath groupingPath;\r
-        private Set<AugmentationSchema> augmentations = Collections.emptySet();\r
-        private boolean addedByUses;\r
-        private Map<SchemaPath, SchemaNode> refines = Collections.emptyMap();\r
-        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();\r
-\r
-        private UsesNodeImpl(final SchemaPath groupingPath) {\r
-            this.groupingPath = groupingPath;\r
-        }\r
-\r
-        @Override\r
-        public SchemaPath getGroupingPath() {\r
-            return groupingPath;\r
-        }\r
-\r
-        @Override\r
-        public Set<AugmentationSchema> getAugmentations() {\r
-            return augmentations;\r
-        }\r
-\r
-        private void setAugmentations(final Set<AugmentationSchema> augmentations) {\r
-            if (augmentations != null) {\r
-                this.augmentations = augmentations;\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public boolean isAugmenting() {\r
-            return false;\r
-        }\r
-\r
-        @Override\r
-        public boolean isAddedByUses() {\r
-            return addedByUses;\r
-        }\r
-\r
-        private void setAddedByUses(final boolean addedByUses) {\r
-            this.addedByUses = addedByUses;\r
-        }\r
-\r
-        @Override\r
-        public Map<SchemaPath, SchemaNode> getRefines() {\r
-            return refines;\r
-        }\r
-\r
-        private void setRefines(Map<SchemaPath, SchemaNode> refines) {\r
-            if (refines != null) {\r
-                this.refines = refines;\r
-            }\r
-        }\r
-\r
-        public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
-            return unknownNodes;\r
-        }\r
-\r
-        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {\r
-            if (unknownSchemaNodes != null) {\r
-                this.unknownNodes = unknownSchemaNodes;\r
-            }\r
-        }\r
-\r
-        public UsesNodeBuilder toBuilder() {\r
-            return UsesNodeBuilderImpl.this;\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            final int prime = 31;\r
-            int result = 1;\r
-            result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode());\r
-            result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj) {\r
-                return true;\r
-            }\r
-            if (obj == null) {\r
-                return false;\r
-            }\r
-            if (getClass() != obj.getClass()) {\r
-                return false;\r
-            }\r
-            final UsesNodeImpl other = (UsesNodeImpl) obj;\r
-            if (groupingPath == null) {\r
-                if (other.groupingPath != null) {\r
-                    return false;\r
-                }\r
-            } else if (!groupingPath.equals(other.groupingPath)) {\r
-                return false;\r
-            }\r
-            if (augmentations == null) {\r
-                if (other.augmentations != null) {\r
-                    return false;\r
-                }\r
-            } else if (!augmentations.equals(other.augmentations)) {\r
-                return false;\r
-            }\r
-            return true;\r
-        }\r
-\r
-        @Override\r
-        public String toString() {\r
-            StringBuilder sb = new StringBuilder(UsesNodeImpl.class.getSimpleName());\r
-            sb.append("[groupingPath=" + groupingPath + "]");\r
-            return sb.toString();\r
-        }\r
-    }\r
-\r
-}\r
+/*
+ * 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.builder.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.parser.builder.api.AbstractBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.util.RefineHolder;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+public final class UsesNodeBuilderImpl extends AbstractBuilder implements UsesNodeBuilder {
+    private boolean isBuilt;
+    private UsesNodeImpl instance;
+    private DataNodeContainerBuilder parent;
+    private final String groupingName;
+    private SchemaPath groupingPath;
+    private GroupingDefinition groupingDefinition;
+    private GroupingBuilder groupingBuilder;
+    private boolean addedByUses;
+    private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();
+    private final List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();
+    private final List<RefineHolder> refines = new ArrayList<RefineHolder>();
+
+    private Set<DataSchemaNodeBuilder> targetChildren = new HashSet<>();
+    private Set<GroupingBuilder> targetGroupings = new HashSet<>();
+    private Set<TypeDefinitionBuilder> targetTypedefs = new HashSet<>();
+    private List<UnknownSchemaNodeBuilder> targetUnknownNodes = new ArrayList<>();
+
+    private final boolean isCopy;
+    private boolean dataCollected;
+
+    @Override
+    public boolean isCopy() {
+        return isCopy;
+    }
+
+    @Override
+    public boolean isDataCollected() {
+        return dataCollected;
+    }
+
+    @Override
+    public void setDataCollected(boolean dataCollected) {
+        this.dataCollected = dataCollected;
+    }
+
+    public UsesNodeBuilderImpl(final String moduleName, final int line, final String groupingName) {
+        super(moduleName, line);
+        this.groupingName = groupingName;
+        isCopy = false;
+    }
+
+    public UsesNodeBuilderImpl(final String moduleName, final int line, final String groupingName, final boolean isCopy) {
+        super(moduleName, line);
+        this.groupingName = groupingName;
+        this.isCopy = isCopy;
+    }
+
+    @Override
+    public UsesNode build() {
+        if (!isBuilt) {
+            instance = new UsesNodeImpl(groupingPath);
+            instance.setAddedByUses(addedByUses);
+
+            // AUGMENTATIONS
+            final Set<AugmentationSchema> augments = new HashSet<AugmentationSchema>();
+            for (AugmentationSchemaBuilder builder : addedAugments) {
+                augments.add(builder.build());
+            }
+            instance.setAugmentations(augments);
+
+            // REFINES
+            final Map<SchemaPath, SchemaNode> refineNodes = new HashMap<SchemaPath, SchemaNode>();
+            for (SchemaNodeBuilder refineBuilder : refineBuilders) {
+                SchemaNode refineNode = refineBuilder.build();
+                refineNodes.put(refineNode.getPath(), refineNode);
+            }
+            instance.setRefines(refineNodes);
+
+            // UNKNOWN NODES
+            List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+            for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+                unknownNodes.add(b.build());
+            }
+            instance.setUnknownSchemaNodes(unknownNodes);
+
+            isBuilt = true;
+        }
+
+        return instance;
+    }
+
+    @Override
+    public DataNodeContainerBuilder getParent() {
+        return parent;
+    }
+
+    @Override
+    public void setParent(Builder parent) {
+        if (!(parent instanceof DataNodeContainerBuilder)) {
+            throw new YangParseException(moduleName, line,
+                    "Parent of 'uses' has to be instance of DataNodeContainerBuilder, but was: '" + parent + "'.");
+        }
+        this.parent = (DataNodeContainerBuilder) parent;
+    }
+
+    @Override
+    public SchemaPath getGroupingPath() {
+        return groupingPath;
+    }
+
+    @Override
+    public GroupingDefinition getGroupingDefinition() {
+        return groupingDefinition;
+    }
+
+    @Override
+    public void setGroupingDefinition(GroupingDefinition groupingDefinition) {
+        this.groupingDefinition = groupingDefinition;
+        if (groupingDefinition != null) {
+            this.groupingPath = groupingDefinition.getPath();
+        }
+    }
+
+    @Override
+    public GroupingBuilder getGroupingBuilder() {
+        return groupingBuilder;
+    }
+
+    @Override
+    public void setGrouping(GroupingBuilder grouping) {
+        this.groupingBuilder = grouping;
+        if (groupingBuilder != null) {
+            this.groupingPath = groupingBuilder.getPath();
+        }
+    }
+
+    @Override
+    public String getGroupingPathAsString() {
+        return groupingName;
+    }
+
+    @Override
+    public Set<AugmentationSchemaBuilder> getAugmentations() {
+        return addedAugments;
+    }
+
+    @Override
+    public void addAugment(final AugmentationSchemaBuilder augmentBuilder) {
+        addedAugments.add(augmentBuilder);
+    }
+
+    @Override
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
+    @Override
+    public void setAddedByUses(final boolean addedByUses) {
+        this.addedByUses = addedByUses;
+    }
+
+    @Override
+    public List<SchemaNodeBuilder> getRefineNodes() {
+        return refineBuilders;
+    }
+
+    @Override
+    public void addRefineNode(DataSchemaNodeBuilder refineNode) {
+        refineBuilders.add(refineNode);
+    }
+
+    @Override
+    public List<RefineHolder> getRefines() {
+        return refines;
+    }
+
+    @Override
+    public void addRefine(RefineHolder refine) {
+        refines.add(refine);
+    }
+
+    @Override
+    public Set<DataSchemaNodeBuilder> getTargetChildren() {
+        return targetChildren;
+    }
+
+    @Override
+    public void setTargetChildren(Set<DataSchemaNodeBuilder> targetChildren) {
+        this.targetChildren = targetChildren;
+    }
+
+    @Override
+    public Set<GroupingBuilder> getTargetGroupings() {
+        return targetGroupings;
+    }
+
+    @Override
+    public void setTargetGroupings(Set<GroupingBuilder> targetGroupings) {
+        this.targetGroupings = targetGroupings;
+    }
+
+    @Override
+    public Set<TypeDefinitionBuilder> getTargetTypedefs() {
+        return targetTypedefs;
+    }
+
+    @Override
+    public void setTargetTypedefs(Set<TypeDefinitionBuilder> targetTypedefs) {
+        this.targetTypedefs = targetTypedefs;
+    }
+
+    @Override
+    public List<UnknownSchemaNodeBuilder> getTargetUnknownNodes() {
+        return targetUnknownNodes;
+    }
+
+    @Override
+    public void setTargetUnknownNodes(List<UnknownSchemaNodeBuilder> targetUnknownNodes) {
+        this.targetUnknownNodes = targetUnknownNodes;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((groupingName == null) ? 0 : groupingName.hashCode());
+        result = prime * result + ((parent == null) ? 0 : parent.hashCode());
+        result = prime * result + ((refines == null) ? 0 : refines.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        UsesNodeBuilderImpl other = (UsesNodeBuilderImpl) obj;
+        if (groupingName == null) {
+            if (other.groupingName != null) {
+                return false;
+            }
+        } else if (!groupingName.equals(other.groupingName)) {
+            return false;
+        }
+        if (parent == null) {
+            if (other.parent != null) {
+                return false;
+            }
+        } else if (!parent.equals(other.parent)) {
+            return false;
+        }
+        if (refines == null) {
+            if (other.refines != null) {
+                return false;
+            }
+        } else if (!refines.equals(other.refines)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "uses '" + groupingName + "'";
+    }
+
+    public final class UsesNodeImpl implements UsesNode {
+        private final SchemaPath groupingPath;
+        private Set<AugmentationSchema> augmentations = Collections.emptySet();
+        private boolean addedByUses;
+        private Map<SchemaPath, SchemaNode> refines = Collections.emptyMap();
+        private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
+
+        private UsesNodeImpl(final SchemaPath groupingPath) {
+            this.groupingPath = groupingPath;
+        }
+
+        @Override
+        public SchemaPath getGroupingPath() {
+            return groupingPath;
+        }
+
+        @Override
+        public Set<AugmentationSchema> getAugmentations() {
+            return augmentations;
+        }
+
+        private void setAugmentations(final Set<AugmentationSchema> augmentations) {
+            if (augmentations != null) {
+                this.augmentations = augmentations;
+            }
+        }
+
+        @Override
+        public boolean isAugmenting() {
+            return false;
+        }
+
+        @Override
+        public boolean isAddedByUses() {
+            return addedByUses;
+        }
+
+        private void setAddedByUses(final boolean addedByUses) {
+            this.addedByUses = addedByUses;
+        }
+
+        @Override
+        public Map<SchemaPath, SchemaNode> getRefines() {
+            return refines;
+        }
+
+        private void setRefines(Map<SchemaPath, SchemaNode> refines) {
+            if (refines != null) {
+                this.refines = refines;
+            }
+        }
+
+        public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+            return unknownNodes;
+        }
+
+        private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+            if (unknownSchemaNodes != null) {
+                this.unknownNodes = unknownSchemaNodes;
+            }
+        }
+
+        public UsesNodeBuilder toBuilder() {
+            return UsesNodeBuilderImpl.this;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode());
+            result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null) {
+                return false;
+            }
+            if (getClass() != obj.getClass()) {
+                return false;
+            }
+            final UsesNodeImpl other = (UsesNodeImpl) obj;
+            if (groupingPath == null) {
+                if (other.groupingPath != null) {
+                    return false;
+                }
+            } else if (!groupingPath.equals(other.groupingPath)) {
+                return false;
+            }
+            if (augmentations == null) {
+                if (other.augmentations != null) {
+                    return false;
+                }
+            } else if (!augmentations.equals(other.augmentations)) {
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(UsesNodeImpl.class.getSimpleName());
+            sb.append("[groupingPath=");
+            sb.append(groupingPath);
+            sb.append("]");
+            return sb.toString();
+        }
+    }
+
+}
index 3efd7edeeecc3b193c88ab3bbf8bca9c1f878848..6be46df39742b2aa35ff77b065c47dcdd2d9a1f3 100644 (file)
@@ -72,7 +72,7 @@ import com.google.common.collect.Sets;
 
 public final class YangParserImpl implements YangModelParser {
     private static final Logger LOG = LoggerFactory.getLogger(YangParserImpl.class);
-    
+
     private static final String FAIL_DEVIATION_TARGET = "Failed to find deviation target.";
 
     @Override
@@ -278,7 +278,7 @@ public final class YangParserImpl implements YangModelParser {
         findUsesTargets(modules, null);
         resolveDirtyNodes(modules);
         resolveAugments(modules);
-        resolveUses(modules);
+        resolveUses(modules, false);
         resolveDeviations(modules);
 
         // build
@@ -301,7 +301,7 @@ public final class YangParserImpl implements YangModelParser {
         findUsesTargets(modules, context);
         resolvedDirtyNodesWithContext(modules, context);
         resolveAugmentsWithContext(modules, context);
-        resolveUsesWithContext(modules);
+        resolveUses(modules, true);
         resolveDeviationsWithContext(modules, context);
 
         // build
@@ -344,7 +344,7 @@ public final class YangParserImpl implements YangModelParser {
     /**
      * Search for dirty nodes (node which contains UnknownType) and resolve
      * unknown types.
-     *
+     * 
      * @param modules
      *            all available modules
      * @param module
@@ -390,7 +390,7 @@ public final class YangParserImpl implements YangModelParser {
     /**
      * Go through all augment definitions and perform augmentation. It is
      * expected that modules are already sorted by their dependencies.
-     *
+     * 
      * @param modules
      *            all loaded modules
      */
@@ -432,7 +432,7 @@ public final class YangParserImpl implements YangModelParser {
 
     /**
      * Search for augment target and perform augmentation.
-     *
+     * 
      * @param modules
      *            all loaded modules
      * @param augmentBuilder
@@ -475,7 +475,7 @@ public final class YangParserImpl implements YangModelParser {
      * Go through all augment definitions and resolve them. This method works in
      * same way as {@link #resolveAugments(Map)} except that if target node is
      * not found in loaded modules, it search for target node in given context.
-     *
+     * 
      * @param modules
      *            all loaded modules
      * @param context
@@ -515,7 +515,7 @@ public final class YangParserImpl implements YangModelParser {
 
     /**
      * Search for augment target and perform augmentation.
-     *
+     * 
      * @param modules
      *            all loaded modules
      * @param augment
@@ -561,7 +561,7 @@ public final class YangParserImpl implements YangModelParser {
     /**
      * Go through identity statements defined in current module and resolve
      * their 'base' statement if present.
-     *
+     * 
      * @param modules
      *            all modules
      * @param module
@@ -599,7 +599,7 @@ public final class YangParserImpl implements YangModelParser {
      * Go through identity statements defined in current module and resolve
      * their 'base' statement. Method tries to find base identity in given
      * modules. If base identity is not found, method will search it in context.
-     *
+     * 
      * @param modules
      *            all loaded modules
      * @param module
@@ -650,7 +650,7 @@ public final class YangParserImpl implements YangModelParser {
 
     /**
      * Find and add reference of uses target grouping.
-     *
+     * 
      * @param modules
      *            all loaded modules
      * @param context
@@ -684,13 +684,17 @@ public final class YangParserImpl implements YangModelParser {
     }
 
     /**
-     * Copy data from uses target, update uses parent and perform refinement.
-     * Augmentations have to be resolved already.
-     *
+     * Copy data from uses target. Augmentations have to be resolved already.
+     * 
      * @param modules
      *            all loaded modules
+     * @param resolveWithContext
+     *            boolean value which says whether
+     *            {@link GroupingUtils#collectUsesDataFromContext(UsesNodeBuilder)
+     *            collectUsesDataFromContext} should be used for processing of
+     *            individual uses node.
      */
-    private void resolveUses(final Map<String, TreeMap<Date, ModuleBuilder>> modules) {
+    private void resolveUses(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final boolean resolveWithContext) {
         for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
             for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
                 ModuleBuilder module = inner.getValue();
@@ -701,68 +705,33 @@ public final class YangParserImpl implements YangModelParser {
                     usesNodes = new ArrayList<>(module.getAllUsesNodes());
                     for (UsesNodeBuilder usesNode : usesNodes) {
                         if (!usesNode.isDataCollected()) {
-                            GroupingUtils.collectUsesData(usesNode);
+                            if (resolveWithContext && usesNode.getGroupingBuilder() == null) {
+                                GroupingUtils.collectUsesDataFromContext(usesNode);
+                            } else {
+                                GroupingUtils.collectUsesData(usesNode);
+                            }
                         }
                     }
                     dataCollected = module.isAllUsesDataCollected();
                 }
             }
         }
-
-        // new loop is must because in collecting data process new uses could
-        // be created
-        final List<UsesNodeBuilder> allModulesUses = new ArrayList<>();
-        for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
-            for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
-                allModulesUses.addAll(inner.getValue().getAllUsesNodes());
-            }
-        }
-
-        for (UsesNodeBuilder usesNode : allModulesUses) {
-            GroupingUtils.updateUsesParent(usesNode);
-            GroupingUtils.performRefine(usesNode);
-        }
-        for (UsesNodeBuilder usesNode : allModulesUses) {
-            GroupingUtils.fixUsesNodesPath(usesNode);
-        }
-
-        for (UsesNodeBuilder usesNode : allModulesUses) {
-            if (usesNode.isCopy()) {
-                usesNode.getParent().getUsesNodes().remove(usesNode);
-            }
-        }
+        resolvedUsesPostProcessing(modules, resolveWithContext);
     }
 
     /**
-     * Copy data from uses target, update uses parent and perform refinement.
-     * Augmentations have to be resolved already.
-     *
+     * Update uses parent and perform refinement.
+     * 
      * @param modules
      *            all loaded modules
+     * @param resolveWithContext
+     *            boolean value which says whether
+     *            {@link GroupingUtils#collectUsesDataFromContext(UsesNodeBuilder)
+     *            collectUsesDataFromContext} should be used for processing of
+     *            individual uses node.
      */
-    private void resolveUsesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules) {
-        for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
-            for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
-                ModuleBuilder module = inner.getValue();
-                List<UsesNodeBuilder> usesNodes = null;
-                boolean dataCollected = module.isAllUsesDataCollected();
-
-                while (!dataCollected) {
-                    usesNodes = new ArrayList<>(module.getAllUsesNodes());
-                    for (UsesNodeBuilder usesNode : usesNodes) {
-                        if (!usesNode.isDataCollected()) {
-                            if (usesNode.getGroupingBuilder() == null) {
-                                GroupingUtils.collectUsesDataFromContext(usesNode);
-                            } else {
-                                GroupingUtils.collectUsesData(usesNode);
-                            }
-                        }
-                    }
-                    dataCollected = module.isAllUsesDataCollected();
-                }
-            }
-        }
-
+    private void resolvedUsesPostProcessing(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            final boolean resolveWithContext) {
         // new loop is must because in collecting data process new uses could
         // be created
         final List<UsesNodeBuilder> allModulesUses = new ArrayList<>();
@@ -779,6 +748,14 @@ public final class YangParserImpl implements YangModelParser {
         for (UsesNodeBuilder usesNode : allModulesUses) {
             GroupingUtils.fixUsesNodesPath(usesNode);
         }
+
+        if (!resolveWithContext) {
+            for (UsesNodeBuilder usesNode : allModulesUses) {
+                if (usesNode.isCopy()) {
+                    usesNode.getParent().getUsesNodes().remove(usesNode);
+                }
+            }
+        }
     }
 
     private void resolveUnknownNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
@@ -796,7 +773,7 @@ public final class YangParserImpl implements YangModelParser {
                 }
             } catch (YangParseException e) {
                 throw new YangParseException(module.getName(), usnb.getLine(), "Failed to resolve node " + usnb
-                        + ": no such extension definition found.",e);
+                        + ": no such extension definition found.", e);
             }
         }
     }
@@ -839,7 +816,7 @@ public final class YangParserImpl implements YangModelParser {
 
     /**
      * Traverse through modules and resolve their deviation statements.
-     *
+     * 
      * @param modules
      *            all loaded modules
      */
@@ -854,7 +831,7 @@ public final class YangParserImpl implements YangModelParser {
 
     /**
      * Traverse through module and resolve its deviation statements.
-     *
+     * 
      * @param modules
      *            all loaded modules
      * @param module
@@ -879,7 +856,7 @@ public final class YangParserImpl implements YangModelParser {
     /**
      * Traverse through modules and resolve their deviation statements with
      * given context.
-     *
+     * 
      * @param modules
      *            all loaded modules
      * @param context
@@ -898,7 +875,7 @@ public final class YangParserImpl implements YangModelParser {
     /**
      * Traverse through module and resolve its deviation statements with given
      * context.
-     *
+     * 
      * @param modules
      *            all loaded modules
      * @param module
@@ -950,7 +927,7 @@ public final class YangParserImpl implements YangModelParser {
 
     /**
      * Correct deviation target path in deviation builder.
-     *
+     * 
      * @param dev
      *            deviation
      * @param dependentModuleBuilder
index cd9f2f49fb94257066cf7324bf45f619ba1c66d9..a09d95a9f365136182766a4e6a9e746956c116c8 100644 (file)
@@ -80,7 +80,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class YangParserListenerImpl extends YangParserBaseListener {
-    private static final Logger logger = LoggerFactory.getLogger(YangParserListenerImpl.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(YangParserListenerImpl.class);
+    private static final String AUGMENT_STR = "augment";
 
     private ModuleBuilder moduleBuilder;
     private String moduleName;
@@ -88,7 +89,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     private String yangModelPrefix;
     private Date revision = new Date(0L);
 
-    public final static DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+    public static final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
     private final Stack<Stack<QName>> actualPath = new Stack<>();
 
     private void addNodeToPath(QName name) {
@@ -102,7 +103,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     @Override
     public void enterModule_stmt(YangParser.Module_stmtContext ctx) {
         moduleName = stringFromNode(ctx);
-        logger.debug("entering module " + moduleName);
+        LOGGER.debug("entering module " + moduleName);
         enterLog("module", moduleName, 0);
         actualPath.push(new Stack<QName>());
 
@@ -213,9 +214,9 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     private void updateRevisionForRevisionStatement(final ParseTree treeNode) {
         final String revisionDateStr = stringFromNode(treeNode);
         try {
-            final Date revision = simpleDateFormat.parse(revisionDateStr);
-            if ((revision != null) && (this.revision.compareTo(revision) < 0)) {
-                this.revision = revision;
+            final Date revisionDate = SIMPLE_DATE_FORMAT.parse(revisionDateStr);
+            if ((revisionDate != null) && (this.revision.compareTo(revisionDate) < 0)) {
+                this.revision = revisionDate;
                 moduleBuilder.setRevision(this.revision);
                 setLog("revision", this.revision.toString());
                 for (int i = 0; i < treeNode.getChildCount(); ++i) {
@@ -227,7 +228,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             }
         } catch (ParseException e) {
             final String message = "Failed to parse revision string: " + revisionDateStr;
-            logger.warn(message);
+            LOGGER.warn(message);
         }
     }
 
@@ -248,9 +249,9 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
             if (treeNode instanceof Revision_date_stmtContext) {
                 String importRevisionStr = stringFromNode(treeNode);
                 try {
-                    importRevision = simpleDateFormat.parse(importRevisionStr);
+                    importRevision = SIMPLE_DATE_FORMAT.parse(importRevisionStr);
                 } catch (ParseException e) {
-                    logger.warn("Failed to parse import revision-date at line " + line + ": " + importRevisionStr);
+                    LOGGER.warn("Failed to parse import revision-date at line " + line + ": " + importRevisionStr);
                 }
             }
         }
@@ -267,7 +268,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     public void enterAugment_stmt(YangParser.Augment_stmtContext ctx) {
         final int line = ctx.getStart().getLine();
         final String augmentPath = stringFromNode(ctx);
-        enterLog("augment", augmentPath, line);
+        enterLog(AUGMENT_STR, augmentPath, line);
         actualPath.push(new Stack<QName>());
 
         AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath);
@@ -291,7 +292,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     @Override
     public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) {
         moduleBuilder.exitNode();
-        exitLog("augment", "");
+        exitLog(AUGMENT_STR, "");
         actualPath.pop();
     }
 
@@ -394,14 +395,15 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
                     SchemaPath path = createActualSchemaPath(actualPath.peek());
                     moduleBuilder.addIdentityrefType(line, path, getIdentityrefBase(typeBody));
                 } else {
-                    type = parseTypeWithBody(typeName, typeBody, actualPath.peek(), namespace, revision, yangModelPrefix, moduleBuilder.getActualNode());
+                    type = parseTypeWithBody(typeName, typeBody, actualPath.peek(), namespace, revision,
+                            yangModelPrefix, moduleBuilder.getActualNode());
                     moduleBuilder.setType(type);
                     addNodeToPath(type.getQName());
                 }
             }
         } else {
-            type = parseUnknownTypeWithBody(typeQName, typeBody, actualPath.peek(), namespace, revision, yangModelPrefix,
-                    moduleBuilder.getActualNode());
+            type = parseUnknownTypeWithBody(typeQName, typeBody, actualPath.peek(), namespace, revision,
+                    yangModelPrefix, moduleBuilder.getActualNode());
             // add parent node of this type statement to dirty nodes
             moduleBuilder.markActualNodeDirty();
             moduleBuilder.setType(type);
@@ -549,7 +551,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         actualPath.push(new Stack<QName>());
         final int line = ctx.getStart().getLine();
         final String augmentPath = stringFromNode(ctx);
-        enterLog("augment", augmentPath, line);
+        enterLog(AUGMENT_STR, augmentPath, line);
 
         AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath);
 
@@ -572,7 +574,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     @Override
     public void exitUses_augment_stmt(YangParser.Uses_augment_stmtContext ctx) {
         moduleBuilder.exitNode();
-        exitLog("augment", "");
+        exitLog(AUGMENT_STR, "");
         actualPath.pop();
     }
 
@@ -978,19 +980,19 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
     }
 
     private void enterLog(String p1, String p2, int line) {
-        logger.trace("entering {} {} ({})", p1, p2, line);
+        LOGGER.trace("entering {} {} ({})", p1, p2, line);
     }
 
     private void exitLog(String p1, String p2) {
-        logger.trace("exiting {} {}", p1, p2);
+        LOGGER.trace("exiting {} {}", p1, p2);
     }
 
     private void exitLog(String p1, QName p2) {
-        logger.trace("exiting {} {}", p1, p2.getLocalName());
+        LOGGER.trace("exiting {} {}", p1, p2.getLocalName());
     }
 
     private void setLog(String p1, String p2) {
-        logger.trace("setting {} {}", p1, p2);
+        LOGGER.trace("setting {} {}", p1, p2);
     }
 
 }
index 971ee8293a605399cf6f5ebe7e5b92a42cb6e83e..3bd7ac00ae83a5b6c3275314bc01f4c9244f7d56 100644 (file)
@@ -52,7 +52,7 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.UsesNodeBuilderImpl;
 
-public class CopyUtils {
+public final class CopyUtils {
 
     private CopyUtils() {
     }
@@ -60,7 +60,7 @@ public class CopyUtils {
     /**
      * Create copy of DataSchemaNodeBuilder with new parent. If updateQName is
      * true, qname of node will be corrected based on new parent.
-     *
+     * 
      * @param old
      * @param newParent
      * @param updateQName
@@ -177,8 +177,8 @@ public class CopyUtils {
         QName newQName = data.qname;
         SchemaPath newSchemaPath = data.schemaPath;
 
-        ContainerSchemaNodeBuilder copy = new ContainerSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(),
-                newQName, newSchemaPath);
+        ContainerSchemaNodeBuilder copy = new ContainerSchemaNodeBuilder(newParent.getModuleName(),
+                newParent.getLine(), newQName, newSchemaPath);
         copyConstraints(copy.getConstraints(), old.getConstraints());
         copy.setParent(newParent);
         copy.setPath(newSchemaPath);
@@ -218,8 +218,8 @@ public class CopyUtils {
         QName newQName = data.qname;
         SchemaPath newSchemaPath = data.schemaPath;
 
-        LeafSchemaNodeBuilder copy = new LeafSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(), newQName,
-                newSchemaPath);
+        LeafSchemaNodeBuilder copy = new LeafSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(),
+                newQName, newSchemaPath);
         copyConstraints(copy.getConstraints(), old.getConstraints());
         copy.setParent(newParent);
         copy.setPath(newSchemaPath);
@@ -281,8 +281,8 @@ public class CopyUtils {
         QName newQName = data.qname;
         SchemaPath newSchemaPath = data.schemaPath;
 
-        ListSchemaNodeBuilder copy = new ListSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(), newQName,
-                newSchemaPath);
+        ListSchemaNodeBuilder copy = new ListSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(),
+                newQName, newSchemaPath);
         copyConstraints(copy.getConstraints(), old.getConstraints());
         copy.setParent(newParent);
         copy.setPath(newSchemaPath);
@@ -359,13 +359,13 @@ public class CopyUtils {
         TypeDefinitionBuilder type = null;
 
         if (old instanceof UnionTypeBuilder) {
-            UnionTypeBuilder oldUnion = (UnionTypeBuilder)old;
+            UnionTypeBuilder oldUnion = (UnionTypeBuilder) old;
             type = new UnionTypeBuilder(newParent.getModuleName(), newParent.getLine());
             type.setParent(newParent);
-            for(TypeDefinition<?> td : oldUnion.getTypes()) {
+            for (TypeDefinition<?> td : oldUnion.getTypes()) {
                 type.setType(td);
             }
-            for(TypeDefinitionBuilder tdb : oldUnion.getTypedefs()) {
+            for (TypeDefinitionBuilder tdb : oldUnion.getTypedefs()) {
                 type.setTypedef(copy(tdb, type, updateQName));
             }
         } else if (old instanceof IdentityrefTypeBuilder) {
@@ -522,7 +522,7 @@ public class CopyUtils {
         return new DataBean(newQName, newSchemaPath);
     }
 
-    private static class DataBean {
+    private static final class DataBean {
         private QName qname;
         private SchemaPath schemaPath;
 
@@ -532,10 +532,9 @@ public class CopyUtils {
         }
     }
 
-
     /**
      * Create AnyXmlBuilder from given AnyXmlSchemaNode.
-     *
+     * 
      * @param anyxml
      * @param qname
      * @param moduleName
@@ -554,7 +553,7 @@ public class CopyUtils {
 
     /**
      * Create GroupingBuilder from given GroupingDefinition.
-     *
+     * 
      * @param grouping
      * @param qname
      * @param moduleName
@@ -579,7 +578,7 @@ public class CopyUtils {
 
     /**
      * Create TypeDefinitionBuilder from given ExtendedType.
-     *
+     * 
      * @param typedef
      * @param qname
      * @param moduleName
@@ -609,7 +608,7 @@ public class CopyUtils {
 
     /**
      * Create UnknownSchemaNodeBuilder from given UnknownSchemaNode.
-     *
+     * 
      * @param unknownNode
      * @param qname
      * @param moduleName
@@ -632,10 +631,9 @@ public class CopyUtils {
         return builder;
     }
 
-
     /**
      * Create LeafSchemaNodeBuilder from given LeafSchemaNode.
-     *
+     * 
      * @param leaf
      *            leaf from which to create builder
      * @param qname
@@ -660,7 +658,7 @@ public class CopyUtils {
 
     /**
      * Create ContainerSchemaNodeBuilder from given ContainerSchemaNode.
-     *
+     * 
      * @param container
      * @param qname
      * @param moduleName
@@ -687,7 +685,7 @@ public class CopyUtils {
 
     /**
      * Create ListSchemaNodeBuilder from given ListSchemaNode.
-     *
+     * 
      * @param list
      * @param qname
      * @param moduleName
@@ -712,7 +710,7 @@ public class CopyUtils {
 
     /**
      * Create LeafListSchemaNodeBuilder from given LeafListSchemaNode.
-     *
+     * 
      * @param leafList
      * @param qname
      * @param moduleName
@@ -735,7 +733,7 @@ public class CopyUtils {
 
     /**
      * Create ChoiceBuilder from given ChoiceNode.
-     *
+     * 
      * @param choice
      * @param qname
      * @param moduleName
@@ -754,10 +752,9 @@ public class CopyUtils {
         return builder;
     }
 
-
     /**
      * Set DataSchemaNode arguments to builder object
-     *
+     * 
      * @param node
      *            node from which arguments should be read
      * @param builder
@@ -774,7 +771,7 @@ public class CopyUtils {
 
     /**
      * Copy constraints from constraints definition to constraints builder.
-     *
+     * 
      * @param nodeConstraints
      *            definition from which constraints will be copied
      * @param constraints
index 058d42542e019e8744b205f3c890cffba5083585..d4a7f1c6d40ca190c6f266f69d7023397e77568f 100644 (file)
@@ -41,14 +41,14 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.RpcDefinitionBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
 
-public class GroupingUtils {
+public final class GroupingUtils {
 
     private GroupingUtils() {
     }
 
     /**
      * Search given modules for grouping by name defined in uses node.
-     *
+     * 
      * @param usesBuilder
      *            builder of uses statement
      * @param modules
@@ -119,7 +119,7 @@ public class GroupingUtils {
 
     /**
      * Search context for grouping by name defined in uses node.
-     *
+     * 
      * @param usesBuilder
      *            builder of uses statement
      * @param module
@@ -153,7 +153,7 @@ public class GroupingUtils {
 
     /**
      * Find grouping by name.
-     *
+     * 
      * @param groupings
      *            collection of grouping builders to search
      * @param name
@@ -171,7 +171,7 @@ public class GroupingUtils {
 
     /**
      * Find grouping by name.
-     *
+     * 
      * @param groupings
      *            collection of grouping definitions to search
      * @param name
@@ -189,7 +189,7 @@ public class GroupingUtils {
 
     /**
      * Add nodes defined in uses target grouping to uses parent.
-     *
+     * 
      * @param usesNode
      */
     public static void updateUsesParent(UsesNodeBuilder usesNode) {
@@ -225,7 +225,7 @@ public class GroupingUtils {
     /**
      * Read data defined in target grouping builder, make a copy and add them to
      * uses node builder.
-     *
+     * 
      * @param usesNode
      *            uses node builder
      */
@@ -239,7 +239,7 @@ public class GroupingUtils {
 
     /**
      * Read child nodes defined in target grouping and make a copy of them.
-     *
+     * 
      * @param usesNode
      * @return copy of child nodes defined in uses target grouping
      */
@@ -258,7 +258,7 @@ public class GroupingUtils {
 
     /**
      * Read typedefs defined in target grouping and make a copy of them.
-     *
+     * 
      * @param usesNode
      * @return copy of typedefs defined in uses target grouping
      */
@@ -277,7 +277,7 @@ public class GroupingUtils {
 
     /**
      * Read groupings defined in target grouping and make a copy of them.
-     *
+     * 
      * @param usesNode
      * @return copy of groupings defined in uses target grouping
      */
@@ -296,7 +296,7 @@ public class GroupingUtils {
 
     /**
      * Read unknown nodes defined in target grouping and make a copy of them.
-     *
+     * 
      * @param usesNode
      * @return copy of unknown nodes defined in uses target grouping
      */
@@ -316,7 +316,7 @@ public class GroupingUtils {
     /**
      * Read data defined in target grouping definition, make a copy and add them
      * to uses node builder.
-     *
+     * 
      * @param usesNode
      *            uses node builder
      */
@@ -329,37 +329,7 @@ public class GroupingUtils {
         int line = parent.getLine();
 
         // child nodes
-        final Set<DataSchemaNodeBuilder> newChildren = new HashSet<>();
-        for (DataSchemaNode child : usesNode.getGroupingDefinition().getChildNodes()) {
-            if (child != null) {
-                DataSchemaNodeBuilder newChild = null;
-                QName newQName = new QName(namespace, revision, prefix, child.getQName().getLocalName());
-                if (child instanceof AnyXmlSchemaNode) {
-                    newChild = CopyUtils.createAnyXml((AnyXmlSchemaNode) child, newQName, moduleName, line);
-                } else if (child instanceof ChoiceNode) {
-                    newChild = CopyUtils.createChoice((ChoiceNode) child, newQName, moduleName, line);
-                } else if (child instanceof ContainerSchemaNode) {
-                    newChild = CopyUtils.createContainer((ContainerSchemaNode) child, newQName, moduleName, line);
-                } else if (child instanceof LeafListSchemaNode) {
-                    newChild = CopyUtils.createLeafList((LeafListSchemaNode) child, newQName, moduleName, line);
-                } else if (child instanceof LeafSchemaNode) {
-                    newChild = CopyUtils.createLeafBuilder((LeafSchemaNode) child, newQName, moduleName, line);
-                } else if (child instanceof ListSchemaNode) {
-                    newChild = CopyUtils.createList((ListSchemaNode) child, newQName, moduleName, line);
-                }
-
-                if (newChild == null) {
-                    throw new YangParseException(moduleName, line,
-                            "Unknown member of target grouping while resolving uses node.");
-                }
-                if (newChild instanceof GroupingMember) {
-                    ((GroupingMember) newChild).setAddedByUses(true);
-                }
-
-                newChildren.add(newChild);
-            }
-        }
-        usesNode.setTargetChildren(newChildren);
+        copyGroupingNodesToUsesNode(usesNode, namespace, revision, prefix, moduleName, line);
 
         // groupings
         final Set<GroupingBuilder> newGroupings = new HashSet<>();
@@ -394,9 +364,63 @@ public class GroupingUtils {
         usesNode.setDataCollected(true);
     }
 
+    /**
+     * Read data defined in target grouping definition, make a copy and add them
+     * to uses node builder.
+     * 
+     * @param usesNode
+     *            used node builder to which are copied nodes from its
+     *            <code>GroupingDefinition</code>
+     * @param namespace
+     *            URI with parent namespace
+     * @param revision
+     *            date with parent revision date
+     * @param prefix
+     *            string with parent prefix
+     * @param moduleName
+     *            string with parent module name
+     * @param lineNumber
+     *            number with YANG file row where is the parent defined
+     */
+    private static void copyGroupingNodesToUsesNode(final UsesNodeBuilder usesNode, final URI namespace,
+            final Date revision, final String prefix, final String moduleName, final int lineNumber) {
+        final Set<DataSchemaNodeBuilder> newChildren = new HashSet<>();
+        for (DataSchemaNode child : usesNode.getGroupingDefinition().getChildNodes()) {
+            if (child != null) {
+                DataSchemaNodeBuilder newChild = null;
+                QName newQName = new QName(namespace, revision, prefix, child.getQName().getLocalName());
+                if (child instanceof AnyXmlSchemaNode) {
+                    newChild = CopyUtils.createAnyXml((AnyXmlSchemaNode) child, newQName, moduleName, lineNumber);
+                } else if (child instanceof ChoiceNode) {
+                    newChild = CopyUtils.createChoice((ChoiceNode) child, newQName, moduleName, lineNumber);
+                } else if (child instanceof ContainerSchemaNode) {
+                    newChild = CopyUtils.createContainer((ContainerSchemaNode) child, newQName, moduleName, lineNumber);
+                } else if (child instanceof LeafListSchemaNode) {
+                    newChild = CopyUtils.createLeafList((LeafListSchemaNode) child, newQName, moduleName, lineNumber);
+                } else if (child instanceof LeafSchemaNode) {
+                    newChild = CopyUtils.createLeafBuilder((LeafSchemaNode) child, newQName, moduleName, lineNumber);
+                } else if (child instanceof ListSchemaNode) {
+                    newChild = CopyUtils.createList((ListSchemaNode) child, newQName, moduleName, lineNumber);
+                }
+
+                if (newChild == null) {
+                    throw new YangParseException(moduleName, lineNumber,
+                            "Unknown member of target grouping while resolving uses node.");
+                }
+                if (newChild instanceof GroupingMember) {
+                    ((GroupingMember) newChild).setAddedByUses(true);
+                }
+
+                newChildren.add(newChild);
+            }
+        }
+        usesNode.setTargetChildren(newChildren);
+
+    }
+
     /**
      * Fix schema path of all nodes which were defined by this usesNode.
-     *
+     * 
      * @param usesNode
      */
     public static void fixUsesNodesPath(UsesNodeBuilder usesNode) {
@@ -443,7 +467,7 @@ public class GroupingUtils {
     /**
      * Perform refinement of uses target grouping nodes. Uses process has to be
      * already performed.
-     *
+     * 
      * @param usesNode
      */
     public static void performRefine(UsesNodeBuilder usesNode) {
index 4f4c26a60426e17d8ab381c47af1ab9e6f194532..a377eb5548f0ebc097c83ddae0745d9cc155391c 100644 (file)
@@ -40,11 +40,17 @@ import com.google.common.collect.Sets;
 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 Logger LOGGER = LoggerFactory.getLogger(ModuleDependencySort.class);
+
+    /**
+     * It is not desirable to instance this class
+     */
+    private ModuleDependencySort() {
+    }
 
     /**
      * Topological sort of module builder dependency graph.
-     *
+     * 
      * @return Sorted list of Module builders. Modules can be further processed
      *         in returned order.
      */
@@ -82,7 +88,7 @@ public final class ModuleDependencySort {
 
     /**
      * Topological sort of module dependency graph.
-     *
+     * 
      * @return Sorted list of Modules. Modules can be further processed in
      *         returned order.
      */
@@ -146,8 +152,9 @@ public final class ModuleDependencySort {
             // no need to check if other Type of object, check is performed in
             // process modules
 
-            if (fromRevision == null)
+            if (fromRevision == null) {
                 fromRevision = DEFAULT_REVISION;
+            }
 
             for (ModuleImport imprt : imports) {
                 String toName = imprt.getModuleName();
@@ -161,12 +168,10 @@ public final class ModuleDependencySort {
                  * Check imports: If module is imported twice with different
                  * revisions then throw exception
                  */
-                if (imported.get(toName) != null && !imported.get(toName).equals(toRevision)) {
-                    if (!imported.get(toName).equals(DEFAULT_REVISION) && !toRevision.equals(DEFAULT_REVISION)) {
-                        ex(String.format("Module:%s imported twice with different revisions:%s, %s", toName,
-                                formatRevDate(imported.get(toName)), formatRevDate(toRevision)));
-                    }
-
+                if (imported.get(toName) != null && !imported.get(toName).equals(toRevision)
+                        && !imported.get(toName).equals(DEFAULT_REVISION) && !toRevision.equals(DEFAULT_REVISION)) {
+                    ex(String.format("Module:%s imported twice with different revisions:%s, %s", toName,
+                            formatRevDate(imported.get(toName)), formatRevDate(toRevision)));
                 }
 
                 imported.put(toName, toRevision);
@@ -189,13 +194,14 @@ public final class ModuleDependencySort {
             if (moduleGraph.get(toName) != null && !moduleGraph.get(toName).isEmpty()
                     && toRevision.equals(DEFAULT_REVISION)) {
                 to = moduleGraph.get(toName).values().iterator().next();
-                logger.warn(String
+                LOGGER.warn(String
                         .format("Import:%s:%s by module:%s:%s does not specify revision, using:%s:%s for module dependency sort",
                                 toName, formatRevDate(toRevision), fromName, formatRevDate(fromRevision), to.getName(),
                                 formatRevDate(to.getRevision())));
-            } else
+            } else {
                 ex(String.format("Not existing module imported:%s:%s by:%s:%s", toName, formatRevDate(toRevision),
                         fromName, formatRevDate(fromRevision)));
+            }
         } else {
             to = moduleGraph.get(toName).get(toRevision);
         }
@@ -230,21 +236,24 @@ public final class ModuleDependencySort {
                         ModuleBuilder.class, mb.getClass()));
             }
 
-            if (rev == null)
+            if (rev == null) {
                 rev = DEFAULT_REVISION;
+            }
 
-            if (moduleGraph.get(name) == null)
+            if (moduleGraph.get(name) == null) {
                 moduleGraph.put(name, Maps.<Date, ModuleNodeImpl> newHashMap());
+            }
 
-            if (moduleGraph.get(name).get(rev) != null)
+            if (moduleGraph.get(name).get(rev) != null) {
                 ex(String.format("Module:%s with revision:%s declared twice", name, formatRevDate(rev)));
+            }
 
             moduleGraph.get(name).put(rev, new ModuleNodeImpl(name, rev, mb));
         }
     }
 
     private static String formatRevDate(Date rev) {
-        return rev == DEFAULT_REVISION ? "default" : YangParserListenerImpl.simpleDateFormat.format(rev);
+        return rev.equals(DEFAULT_REVISION) ? "default" : YangParserListenerImpl.SIMPLE_DATE_FORMAT.format(rev);
     }
 
     @VisibleForTesting
@@ -278,23 +287,30 @@ public final class ModuleDependencySort {
 
         @Override
         public boolean equals(Object obj) {
-            if (this == obj)
+            if (this == obj) {
                 return true;
-            if (obj == null)
+            }
+            if (obj == null) {
                 return false;
-            if (getClass() != obj.getClass())
+            }
+            if (getClass() != obj.getClass()) {
                 return false;
+            }
             ModuleNodeImpl other = (ModuleNodeImpl) obj;
             if (name == null) {
-                if (other.name != null)
+                if (other.name != null) {
                     return false;
-            } else if (!name.equals(other.name))
+                }
+            } else if (!name.equals(other.name)) {
                 return false;
+            }
             if (revision == null) {
-                if (other.revision != null)
+                if (other.revision != null) {
                     return false;
-            } else if (!revision.equals(other.revision))
+                }
+            } else if (!revision.equals(other.revision)) {
                 return false;
+            }
             return true;
         }
 
index 27b28a40becc2486f195742939ff3d2c0631d78f..45d46c69bb9b3cee186496e47f705ef9f2fe6c71 100644 (file)
@@ -127,7 +127,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given tree and get first string value.
-     *
+     * 
      * @param treeNode
      *            tree to parse
      * @return first string value from given tree
@@ -148,7 +148,7 @@ public final class ParserListenerUtils {
     /**
      * Parse 'description', 'reference' and 'status' statements and fill in
      * given builder.
-     *
+     * 
      * @param ctx
      *            context to parse
      * @param builder
@@ -172,7 +172,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given context and return its value;
-     *
+     * 
      * @param ctx
      *            status context
      * @return value parsed from context
@@ -199,7 +199,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given tree and returns units statement as string.
-     *
+     * 
      * @param ctx
      *            context to parse
      * @return value of units statement as string or null if there is no units
@@ -219,7 +219,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given tree and returns default statement as string.
-     *
+     * 
      * @param ctx
      *            context to parse
      * @return value of default statement as string or null if there is no
@@ -239,7 +239,7 @@ public final class ParserListenerUtils {
 
     /**
      * Create SchemaPath from actualPath and new node name.
-     *
+     * 
      * @param actualPath
      *            current position in model
      * @return SchemaPath object
@@ -252,7 +252,7 @@ public final class ParserListenerUtils {
     /**
      * Create java.util.List of QName objects from given key definition as
      * string.
-     *
+     * 
      * @param keyDefinition
      *            key definition as string
      * @param namespace
@@ -280,7 +280,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given type body of enumeration statement.
-     *
+     * 
      * @param ctx
      *            type body context to parse
      * @param path
@@ -314,7 +314,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse enum statement context
-     *
+     * 
      * @param ctx
      *            enum statement context
      * @param highestValue
@@ -491,7 +491,7 @@ public final class ParserListenerUtils {
 
     /**
      * Get and parse range from given type body context.
-     *
+     * 
      * @param ctx
      *            type body context to parse
      * @param moduleName
@@ -516,7 +516,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given range context.
-     *
+     * 
      * @param ctx
      *            range context to parse
      * @param moduleName
@@ -559,7 +559,7 @@ public final class ParserListenerUtils {
 
     /**
      * Get and parse length from given type body context.
-     *
+     * 
      * @param ctx
      *            type body context to parse
      * @param moduleName
@@ -584,7 +584,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given length context.
-     *
+     * 
      * @param ctx
      *            length context to parse
      * @param moduleName
@@ -628,8 +628,10 @@ public final class ParserListenerUtils {
     /**
      * @param value
      *            value to parse
-     * @param moduleName name of current module
-     * @param line current line in module
+     * @param moduleName
+     *            name of current module
+     * @param line
+     *            current line in module
      * @return wrapper object of primitive java type or UnknownBoundaryNumber if
      *         type is one of special YANG values 'min' or 'max'
      */
@@ -649,7 +651,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse type body and return pattern constraints.
-     *
+     * 
      * @param ctx
      *            type body
      * @return list of pattern constraints
@@ -673,7 +675,7 @@ public final class ParserListenerUtils {
 
     /**
      * Internal helper method.
-     *
+     * 
      * @param ctx
      *            pattern context
      * @return PatternConstraint object
@@ -695,7 +697,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given context and return pattern value.
-     *
+     * 
      * @param ctx
      *            context to parse
      * @return pattern value as String
@@ -718,7 +720,7 @@ public final class ParserListenerUtils {
 
     /**
      * Get fraction digits value from type body.
-     *
+     * 
      * @param ctx
      *            type body context to parse
      * @param moduleName
@@ -739,7 +741,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse decimal64 fraction-digits value.
-     *
+     * 
      * @param ctx
      *            decimal64 context
      * @param moduleName
@@ -766,7 +768,7 @@ public final class ParserListenerUtils {
     /**
      * Internal helper method for parsing bit statements from given type body
      * context.
-     *
+     * 
      * @param ctx
      *            type body context to parse
      * @param actualPath
@@ -799,7 +801,7 @@ public final class ParserListenerUtils {
 
     /**
      * Internal helper method for parsing bit context.
-     *
+     * 
      * @param ctx
      *            bit statement context to parse
      * @param highestPosition
@@ -850,11 +852,11 @@ public final class ParserListenerUtils {
 
     /**
      * Parse 'ordered-by' statement.
-     *
+     * 
      * The 'ordered-by' statement defines whether the order of entries within a
      * list are determined by the user or the system. The argument is one of the
      * strings "system" or "user". If not present, order defaults to "system".
-     *
+     * 
      * @param ctx
      *            Ordered_by_stmtContext
      * @return true, if ordered-by contains value 'user', false otherwise
@@ -880,7 +882,7 @@ public final class ParserListenerUtils {
     /**
      * Get config statement from given context. If there is no config statement,
      * return config value of parent
-     *
+     * 
      * @param ctx
      *            context to parse
      * @param parent
@@ -944,7 +946,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse config statement.
-     *
+     * 
      * @param ctx
      *            config context to parse
      * @param moduleName
@@ -976,7 +978,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse type body and create UnknownType definition.
-     *
+     * 
      * @param typedefQName
      *            qname of current type
      * @param ctx
@@ -1033,7 +1035,7 @@ public final class ParserListenerUtils {
 
     /**
      * Create TypeDefinition object based on given type name and type body.
-     *
+     * 
      * @param typeName
      *            name of type
      * @param typeBody
@@ -1196,7 +1198,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given context and find identityref base value.
-     *
+     * 
      * @param ctx
      *            type body
      * @return identityref base value as String
@@ -1220,7 +1222,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse type body statement and find require-instance value.
-     *
+     * 
      * @param ctx
      *            type body context
      * @return require-instance value
@@ -1247,7 +1249,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse type body statement and find leafref path.
-     *
+     * 
      * @param ctx
      *            type body context
      * @return leafref path as String
@@ -1269,7 +1271,7 @@ public final class ParserListenerUtils {
 
     /**
      * Internal helper method for parsing must statement.
-     *
+     * 
      * @param ctx
      *            Must_stmtContext
      * @return MustDefinition object based on parsed context
@@ -1318,7 +1320,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given context and set constraints to constraints builder.
-     *
+     * 
      * @param ctx
      *            context to parse
      * @param constraints
@@ -1388,7 +1390,7 @@ public final class ParserListenerUtils {
 
     /**
      * Parse given context and return yin value.
-     *
+     * 
      * @param ctx
      *            context to parse
      * @return true if value is 'true', false otherwise
@@ -1415,7 +1417,7 @@ public final class ParserListenerUtils {
 
     /**
      * Check this base type.
-     *
+     * 
      * @param typeName
      *            base YANG type name
      * @param moduleName
@@ -1426,8 +1428,7 @@ public final class ParserListenerUtils {
      *             if this is one of YANG type which MUST contain additional
      *             informations in its body
      */
-    public static void checkMissingBody(final String typeName, final String moduleName, final int line)
-            throws YangParseException {
+    public static void checkMissingBody(final String typeName, final String moduleName, final int line) {
         if ("decimal64".equals(typeName)) {
             throw new YangParseException(moduleName, line,
                     "The 'fraction-digits' statement MUST be present if the type is 'decimal64'.");
@@ -1447,10 +1448,11 @@ public final class ParserListenerUtils {
 
     /**
      * Parse refine statement.
-     *
+     * 
      * @param refineCtx
      *            refine statement
-     * @param moduleName name of current module
+     * @param moduleName
+     *            name of current module
      * @return RefineHolder object representing this refine statement
      */
     public static RefineHolder parseRefine(Refine_stmtContext refineCtx, String moduleName) {
index 7f462920ca8f71f6b8cae746a7cb55f0354eac74..40d47dddd7c6d3fa1cb072b13e859bf7d4a720cb 100644 (file)
@@ -129,73 +129,100 @@ public final class RefineHolder extends AbstractBuilder {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         RefineHolder other = (RefineHolder) obj;
         if (addedUnknownNodes == null) {
-            if (other.addedUnknownNodes != null)
+            if (other.addedUnknownNodes != null) {
                 return false;
-        } else if (!addedUnknownNodes.equals(other.addedUnknownNodes))
+            }
+        } else if (!addedUnknownNodes.equals(other.addedUnknownNodes)) {
             return false;
+        }
         if (config == null) {
-            if (other.config != null)
+            if (other.config != null) {
                 return false;
-        } else if (!config.equals(other.config))
+            }
+        } else if (!config.equals(other.config)) {
             return false;
+        }
         if (defaultStr == null) {
-            if (other.defaultStr != null)
+            if (other.defaultStr != null) {
                 return false;
-        } else if (!defaultStr.equals(other.defaultStr))
+            }
+        } else if (!defaultStr.equals(other.defaultStr)) {
             return false;
+        }
         if (description == null) {
-            if (other.description != null)
+            if (other.description != null) {
                 return false;
-        } else if (!description.equals(other.description))
+            }
+        } else if (!description.equals(other.description)) {
             return false;
+        }
         if (mandatory == null) {
-            if (other.mandatory != null)
+            if (other.mandatory != null) {
                 return false;
-        } else if (!mandatory.equals(other.mandatory))
+            }
+        } else if (!mandatory.equals(other.mandatory)) {
             return false;
+        }
         if (maxElements == null) {
-            if (other.maxElements != null)
+            if (other.maxElements != null) {
                 return false;
-        } else if (!maxElements.equals(other.maxElements))
+            }
+        } else if (!maxElements.equals(other.maxElements)) {
             return false;
+        }
         if (minElements == null) {
-            if (other.minElements != null)
+            if (other.minElements != null) {
                 return false;
-        } else if (!minElements.equals(other.minElements))
+            }
+        } else if (!minElements.equals(other.minElements)) {
             return false;
+        }
         if (must == null) {
-            if (other.must != null)
+            if (other.must != null) {
                 return false;
-        } else if (!must.equals(other.must))
+            }
+        } else if (!must.equals(other.must)) {
             return false;
+        }
         if (name == null) {
-            if (other.name != null)
+            if (other.name != null) {
                 return false;
-        } else if (!name.equals(other.name))
+            }
+        } else if (!name.equals(other.name)) {
             return false;
+        }
         if (parent == null) {
-            if (other.parent != null)
+            if (other.parent != null) {
                 return false;
-        } else if (!parent.equals(other.parent))
+            }
+        } else if (!parent.equals(other.parent)) {
             return false;
+        }
         if (presence == null) {
-            if (other.presence != null)
+            if (other.presence != null) {
                 return false;
-        } else if (!presence.equals(other.presence))
+            }
+        } else if (!presence.equals(other.presence)) {
             return false;
+        }
         if (reference == null) {
-            if (other.reference != null)
+            if (other.reference != null) {
                 return false;
-        } else if (!reference.equals(other.reference))
+            }
+        } else if (!reference.equals(other.reference)) {
             return false;
+        }
         return true;
     }
 
index bb41743ef978a8a79b2886ed0e5cc95c133dcbbf..cea5a906f771f27ef9e2a106db793ed17212417c 100644 (file)
@@ -19,9 +19,15 @@ import com.google.common.collect.Sets;
  */
 public final class TopologicalSort {
 
+    /**
+     * It isn't desirable to create instance of this class
+     */
+    private TopologicalSort() {
+    }
+
     /**
      * Topological sort of dependent nodes in acyclic graphs.
-     *
+     * 
      * @return Sorted {@link List} of {@link Node}s. Order: Nodes with no
      *         dependencies starting.
      * @throws IllegalStateException
@@ -54,13 +60,13 @@ public final class TopologicalSort {
     }
 
     private static Set<Node> getDependentNodes(Set<Node> nodes) {
-        Set<Node> S = Sets.newHashSet();
+        Set<Node> dependentNodes = Sets.newHashSet();
         for (Node n : nodes) {
             if (n.getOutEdges().size() == 0) {
-                S.add(n);
+                dependentNodes.add(n);
             }
         }
-        return S;
+        return dependentNodes;
     }
 
     private static void detectCycles(Set<Node> nodes) {
@@ -75,14 +81,13 @@ public final class TopologicalSort {
                 break;
             }
         }
-        Preconditions.checkState(cycle == false,
-                "Cycle detected in graph around node: " + cycledNode);
+        Preconditions.checkState(!cycle, "Cycle detected in graph around node: " + cycledNode);
     }
 
     /**
      * Interface for nodes in graph that can be sorted topologically
      */
-    public static interface Node {
+    public interface Node {
         Set<Edge> getInEdges();
 
         Set<Edge> getOutEdges();
@@ -91,7 +96,7 @@ public final class TopologicalSort {
     /**
      * Interface for edges in graph that can be sorted topologically
      */
-    public static interface Edge {
+    public interface Edge {
         Node getFrom();
 
         Node getTo();
@@ -160,23 +165,30 @@ public final class TopologicalSort {
 
         @Override
         public boolean equals(Object obj) {
-            if (this == obj)
+            if (this == obj) {
                 return true;
-            if (obj == null)
+            }
+            if (obj == null) {
                 return false;
-            if (getClass() != obj.getClass())
+            }
+            if (getClass() != obj.getClass()) {
                 return false;
+            }
             EdgeImpl other = (EdgeImpl) obj;
             if (from == null) {
-                if (other.from != null)
+                if (other.from != null) {
                     return false;
-            } else if (!from.equals(other.from))
+                }
+            } else if (!from.equals(other.from)) {
                 return false;
+            }
             if (to == null) {
-                if (other.to != null)
+                if (other.to != null) {
                     return false;
-            } else if (!to.equals(other.to))
+                }
+            } else if (!to.equals(other.to)) {
                 return false;
+            }
             return true;
         }
     }
index 995493e50a583489efe7b122d333f232707e5421..e3c31966a31b9ee0a6ec32c1145c96f15e2d112e 100644 (file)
@@ -87,24 +87,26 @@ public final class TypeConstraints {
         return resolved;
     }
 
-    private Number resolveMinRange(Number min) {
+    private Number resolveMinRange(final Number min) {
         int i = 1;
-        while (min instanceof UnknownBoundaryNumber) {
+        Number newMin = min;
+        while (newMin instanceof UnknownBoundaryNumber) {
             final List<RangeConstraint> act = ranges.get(i);
-            min = act.get(0).getMin();
+            newMin = act.get(0).getMin();
             i++;
         }
-        return min;
+        return newMin;
     }
 
-    private Number resolveMaxRange(Number max) {
+    private Number resolveMaxRange(final Number max) {
         int i = 1;
-        while (max instanceof UnknownBoundaryNumber) {
+        Number newMax = max;
+        while (newMax instanceof UnknownBoundaryNumber) {
             final List<RangeConstraint> act = ranges.get(i);
-            max = act.get(act.size() - 1).getMax();
+            newMax = act.get(act.size() - 1).getMax();
             i++;
         }
-        return max;
+        return newMax;
     }
 
     public void addRanges(final List<RangeConstraint> ranges) {
@@ -169,24 +171,26 @@ public final class TypeConstraints {
         return resolved;
     }
 
-    private Number resolveMinLength(Number min) {
+    private Number resolveMinLength(final Number min) {
         int i = 1;
-        while (min instanceof UnknownBoundaryNumber) {
+        Number newMin = min;
+        while (newMin instanceof UnknownBoundaryNumber) {
             final List<LengthConstraint> act = lengths.get(i);
-            min = act.get(0).getMin();
+            newMin = act.get(0).getMin();
             i++;
         }
-        return min;
+        return newMin;
     }
 
-    private Number resolveMaxLength(Number max) {
+    private Number resolveMaxLength(final Number max) {
         int i = 1;
-        while (max instanceof UnknownBoundaryNumber) {
+        Number newMax = max;
+        while (newMax instanceof UnknownBoundaryNumber) {
             final List<LengthConstraint> act = lengths.get(i);
-            max = act.get(act.size() - 1).getMax();
+            newMax = act.get(act.size() - 1).getMax();
             i++;
         }
-        return max;
+        return newMax;
     }
 
     public void addLengths(final List<LengthConstraint> lengths) {
@@ -196,7 +200,7 @@ public final class TypeConstraints {
     }
 
     public List<PatternConstraint> getPatterns() {
-        if(patterns.isEmpty()) {
+        if (patterns.isEmpty()) {
             return Collections.emptyList();
         }
         return patterns.get(0);
@@ -223,89 +227,61 @@ public final class TypeConstraints {
     }
 
     private void validateRange() {
+        validateRange(getRange());
+    }
+
+    private void validateRange(List<RangeConstraint> typeRange) {
         if (ranges.size() < 2) {
             return;
         }
-        List<RangeConstraint> typeRange = getRange();
 
         for (RangeConstraint range : typeRange) {
             if (range.getMin() instanceof UnknownBoundaryNumber || range.getMax() instanceof UnknownBoundaryNumber) {
                 throw new YangParseException(moduleName, line, "Unresolved range constraints");
             }
-            final long min = range.getMin().longValue();
-            final long max = range.getMax().longValue();
+            final BigDecimal min = new BigDecimal(range.getMin().toString());
+            final BigDecimal max = new BigDecimal(range.getMax().toString());
 
             List<RangeConstraint> parentRanges = ranges.get(1);
-            boolean check = false;
-            for (RangeConstraint r : parentRanges) {
-                Number parentMinNumber = r.getMin();
-                if (parentMinNumber instanceof UnknownBoundaryNumber) {
-                    parentMinNumber = resolveMinRange(parentMinNumber);
-                }
-                long parentMin = parentMinNumber.longValue();
-
-                Number parentMaxNumber = r.getMax();
-                if (parentMaxNumber instanceof UnknownBoundaryNumber) {
-                    parentMaxNumber = resolveMaxRange(parentMaxNumber);
-                }
-                long parentMax = parentMaxNumber.longValue();
-
-                if (parentMin <= min && parentMax >= max) {
-                    check = true;
-                    break;
-                }
-            }
-            if (!check) {
+            if (!areRangesSubintervalsOfParentRanges(parentRanges, min, max)) {
                 throw new YangParseException(moduleName, line, "Invalid range constraint: <" + min + ", " + max
                         + "> (parent: " + parentRanges + ").");
             }
         }
     }
 
-    private void validateRange(List<RangeConstraint> typeRange) {
-        if (ranges.size() < 2) {
-            return;
-        }
-
-        for (RangeConstraint range : typeRange) {
-            if (range.getMin() instanceof UnknownBoundaryNumber || range.getMax() instanceof UnknownBoundaryNumber) {
-                throw new YangParseException(moduleName, line, "Unresolved range constraints");
+    private boolean areRangesSubintervalsOfParentRanges(List<RangeConstraint> parentRanges, final BigDecimal min,
+            final BigDecimal max) {
+        boolean check = false;
+        for (RangeConstraint r : parentRanges) {
+            Number parentMinNumber = r.getMin();
+            if (parentMinNumber instanceof UnknownBoundaryNumber) {
+                parentMinNumber = resolveMinRange(parentMinNumber);
             }
-            final BigDecimal min = new BigDecimal(range.getMin().toString());
-            final BigDecimal max = new BigDecimal(range.getMax().toString());
+            BigDecimal parentMin = new BigDecimal(parentMinNumber.toString());
 
-            List<RangeConstraint> parentRanges = ranges.get(1);
-            boolean check = false;
-            for (RangeConstraint r : parentRanges) {
-                Number parentMinNumber = r.getMin();
-                if (parentMinNumber instanceof UnknownBoundaryNumber) {
-                    parentMinNumber = resolveMinRange(parentMinNumber);
-                }
-                BigDecimal parentMin = new BigDecimal(parentMinNumber.toString());
-
-                Number parentMaxNumber = r.getMax();
-                if (parentMaxNumber instanceof UnknownBoundaryNumber) {
-                    parentMaxNumber = resolveMaxRange(parentMaxNumber);
-                }
-                BigDecimal parentMax = new BigDecimal(parentMaxNumber.toString());
-
-                if(parentMin.compareTo(min) <=0 && parentMax.compareTo(max) >= 0) {
-                    check = true;
-                    break;
-                }
+            Number parentMaxNumber = r.getMax();
+            if (parentMaxNumber instanceof UnknownBoundaryNumber) {
+                parentMaxNumber = resolveMaxRange(parentMaxNumber);
             }
-            if (!check) {
-                throw new YangParseException(moduleName, line, "Invalid range constraint: <" + min + ", " + max
-                        + "> (parent: " + parentRanges + ").");
+            BigDecimal parentMax = new BigDecimal(parentMaxNumber.toString());
+
+            if (parentMin.compareTo(min) <= 0 && parentMax.compareTo(max) >= 0) {
+                check = true;
+                break;
             }
         }
+        return check;
     }
 
     private void validateLength() {
+        validateLength(getLength());
+    }
+
+    private void validateLength(List<LengthConstraint> typeLength) {
         if (lengths.size() < 2) {
             return;
         }
-        List<LengthConstraint> typeLength = getLength();
 
         for (LengthConstraint length : typeLength) {
             if (length.getMin() instanceof UnknownBoundaryNumber || length.getMax() instanceof UnknownBoundaryNumber) {
@@ -315,69 +291,35 @@ public final class TypeConstraints {
             final long max = length.getMax().longValue();
 
             List<LengthConstraint> parentLengths = lengths.get(1);
-            boolean check = false;
-            for (LengthConstraint lc : parentLengths) {
-                Number parentMinNumber = lc.getMin();
-                if (parentMinNumber instanceof UnknownBoundaryNumber) {
-                    parentMinNumber = resolveMinLength(parentMinNumber);
-                }
-                long parentMin = parentMinNumber.longValue();
-
-                Number parentMaxNumber = lc.getMax();
-                if (parentMaxNumber instanceof UnknownBoundaryNumber) {
-                    parentMaxNumber = resolveMaxLength(parentMaxNumber);
-                }
-                long parentMax = parentMaxNumber.longValue();
-
-                if (parentMin <= min && parentMax >= max) {
-                    check = true;
-                    break;
-                }
-            }
-            if (!check) {
+            if (!areLengthRangesSubintervalsOfParentLengthRanges(parentLengths, min, max)) {
                 throw new YangParseException(moduleName, line, "Invalid length constraint: <" + min + ", " + max
                         + "> (parent: " + parentLengths + ").");
             }
         }
     }
 
-    private void validateLength(List<LengthConstraint> typeLength) {
-        if (lengths.size() < 2) {
-            return;
-        }
-
-        for (LengthConstraint length : typeLength) {
-            if (length.getMin() instanceof UnknownBoundaryNumber || length.getMax() instanceof UnknownBoundaryNumber) {
-                throw new YangParseException(moduleName, line, "Unresolved length constraints");
+    private boolean areLengthRangesSubintervalsOfParentLengthRanges(final List<LengthConstraint> parentLengths,
+            final long min, final long max) {
+        boolean check = false;
+        for (LengthConstraint lc : parentLengths) {
+            Number parentMinNumber = lc.getMin();
+            if (parentMinNumber instanceof UnknownBoundaryNumber) {
+                parentMinNumber = resolveMinLength(parentMinNumber);
             }
-            final long min = length.getMin().longValue();
-            final long max = length.getMax().longValue();
+            long parentMin = parentMinNumber.longValue();
 
-            List<LengthConstraint> parentLengths = lengths.get(1);
-            boolean check = false;
-            for (LengthConstraint lc : parentLengths) {
-                Number parentMinNumber = lc.getMin();
-                if (parentMinNumber instanceof UnknownBoundaryNumber) {
-                    parentMinNumber = resolveMinLength(parentMinNumber);
-                }
-                long parentMin = parentMinNumber.longValue();
-
-                Number parentMaxNumber = lc.getMax();
-                if (parentMaxNumber instanceof UnknownBoundaryNumber) {
-                    parentMaxNumber = resolveMaxLength(parentMaxNumber);
-                }
-                long parentMax = parentMaxNumber.longValue();
-
-                if (parentMin <= min && parentMax >= max) {
-                    check = true;
-                    break;
-                }
+            Number parentMaxNumber = lc.getMax();
+            if (parentMaxNumber instanceof UnknownBoundaryNumber) {
+                parentMaxNumber = resolveMaxLength(parentMaxNumber);
             }
-            if (!check) {
-                throw new YangParseException(moduleName, line, "Invalid length constraint: <" + min + ", " + max
-                        + "> (parent: " + parentLengths + ").");
+            long parentMax = parentMaxNumber.longValue();
+
+            if (parentMin <= min && parentMax >= max) {
+                check = true;
+                break;
             }
         }
+        return check;
     }
 
 }
index 16009fb35e8740dbdcaa3b2dac8b738d05d6a6a5..e4095d462758f2c1d9bff30e70a57743e57d6205 100644 (file)
@@ -40,7 +40,7 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder;
 /**
  * Utility class which contains helper methods for dealing with type operations.
  */
-public class TypeUtils {
+public final class TypeUtils {
 
     private TypeUtils() {
     }
@@ -48,7 +48,7 @@ public class TypeUtils {
     /**
      * Resolve unknown type of node. It is assumed that type of node is either
      * UnknownType or ExtendedType with UnknownType as base type.
-     *
+     * 
      * @param nodeToResolve
      *            node with type to resolve
      * @param modules
@@ -72,7 +72,7 @@ public class TypeUtils {
     /**
      * Resolve unknown type of node. It is assumed that type of node is either
      * UnknownType or ExtendedType with UnknownType as base type.
-     *
+     * 
      * @param nodeToResolve
      *            node with type to resolve
      * @param modules
@@ -221,7 +221,7 @@ public class TypeUtils {
 
     /**
      * Find type definition of type of unresolved node.
-     *
+     * 
      * @param nodeToResolve
      *            node with unresolved type
      * @param dependentModuleBuilder
@@ -261,7 +261,7 @@ public class TypeUtils {
 
     /**
      * Search types for type with given name.
-     *
+     * 
      * @param types
      *            types to search
      * @param name
@@ -279,7 +279,7 @@ public class TypeUtils {
 
     /**
      * Find type by name.
-     *
+     * 
      * @param types
      *            collection of types
      * @param typeName
@@ -298,13 +298,13 @@ public class TypeUtils {
 
     /**
      * Pull restriction from type and add them to constraints.
-     *
+     * 
      * @param type
      *            type from which constraints will be read
      * @param constraints
      *            constraints object to which constraints will be added
      */
-    private static void mergeConstraints(final TypeDefinition<?> type, final TypeConstraints constraints) {
+    private static TypeConstraints mergeConstraints(final TypeDefinition<?> type, final TypeConstraints constraints) {
         if (type instanceof DecimalTypeDefinition) {
             constraints.addRanges(((DecimalTypeDefinition) type).getRangeStatements());
             constraints.addFractionDigits(((DecimalTypeDefinition) type).getFractionDigits());
@@ -315,13 +315,19 @@ public class TypeUtils {
             constraints.addLengths(((StringTypeDefinition) type).getLengthStatements());
         } else if (type instanceof BinaryTypeDefinition) {
             constraints.addLengths(((BinaryTypeDefinition) type).getLengthConstraints());
+        } else if (type instanceof ExtendedType) {
+            constraints.addFractionDigits(((ExtendedType) type).getFractionDigits());
+            constraints.addLengths(((ExtendedType) type).getLengths());
+            constraints.addPatterns(((ExtendedType) type).getPatterns());
+            constraints.addRanges(((ExtendedType) type).getRanges());
         }
+        return constraints;
     }
 
     /**
      * Create new type builder based on old type with new base type. Note: only
      * one of newBaseTypeBuilder or newBaseType can be specified.
-     *
+     * 
      * @param newBaseTypeBuilder
      *            new base type builder or null
      * @param newBaseType
@@ -376,7 +382,7 @@ public class TypeUtils {
 
     /**
      * Pull restrictions from type and add them to constraints.
-     *
+     * 
      * @param typeToResolve
      *            type from which constraints will be read
      * @param constraints
@@ -436,30 +442,17 @@ public class TypeUtils {
                     Module dm = ParserUtils.findModuleFromContext(context, builder, qname.getPrefix(),
                             nodeToResolve.getLine());
                     TypeDefinition<?> t = findTypeByName(dm.getTypeDefinitions(), qname.getLocalName());
-                    if (t instanceof ExtendedType) {
-                        ExtendedType extType = (ExtendedType) t;
-                        constraints.addFractionDigits(extType.getFractionDigits());
-                        constraints.addLengths(extType.getLengths());
-                        constraints.addPatterns(extType.getPatterns());
-                        constraints.addRanges(extType.getRanges());
-                        return constraints;
-                    } else {
-                        mergeConstraints(t, constraints);
-                        return constraints;
-                    }
+                    return mergeConstraints(t, constraints);
+
                 } else {
                     TypeDefinitionBuilder tdb = findTypeDefinitionBuilder(nodeToResolve, dependentModuleBuilder,
                             qname.getLocalName(), builder.getName(), nodeToResolve.getLine());
                     return findConstraintsFromTypeBuilder(tdb, constraints, modules, dependentModuleBuilder, context);
                 }
             } else if (type instanceof ExtendedType) {
-                ExtendedType extType = (ExtendedType) type;
-                constraints.addFractionDigits(extType.getFractionDigits());
-                constraints.addLengths(extType.getLengths());
-                constraints.addPatterns(extType.getPatterns());
-                constraints.addRanges(extType.getRanges());
+                mergeConstraints(type, constraints);
 
-                TypeDefinition<?> base = extType.getBaseType();
+                TypeDefinition<?> base = ((ExtendedType) type).getBaseType();
                 if (base instanceof UnknownType) {
                     ModuleBuilder dependentModule = ParserUtils.findDependentModuleBuilder(modules, builder, base
                             .getQName().getPrefix(), nodeToResolve.getLine());
@@ -468,20 +461,18 @@ public class TypeUtils {
                     return findConstraintsFromTypeBuilder(tdb, constraints, modules, dependentModule, context);
                 } else {
                     // it has to be base yang type
-                    mergeConstraints(type, constraints);
-                    return constraints;
+                    return mergeConstraints(type, constraints);
                 }
             } else {
                 // it is base yang type
-                mergeConstraints(type, constraints);
-                return constraints;
+                return mergeConstraints(type, constraints);
             }
         }
     }
 
     /**
      * Search for type definition builder by name.
-     *
+     * 
      * @param dirtyNodeSchemaPath
      *            schema path of node which contains unresolved type
      * @param dependentModule
index e91ffeadb2e7034b4da98e0da2c8b136ef28b281..38c6c352bd0c1087ec498e02aa4176ad2e9cd0b7 100644 (file)
@@ -95,12 +95,12 @@ final class BasicValidations {
             String exceptionMessage = ValidationUtil.f(
                     "(In (sub)module:%s) %s:%s, invalid date format expected date format is:%s",
                     ValidationUtil.getRootParentName(stmt), ValidationUtil.getSimpleStatementName(stmt.getClass()),
-                    ValidationUtil.getName(stmt), YangParserListenerImpl.simpleDateFormat.format(new Date()));
+                    ValidationUtil.getName(stmt), YangParserListenerImpl.SIMPLE_DATE_FORMAT.format(new Date()));
             ValidationUtil.ex(exceptionMessage);
         }
     }
 
-    static private Pattern identifierPattern = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
+    private static Pattern identifierPattern = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
 
     static void checkIdentifier(ParseTree statement) {
         checkIdentifierInternal(statement, ValidationUtil.getName(statement));
@@ -122,7 +122,7 @@ final class BasicValidations {
         }
     }
 
-    static private Pattern prefixedIdentifierPattern = Pattern.compile("(.+):(.+)");
+    private static Pattern prefixedIdentifierPattern = Pattern.compile("(.+):(.+)");
 
     static void checkPrefixedIdentifier(ParseTree statement) {
         checkPrefixedIdentifierInternal(statement, ValidationUtil.getName(statement));
index 61305f1447bf924b901a7e55eb9f6c4318a34edd..d46f5077805157171c5278e1e0e12601c4ba9626 100644 (file)
@@ -69,8 +69,7 @@ import com.google.common.collect.Sets;
  */
 final class YangModelBasicValidationListener extends YangParserBaseListener {
 
-    private static final Logger logger = LoggerFactory
-            .getLogger(YangModelBasicValidationListener.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(YangModelBasicValidationListener.class);
 
     private final Set<String> uniquePrefixes;
     private final Set<String> uniqueImports;
@@ -99,8 +98,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
 
         BasicValidations.checkIdentifier(ctx);
 
-        BasicValidations.checkPresentChildOfType(ctx,
-                Module_header_stmtsContext.class, true);
+        BasicValidations.checkPresentChildOfType(ctx, Module_header_stmtsContext.class, true);
 
         String moduleName = ValidationUtil.getName(ctx);
         BasicValidations.checkOnlyOneModulePresent(moduleName, globalModuleId);
@@ -121,12 +119,10 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
 
         BasicValidations.checkIdentifier(ctx);
 
-        BasicValidations.checkPresentChildOfType(ctx,
-                Submodule_header_stmtsContext.class, true);
+        BasicValidations.checkPresentChildOfType(ctx, Submodule_header_stmtsContext.class, true);
 
         String submoduleName = ValidationUtil.getName(ctx);
-        BasicValidations.checkOnlyOneModulePresent(submoduleName,
-                globalModuleId);
+        BasicValidations.checkOnlyOneModulePresent(submoduleName, globalModuleId);
         globalModuleId = submoduleName;
 
     }
@@ -139,15 +135,13 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
      */
     @Override
     public void enterSubmodule_header_stmts(Submodule_header_stmtsContext ctx) {
-        BasicValidations.checkPresentChildOfType(ctx,
-                Belongs_to_stmtContext.class, true);
+        BasicValidations.checkPresentChildOfType(ctx, Belongs_to_stmtContext.class, true);
 
         // check Yang version present, if not log
         try {
-            BasicValidations.checkPresentYangVersion(ctx,
-                    ValidationUtil.getRootParentName(ctx));
+            BasicValidations.checkPresentYangVersion(ctx, ValidationUtil.getRootParentName(ctx));
         } catch (Exception e) {
-            logger.debug(e.getMessage());
+            LOGGER.debug(e.getMessage());
         }
     }
 
@@ -162,16 +156,14 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
     public void enterModule_header_stmts(Module_header_stmtsContext ctx) {
         String moduleName = ValidationUtil.getRootParentName(ctx);
 
-        BasicValidations.checkPresentChildOfType(ctx,
-                Namespace_stmtContext.class, true);
-        BasicValidations.checkPresentChildOfType(ctx, Prefix_stmtContext.class,
-                true);
+        BasicValidations.checkPresentChildOfType(ctx, Namespace_stmtContext.class, true);
+        BasicValidations.checkPresentChildOfType(ctx, Prefix_stmtContext.class, true);
 
         // check Yang version present, if not log
         try {
             BasicValidations.checkPresentYangVersion(ctx, moduleName);
         } catch (Exception e) {
-            logger.debug(e.getMessage());
+            LOGGER.debug(e.getMessage());
         }
     }
 
@@ -183,8 +175,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
      */
     @Override
     public void enterRevision_stmt(Revision_stmtContext ctx) {
-        BasicValidations.checkDateFormat(ctx,
-                YangParserListenerImpl.simpleDateFormat);
+        BasicValidations.checkDateFormat(ctx, YangParserListenerImpl.SIMPLE_DATE_FORMAT);
 
     }
 
@@ -199,8 +190,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
     public void enterBelongs_to_stmt(Belongs_to_stmtContext ctx) {
         BasicValidations.checkIdentifier(ctx);
 
-        BasicValidations.checkPresentChildOfType(ctx, Prefix_stmtContext.class,
-                true);
+        BasicValidations.checkPresentChildOfType(ctx, Prefix_stmtContext.class, true);
     }
 
     /**
@@ -217,9 +207,8 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
         try {
             new URI(namespaceName);
         } catch (URISyntaxException e) {
-            ValidationUtil.ex(ValidationUtil.f(
-                    "(In module:%s) Namespace:%s cannot be parsed as URI",
-                    rootParentName, namespaceName));
+            ValidationUtil.ex(ValidationUtil.f("(In module:%s) Namespace:%s cannot be parsed as URI", rootParentName,
+                    namespaceName));
         }
     }
 
@@ -239,8 +228,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
 
         BasicValidations.checkUniquenessInNamespace(ctx, uniqueImports);
 
-        BasicValidations.checkPresentChildOfType(ctx, Prefix_stmtContext.class,
-                true);
+        BasicValidations.checkPresentChildOfType(ctx, Prefix_stmtContext.class, true);
 
     }
 
@@ -252,8 +240,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
      */
     @Override
     public void enterRevision_date_stmt(Revision_date_stmtContext ctx) {
-        BasicValidations.checkDateFormat(ctx,
-                YangParserListenerImpl.simpleDateFormat);
+        BasicValidations.checkDateFormat(ctx, YangParserListenerImpl.SIMPLE_DATE_FORMAT);
     }
 
     /**
@@ -283,11 +270,8 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
         String version = ValidationUtil.getName(ctx);
         String rootParentName = ValidationUtil.getRootParentName(ctx);
         if (!version.equals(BasicValidations.SUPPORTED_YANG_VERSION)) {
-            ValidationUtil
-                    .ex(ValidationUtil
-                            .f("(In (sub)module:%s) Unsupported yang version:%s, supported version:%s",
-                                    rootParentName, version,
-                                    BasicValidations.SUPPORTED_YANG_VERSION));
+            ValidationUtil.ex(ValidationUtil.f("(In (sub)module:%s) Unsupported yang version:%s, supported version:%s",
+                    rootParentName, version, BasicValidations.SUPPORTED_YANG_VERSION));
         }
     }
 
@@ -319,8 +303,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
 
         BasicValidations.checkIdentifier(ctx);
 
-        BasicValidations.checkPresentChildOfType(ctx, Type_stmtContext.class,
-                true);
+        BasicValidations.checkPresentChildOfType(ctx, Type_stmtContext.class, true);
     }
 
     /**
@@ -357,11 +340,9 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
     public void enterLeaf_stmt(Leaf_stmtContext ctx) {
         BasicValidations.checkIdentifier(ctx);
 
-        BasicValidations.checkPresentChildOfType(ctx, Type_stmtContext.class,
-                true);
+        BasicValidations.checkPresentChildOfType(ctx, Type_stmtContext.class, true);
 
-        BasicValidations.checkNotPresentBoth(ctx, Mandatory_stmtContext.class,
-                Default_stmtContext.class);
+        BasicValidations.checkNotPresentBoth(ctx, Mandatory_stmtContext.class, Default_stmtContext.class);
     }
 
     /**
@@ -376,12 +357,10 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
 
         BasicValidations.checkIdentifier(ctx);
 
-        BasicValidations.checkPresentChildOfType(ctx, Type_stmtContext.class,
-                true);
+        BasicValidations.checkPresentChildOfType(ctx, Type_stmtContext.class, true);
     }
 
-    private static final Set<String> permittedOrderByArgs = Sets.newHashSet(
-            "system", "user");
+    private static final Set<String> PERMITTED_ORDER_BY_ARGS = Sets.newHashSet("system", "user");
 
     /**
      * Constraints:
@@ -391,7 +370,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
      */
     @Override
     public void enterOrdered_by_arg(Ordered_by_argContext ctx) {
-        BasicValidations.checkOnlyPermittedValues(ctx, permittedOrderByArgs);
+        BasicValidations.checkOnlyPermittedValues(ctx, PERMITTED_ORDER_BY_ARGS);
     }
 
     /**
@@ -440,8 +419,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
     public void enterChoice_stmt(Choice_stmtContext ctx) {
         BasicValidations.checkIdentifier(ctx);
 
-        BasicValidations.checkNotPresentBoth(ctx, Mandatory_stmtContext.class,
-                Default_stmtContext.class);
+        BasicValidations.checkNotPresentBoth(ctx, Mandatory_stmtContext.class, Default_stmtContext.class);
 
     }
 
@@ -456,8 +434,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
         BasicValidations.checkIdentifier(ctx);
     }
 
-    private static final Set<String> permittedBooleanArgs = Sets.newHashSet(
-            "true", "false");
+    private static final Set<String> PERMITTED_BOOLEAN_ARGS = Sets.newHashSet("true", "false");
 
     /**
      * Constraints:
@@ -467,7 +444,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
      */
     @Override
     public void enterMandatory_arg(Mandatory_argContext ctx) {
-        BasicValidations.checkOnlyPermittedValues(ctx, permittedBooleanArgs);
+        BasicValidations.checkOnlyPermittedValues(ctx, PERMITTED_BOOLEAN_ARGS);
     }
 
     /**
@@ -578,7 +555,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
      */
     @Override
     public void enterYin_element_arg(Yin_element_argContext ctx) {
-        BasicValidations.checkOnlyPermittedValues(ctx, permittedBooleanArgs);
+        BasicValidations.checkOnlyPermittedValues(ctx, PERMITTED_BOOLEAN_ARGS);
     }
 
     /**
@@ -651,11 +628,10 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
      */
     @Override
     public void enterConfig_arg(Config_argContext ctx) {
-        BasicValidations.checkOnlyPermittedValues(ctx, permittedBooleanArgs);
+        BasicValidations.checkOnlyPermittedValues(ctx, PERMITTED_BOOLEAN_ARGS);
     }
 
-    private static final Set<String> permittedStatusArgs = Sets.newHashSet(
-            "current", "deprecated", "obsolete");
+    private static final Set<String> PERMITTED_STATUS_ARGS = Sets.newHashSet("current", "deprecated", "obsolete");
 
     /**
      * Constraints:
@@ -665,7 +641,7 @@ final class YangModelBasicValidationListener extends YangParserBaseListener {
      */
     @Override
     public void enterStatus_arg(Status_argContext ctx) {
-        BasicValidations.checkOnlyPermittedValues(ctx, permittedStatusArgs);
+        BasicValidations.checkOnlyPermittedValues(ctx, PERMITTED_STATUS_ARGS);
     }
 
 }
index 8c78e40580c27bfa9bb7c0a5645487eb6295997c..bcad3caf4e4b7428e64480b95013856c43b1c975 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
 
 /**
  * Exposed basic yang validation.
- *
+ * 
  * Every file is validated using {@link YangModelBasicValidationListener}.
  */
 public final class YangModelBasicValidator {
@@ -37,8 +37,7 @@ public final class YangModelBasicValidator {
                 walker.walk(yangModelParser, trees.get(i));
             } catch (YangValidationException e) {
                 // wrap exception to add information about which file failed
-                throw new YangValidationException(
-                        "Yang validation failed for file" + e);
+                throw new YangValidationException("Yang validation failed for file" + e);
             }
         }
     }
index e238fdcbd4555f5a49726035c1fee981b600495c..b66fb83e92d186742999bb1741faf27f7eed8b84 100644 (file)
@@ -117,7 +117,7 @@ public class YangParserNegativeTest {
                 fail("YangParseException should by thrown");
             }
         } catch (YangParseException e) {
-            String expected = "Error in module 'container' at line 10: Can not add 'container foo': node with same name already declared at line 6";
+            String expected = "Error in module 'container' at line 10: Can not add 'container foo': node with same name 'foo' already declared at line 6.";
             assertEquals(expected, e.getMessage());
         }
     }
@@ -131,7 +131,7 @@ public class YangParserNegativeTest {
                 fail("YangParseException should by thrown");
             }
         } catch (YangParseException e) {
-            String expected = "Error in module 'container-list' at line 10: Can not add 'list foo': node with same name already declared at line 6";
+            String expected = "Error in module 'container-list' at line 10: Can not add 'list foo': node with same name 'foo' already declared at line 6.";
             assertEquals(expected, e.getMessage());
         }
     }
@@ -145,7 +145,7 @@ public class YangParserNegativeTest {
                 fail("YangParseException should by thrown");
             }
         } catch (YangParseException e) {
-            String expected = "Error in module 'container-leaf' at line 10: Can not add 'leaf foo': node with same name already declared at line 6";
+            String expected = "Error in module 'container-leaf' at line 10: Can not add 'leaf foo': node with same name 'foo' already declared at line 6.";
             assertEquals(expected, e.getMessage());
         }
     }
@@ -159,7 +159,7 @@ public class YangParserNegativeTest {
                 fail("YangParseException should by thrown");
             }
         } catch (YangParseException e) {
-            String expected = "Error in module 'typedef' at line 10: typedef with same name 'int-ext' already declared at line 6";
+            String expected = "Error in module 'typedef' at line 10: typedef with same name 'int-ext' already declared at line 6.";
             assertEquals(expected, e.getMessage());
         }
     }
index 5f128f828077f8a6306303ceebef44af5a309569..1c07b0058801f2a2dcbfbb5354b67ebee6d0b527 100644 (file)
@@ -131,8 +131,8 @@ public class ModuleDependencySortTest {
             ModuleDependencySort.sort(builders);
         } catch (YangValidationException e) {
             assertThat(e.getMessage(), containsString("Module:b imported twice with different revisions:"
-                    + YangParserListenerImpl.simpleDateFormat.format(date1) + ", "
-                    + YangParserListenerImpl.simpleDateFormat.format(date2)));
+                    + YangParserListenerImpl.SIMPLE_DATE_FORMAT.format(date1) + ", "
+                    + YangParserListenerImpl.SIMPLE_DATE_FORMAT.format(date2)));
             throw e;
         }
     }
@@ -156,7 +156,7 @@ public class ModuleDependencySortTest {
             ModuleDependencySort.sort(builders);
         } catch (YangValidationException e) {
             assertThat(e.getMessage(), containsString("Module:a with revision:"
-                    + YangParserListenerImpl.simpleDateFormat.format(rev) + " declared twice"));
+                    + YangParserListenerImpl.SIMPLE_DATE_FORMAT.format(rev) + " declared twice"));
             throw e;
         }
     }
index 54000c21f963c578c30a578923d92e47e5df431d..f65fc045843eb93795cf339f6fbd20f63faedc32 100644 (file)
@@ -50,10 +50,8 @@ public class YangModelValidationTest {
 
     @Test
     public void testPrefixes() {
-        Prefix_stmtContext pref = mockStatement(Prefix_stmtContext.class,
-                "unique1");
-        Module_stmtContext module = mockStatement(Module_stmtContext.class,
-                "module1");
+        Prefix_stmtContext pref = mockStatement(Prefix_stmtContext.class, "unique1");
+        Module_stmtContext module = mockStatement(Module_stmtContext.class, "module1");
         addChild(module, pref);
 
         valid.enterPrefix_stmt(pref);
@@ -74,10 +72,8 @@ public class YangModelValidationTest {
     @Test
     public void testNamespace() {
 
-        Namespace_stmtContext namespace = mockStatement(
-                Namespace_stmtContext.class, "http://test.parsing.uri.com");
-        Module_stmtContext module = mockStatement(Module_stmtContext.class,
-                "module1");
+        Namespace_stmtContext namespace = mockStatement(Namespace_stmtContext.class, "http://test.parsing.uri.com");
+        Module_stmtContext module = mockStatement(Module_stmtContext.class, "module1");
         addChild(module, namespace);
 
         valid.enterNamespace_stmt(namespace);
@@ -89,9 +85,7 @@ public class YangModelValidationTest {
         try {
             valid.enterNamespace_stmt(namespace);
         } catch (YangValidationException e) {
-            assertThat(
-                    e.getMessage(),
-                    containsString("Namespace:invalid uri cannot be parsed as URI"));
+            assertThat(e.getMessage(), containsString("Namespace:invalid uri cannot be parsed as URI"));
             return;
         }
 
@@ -101,8 +95,7 @@ public class YangModelValidationTest {
     @Test
     public void testImports() {
         Import_stmtContext impor = mockImport("unique1", "p1");
-        Module_stmtContext mod = mockStatement(Module_stmtContext.class,
-                "module1");
+        Module_stmtContext mod = mockStatement(Module_stmtContext.class, "module1");
         addChild(mod, impor);
 
         valid.enterImport_stmt(impor);
@@ -114,8 +107,7 @@ public class YangModelValidationTest {
         try {
             valid.enterImport_stmt(impor);
         } catch (YangValidationException e) {
-            assertThat(e.getMessage(),
-                    containsString("Import:unique1 not unique"));
+            assertThat(e.getMessage(), containsString("Import:unique1 not unique"));
             return;
         }
 
@@ -125,8 +117,7 @@ public class YangModelValidationTest {
     @Test
     public void testIncludes() {
         Include_stmtContext incl = mockInclude("unique1");
-        Module_stmtContext mod = mockStatement(Module_stmtContext.class,
-                "module1");
+        Module_stmtContext mod = mockStatement(Module_stmtContext.class, "module1");
         addChild(mod, incl);
         valid.enterInclude_stmt(incl);
 
@@ -137,8 +128,7 @@ public class YangModelValidationTest {
         try {
             valid.enterInclude_stmt(incl);
         } catch (YangValidationException e) {
-            assertThat(e.getMessage(),
-                    containsString("Include:unique1 not unique in (sub)module"));
+            assertThat(e.getMessage(), containsString("Include:unique1 not unique in (sub)module"));
             return;
         }
 
@@ -163,8 +153,7 @@ public class YangModelValidationTest {
                 Module_stmtContext module = mock(Module_stmtContext.class);
                 Token token = mock(Token.class);
                 when(module.getStart()).thenReturn(token);
-                BasicValidations.checkIdentifierInternal(
-                        module, id);
+                BasicValidations.checkIdentifierInternal(module, id);
             } catch (YangValidationException e) {
                 thrown++;
             }
@@ -175,10 +164,8 @@ public class YangModelValidationTest {
 
     @Test(expected = YangValidationException.class)
     public void testAugument() {
-        Augment_stmtContext augument = mockStatement(Augment_stmtContext.class,
-                "/a:*abc/a:augument1");
-        Module_stmtContext mod1 = mockStatement(Module_stmtContext.class,
-                "mod1");
+        Augment_stmtContext augument = mockStatement(Augment_stmtContext.class, "/a:*abc/a:augument1");
+        Module_stmtContext mod1 = mockStatement(Module_stmtContext.class, "mod1");
         addChild(mod1, augument);
 
         Token token = mock(Token.class);
@@ -196,12 +183,9 @@ public class YangModelValidationTest {
 
     @Test
     public void testDeviate() {
-        Deviation_stmtContext ctx = mockStatement(Deviation_stmtContext.class,
-                "deviations");
-        Deviate_add_stmtContext add = mockStatement(
-                Deviate_add_stmtContext.class, "add");
-        Deviate_delete_stmtContext del = mockStatement(
-                Deviate_delete_stmtContext.class, "delete");
+        Deviation_stmtContext ctx = mockStatement(Deviation_stmtContext.class, "deviations");
+        Deviate_add_stmtContext add = mockStatement(Deviate_add_stmtContext.class, "add");
+        Deviate_delete_stmtContext del = mockStatement(Deviate_delete_stmtContext.class, "delete");
 
         addChild(ctx, add);
         addChild(ctx, del);
@@ -218,14 +202,11 @@ public class YangModelValidationTest {
 
     @Test(expected = YangValidationException.class)
     public void testStatus() throws Exception {
-        Status_argContext status = mockStatement(Status_argContext.class,
-                "unknown");
+        Status_argContext status = mockStatement(Status_argContext.class, "unknown");
         try {
             valid.enterStatus_arg(status);
         } catch (YangValidationException e) {
-            assertThat(
-                    e.getMessage(),
-                    containsString("illegal value for Status statement, only permitted:"));
+            assertThat(e.getMessage(), containsString("illegal value for Status statement, only permitted:"));
             throw e;
         }
     }
@@ -233,10 +214,8 @@ public class YangModelValidationTest {
     private Import_stmtContext mockImport(String name, String prefixName) {
         Import_stmtContext impor = mockStatement(Import_stmtContext.class, name);
 
-        Prefix_stmtContext prefix = mockStatement(Prefix_stmtContext.class,
-                prefixName);
-        Revision_date_stmtContext revDate = mockStatement(
-                Revision_date_stmtContext.class, getFormattedDate());
+        Prefix_stmtContext prefix = mockStatement(Prefix_stmtContext.class, prefixName);
+        Revision_date_stmtContext revDate = mockStatement(Revision_date_stmtContext.class, getFormattedDate());
 
         addChild(impor, prefix);
         addChild(impor, revDate);
@@ -244,15 +223,13 @@ public class YangModelValidationTest {
     }
 
     static String getFormattedDate() {
-        return YangParserListenerImpl.simpleDateFormat.format(new Date());
+        return YangParserListenerImpl.SIMPLE_DATE_FORMAT.format(new Date());
     }
 
     private Include_stmtContext mockInclude(String name) {
-        Include_stmtContext incl = mockStatement(Include_stmtContext.class,
-                name);
+        Include_stmtContext incl = mockStatement(Include_stmtContext.class, name);
 
-        Revision_date_stmtContext revDate = mockStatement(
-                Revision_date_stmtContext.class, getFormattedDate());
+        Revision_date_stmtContext revDate = mockStatement(Revision_date_stmtContext.class, getFormattedDate());
 
         addChild(incl, revDate);
         return incl;