Added following mapping: 22/522/10
authorJozef Gloncak <jgloncak@cisco.com>
Wed, 26 Jun 2013 09:45:12 +0000 (11:45 +0200)
committerJozef Gloncak <jgloncak@cisco.com>
Fri, 28 Jun 2013 07:20:06 +0000 (09:20 +0200)
from:
- subelement >>PATTERN<< of YANG build-in type string
to:
- constant list string >>PATTERN_CONSTANTS<< which contains list of regular expressions specified in >>PATTENR<<
- member class attribute >>patterns<< which is list of Pattern objects.

Change-Id: I47ec9f4a5cd3e7eef85b78189a3788dd2f9e007f
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
13 files changed:
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/pom.xml
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/yang/types/TypeProviderImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesBitsTest.java [moved from opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneretedTypesBitsTest.java with 67% similarity]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesStringTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/simple-string-demo.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/BindingGeneratorUtil.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/TypeConstants.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AbstractGeneratedType.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/ClassCodeGenerator.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/Constants.java
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/main/java/org/opendaylight/controller/sal/java/api/generator/GeneratorUtil.java
opendaylight/sal/yang-prototype/code-generator/samples/maven-code-gen-sample/src/main/yang/simple-string-demo.yang [new file with mode: 0644]

index 18f29ed416f5cb7326f862c3927bee0b5774e85b..57fbd2c67bce9220d80d66b35d0695598f9e3a34 100644 (file)
        <groupId>junit</groupId>\r
        <artifactId>junit</artifactId>\r
       </dependency>\r
        <groupId>junit</groupId>\r
        <artifactId>junit</artifactId>\r
       </dependency>\r
+      <dependency>\r
+       <groupId>commons-lang</groupId>\r
+       <artifactId>commons-lang</artifactId>\r
+       <version>2.1</version>\r
+      </dependency>\r
   </dependencies>\r
 </project>
\ No newline at end of file
   </dependencies>\r
 </project>
\ No newline at end of file
index 9410ffe1de5dc9825325bfc97b076aa32f079a94..6bb7907a74ab50be2720c4c37fb75ec4f1cd794d 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.controller.sal.binding.yang.types;
 
  */
 package org.opendaylight.controller.sal.binding.yang.types;
 
+import org.apache.commons.lang.StringEscapeUtils;
 import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
 import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
+import org.opendaylight.controller.binding.generator.util.TypeConstants;
 import org.opendaylight.controller.binding.generator.util.Types;
 import org.opendaylight.controller.binding.generator.util.generated.type.builder.EnumerationBuilderImpl;
 import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
 import org.opendaylight.controller.binding.generator.util.Types;
 import org.opendaylight.controller.binding.generator.util.generated.type.builder.EnumerationBuilderImpl;
 import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
@@ -26,6 +28,7 @@ import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition.Bit;
 import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition.EnumPair;
 import org.opendaylight.controller.yang.model.util.ExtendedType;
 
 import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition.EnumPair;
 import org.opendaylight.controller.yang.model.util.ExtendedType;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -456,6 +459,23 @@ public final class TypeProviderImpl implements TypeProvider {
             genTOBuilder.addEqualsIdentity(genPropBuilder);
             genTOBuilder.addHashIdentity(genPropBuilder);
             genTOBuilder.addToStringProperty(genPropBuilder);
             genTOBuilder.addEqualsIdentity(genPropBuilder);
             genTOBuilder.addHashIdentity(genPropBuilder);
             genTOBuilder.addToStringProperty(genPropBuilder);
+            if (javaType == BaseYangTypes.STRING_TYPE) {
+                if (typedef instanceof ExtendedType) {
+                    List<PatternConstraint> patternConstraints = ((ExtendedType) typedef).getPatterns();
+                    List<String> regularExpressions = new ArrayList<String>();
+                    String regEx;
+                    String modifiedRegEx;
+                    for (PatternConstraint ptrnCons : patternConstraints) {
+                        regEx = ptrnCons.getRegularExpression();
+                        modifiedRegEx = StringEscapeUtils.escapeJava(regEx);
+                        regularExpressions.add(modifiedRegEx);
+                    }                   
+                    
+                    genTOBuilder.addConstant(Types.listTypeFor(BaseYangTypes.STRING_TYPE),
+                            TypeConstants.PATTERN_CONSTANT_NAME, regularExpressions);
+                }
+            }            
+            
             return genTOBuilder.toInstance();
         }
         return null;
             return genTOBuilder.toInstance();
         }
         return null;
@@ -596,4 +616,5 @@ public final class TypeProviderImpl implements TypeProvider {
         }
         return genTOBuilder.toInstance();
     }
         }
         return genTOBuilder.toInstance();
     }
+    
 }
 }
@@ -1,5 +1,7 @@
 package org.opendaylight.controller.sal.binding.generator.impl;
 
 package org.opendaylight.controller.sal.binding.generator.impl;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
@@ -20,10 +22,9 @@ import org.opendaylight.controller.yang.model.api.SchemaContext;
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
 
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
 
-public class GeneretedTypesBitsTest {
+public class GeneratedTypesBitsTest {
 
 
-    private SchemaContext resolveSchemaContextFromFiles(
-            final String... yangFiles) {
+    private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
         final YangModelParser parser = new YangParserImpl();
 
         final List<File> inputFiles = new ArrayList<File>();
         final YangModelParser parser = new YangParserImpl();
 
         final List<File> inputFiles = new ArrayList<File>();
@@ -37,8 +38,7 @@ public class GeneretedTypesBitsTest {
 
     @Test
     public void testGeneretedTypesBitsTest() {
 
     @Test
     public void testGeneretedTypesBitsTest() {
-        final String yangTypesPath = getClass().getResource(
-                "/simple-bits-demo.yang").getPath();
+        final String yangTypesPath = getClass().getResource("/simple-bits-demo.yang").getPath();
 
         final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
         assertTrue(context != null);
 
         final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
         assertTrue(context != null);
@@ -65,12 +65,11 @@ public class GeneretedTypesBitsTest {
 
         for (final Type type : genTypes) {
             if (type instanceof GeneratedTransferObject) { // searching for
 
         for (final Type type : genTypes) {
             if (type instanceof GeneratedTransferObject) { // searching for
-                                                            // ByteType
+                                                           // ByteType
                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
                 if (genTO.getName().equals("ByteType")) {
                     byteTypeFound = true;
                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
                 if (genTO.getName().equals("ByteType")) {
                     byteTypeFound = true;
-                    List<GeneratedProperty> genProperties = genTO
-                            .getProperties();
+                    List<GeneratedProperty> genProperties = genTO.getProperties();
                     classPropertiesNumb = genProperties.size();
 
                     genProperties = null;
                     classPropertiesNumb = genProperties.size();
 
                     genProperties = null;
@@ -90,31 +89,26 @@ public class GeneretedTypesBitsTest {
                                                         // interface
                                                         // LeafParameterContainer
                 final GeneratedType genType = (GeneratedType) type;
                                                         // interface
                                                         // LeafParameterContainer
                 final GeneratedType genType = (GeneratedType) type;
-                if (genType.getName().compareTo("LeafParentContainer") == 0) {
+                if (genType.getName().equals("LeafParentContainer")) {
                     leafParentFound = true;
                     // check of methods
                     methodSignaturesList = genType.getMethodDefinitions();
                     if (methodSignaturesList != null) {
                         for (MethodSignature methodSignature : methodSignaturesList) { // loop
                     leafParentFound = true;
                     // check of methods
                     methodSignaturesList = genType.getMethodDefinitions();
                     if (methodSignaturesList != null) {
                         for (MethodSignature methodSignature : methodSignaturesList) { // loop
-                                                                                        // through
-                                                                                        // all
-                                                                                        // methods
-                            if (methodSignature.getName().compareTo(
-                                    "getByteLeaf") == 0) {
+                                                                                       // through
+                                                                                       // all
+                                                                                       // methods
+                            if (methodSignature.getName().equals("getByteLeaf")) {
                                 getByteLeafMethodFound = true;
 
                                 getByteLeafMethodFound = true;
 
-                                nameReturnParamType = methodSignature
-                                        .getReturnType().getName();
-                            } else if (methodSignature.getName().compareTo(
-                                    "setByteLeaf") == 0) {
+                                nameReturnParamType = methodSignature.getReturnType().getName();
+                            } else if (methodSignature.getName().equals("setByteLeaf")) {
                                 setByteLeafMethodFound = true;
 
                                 setByteLeafMethodFound = true;
 
-                                List<Parameter> parameters = methodSignature
-                                        .getParameters();
+                                List<Parameter> parameters = methodSignature.getParameters();
                                 setByteLeafMethodParamNum = parameters.size();
                                 for (Parameter parameter : parameters) {
                                 setByteLeafMethodParamNum = parameters.size();
                                 for (Parameter parameter : parameters) {
-                                    nameMethodeParamType = parameter.getType()
-                                            .getName();
+                                    nameMethodeParamType = parameter.getType().getName();
                                 }
 
                             }
                                 }
 
                             }
@@ -126,33 +120,23 @@ public class GeneretedTypesBitsTest {
 
         }
 
 
         }
 
-        assertTrue("type >ByteType< wasn't in YANG file", byteTypeFound == true);
-
-        assertTrue("Incorrect number of bit properties in class",
-                classPropertiesNumb == 8);
-
-        assertTrue("Incorrect number of properties in toString method",
-                toStringPropertiesNum == 8);
-        assertTrue("Incorrect number of properties in equals method",
-                equalPropertiesNum == 8);
-        assertTrue("Incorrect number of properties in hash method",
-                hashPropertiesNum == 8);
-        assertTrue("LeafParameterContainer container wasn't found",
-                leafParentFound == true);
-
-        assertTrue("No methods were generated", methodSignaturesList != null);
-
-        assertTrue("Method getByteLeaf wasn't generated.",
-                getByteLeafMethodFound == true);
-        assertTrue("Wrong returning parameter type of method getByteLeaf",
-                nameReturnParamType.compareTo("ByteType") == 0);
-
-        assertTrue("Method setByteLeaf wasn't generated.",
-                setByteLeafMethodFound == true);
-        assertTrue("Incorrect number of input parameters for setByteLeaf",
-                setByteLeafMethodParamNum == 1);
-        assertTrue("Wrong input parameter type",
-                nameMethodeParamType.compareTo("ByteType") == 0);
+        assertTrue(byteTypeFound);
+
+        assertEquals(classPropertiesNumb,8);
+
+        assertEquals(toStringPropertiesNum,8);
+        assertEquals(equalPropertiesNum,8);
+        assertEquals(hashPropertiesNum,8);
+        assertTrue(leafParentFound);
+
+        assertNotNull(methodSignaturesList);
+
+        assertTrue(getByteLeafMethodFound);
+        assertEquals(nameReturnParamType,"ByteType");
+
+        assertTrue(setByteLeafMethodFound);
+        assertEquals(setByteLeafMethodParamNum,1);
+        assertEquals(nameMethodeParamType,"ByteType");
 
     }
 
 
     }
 
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesStringTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesStringTest.java
new file mode 100644 (file)
index 0000000..ab290f7
--- /dev/null
@@ -0,0 +1,116 @@
+package org.opendaylight.controller.sal.binding.generator.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.generator.impl.BindingGeneratorImpl;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+public class GeneratedTypesStringTest {
+
+    private final static List<File> testModels = new ArrayList<File>();
+
+    @BeforeClass
+    public static void loadTestResources() {
+        final File listModelFile = new File(GeneratedTypesStringTest.class.getResource("/simple-string-demo.yang")
+                .getPath());
+        testModels.add(listModelFile);
+    }
+
+    @Test
+    public void constantGenerationTest() {
+        final YangModelParser parser = new YangParserImpl();
+        final Set<Module> modules = parser.parseYangModels(testModels);
+        final SchemaContext context = parser.resolveSchemaContext(modules);
+
+        assertNotNull(context);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
+        final List<Type> genTypes = bindingGen.generateTypes(context);
+
+        boolean typedefStringFound = false;
+        boolean constantRegExListFound = false;
+        boolean constantRegExListTypeGeneric = false;
+        boolean constantRegExListTypeContainer = false;
+        boolean noStringInReqExListFound = false;
+        boolean constantRegExListValueOK = false;
+        boolean constantRegExListTypeOneGeneric = false;
+        for (final Type type : genTypes) {
+            if (type instanceof GeneratedTransferObject) {
+                final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
+
+                if (genTO.getName().equals("TypedefString")) {
+                    typedefStringFound = true;
+
+                    List<Constant> constants = genTO.getConstantDefinitions();
+                    for (Constant con : constants) {
+                        if (con.getName().equals("PATTERN_CONSTANTS")) {
+                            constantRegExListFound = true;
+                        } else
+                            break;
+                        ParameterizedType pType;
+                        if (con.getType() instanceof ParameterizedType) {
+                            pType = (ParameterizedType) con.getType();
+                        } else
+                            break;
+
+                        Type[] types;
+                        if (pType.getName().equals("List")) {
+                            constantRegExListTypeContainer = true;
+                            types = pType.getActualTypeArguments();
+                        } else
+                            break;
+
+                        if (types.length == 1) {
+                            constantRegExListTypeOneGeneric = true;
+                        } else
+                            break;
+
+                        if (types[0].getName().equals("String")) {
+                            constantRegExListTypeGeneric = true;
+                        } else
+                            break;
+
+                        if (con.getValue() instanceof List) {
+                            constantRegExListValueOK = true;
+                        } else
+                            break;
+
+                        for (Object obj : (List<?>) con.getValue()) {
+                            if (!(obj instanceof String)) {
+                                noStringInReqExListFound = true;
+                                break;
+                            }
+                        }
+
+                    }
+                }
+            }
+
+        }
+
+        assertTrue("Typedef >>TypedefString<< wasn't found", typedefStringFound);
+        assertTrue("Constant PATTERN_CONSTANTS is missing in TO", constantRegExListFound);
+        assertTrue("Constant PATTERN_CONSTANTS doesn't have correct container type", constantRegExListTypeContainer);
+        assertTrue("Constant PATTERN_CONSTANTS has more than one generic type", constantRegExListTypeOneGeneric);
+        assertTrue("Constant PATTERN_CONSTANTS doesn't have correct generic type", constantRegExListTypeGeneric);
+        assertTrue("Constant PATTERN_CONSTANTS doesn't contain List object", constantRegExListValueOK);
+        assertTrue("In list found other type than String", !noStringInReqExListFound);
+
+    }
+
+}
index cfa74a005f31f12ca157fb0b736f9a0983ca8001..6d50975e8d365a5056d6956c3c572592dfe4b85f 100644 (file)
@@ -28,8 +28,7 @@ import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
 
 public class GeneratedTypesTest {
 
 
 public class GeneratedTypesTest {
 
-    private SchemaContext resolveSchemaContextFromFiles(
-            final String... yangFiles) {
+    private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
         final YangModelParser parser = new YangParserImpl();
 
         final List<File> inputFiles = new ArrayList<File>();
         final YangModelParser parser = new YangParserImpl();
 
         final List<File> inputFiles = new ArrayList<File>();
@@ -43,57 +42,50 @@ public class GeneratedTypesTest {
 
     @Test
     public void testMultipleModulesResolving() {
 
     @Test
     public void testMultipleModulesResolving() {
-        final String topologyPath = getClass().getResource(
-                "/abstract-topology.yang").getPath();
-        final String typesPath = getClass().getResource(
-                "/ietf-inet-types@2010-09-24.yang").getPath();
-        final SchemaContext context = resolveSchemaContextFromFiles(
-                topologyPath, typesPath);
-        assertTrue(context != null);
+        final String topologyPath = getClass().getResource("/abstract-topology.yang").getPath();
+        final String typesPath = getClass().getResource("/ietf-inet-types@2010-09-24.yang").getPath();
+        final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, typesPath);
+        assertNotNull(context);
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
-        assertTrue(genTypes != null);
+        assertNotNull(genTypes);
         assertEquals(29, genTypes.size());
     }
 
     @Test
     public void testLeafrefResolving() {
         assertEquals(29, genTypes.size());
     }
 
     @Test
     public void testLeafrefResolving() {
-        final String topologyPath = getClass().getResource(
-                "/leafref-test-models/abstract-topology@2013-02-08.yang")
+        final String topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang")
                 .getPath();
                 .getPath();
-        final String interfacesPath = getClass().getResource(
-                "/leafref-test-models/ietf-interfaces@2012-11-15.yang")
+        final String interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang")
                 .getPath();
         // final String ifTypePath = getClass().getResource(
         // "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath();
                 .getPath();
         // final String ifTypePath = getClass().getResource(
         // "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath();
-        final String inetTypesPath = getClass().getResource(
-                "/leafref-test-models/ietf-inet-types@2010-09-24.yang")
+        final String inetTypesPath = getClass().getResource("/leafref-test-models/ietf-inet-types@2010-09-24.yang")
                 .getPath();
                 .getPath();
-        final String yangTypesPath = getClass().getResource(
-                "/leafref-test-models/ietf-yang-types@2010-09-24.yang")
+        final String yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang")
                 .getPath();
 
                 .getPath();
 
-        assertTrue(topologyPath != null);
-        assertTrue(interfacesPath != null);
+        assertNotNull(topologyPath);
+        assertNotNull(interfacesPath);
         // assertTrue(ifTypePath != null);
         // assertTrue(ifTypePath != null);
-        assertTrue(inetTypesPath != null);
-        assertTrue(yangTypesPath != null);
+        assertNotNull(inetTypesPath);
+        assertNotNull(yangTypesPath);
 
         // final SchemaContext context = resolveSchemaContextFromFiles(
         // topologyPath, interfacesPath, ifTypePath, inetTypesPath,
         // yangTypesPath);
 
         // final SchemaContext context = resolveSchemaContextFromFiles(
         // topologyPath, interfacesPath, ifTypePath, inetTypesPath,
         // yangTypesPath);
-        final SchemaContext context = resolveSchemaContextFromFiles(
-                topologyPath, interfacesPath, inetTypesPath, yangTypesPath);
-        assertTrue(context != null);
+        final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, inetTypesPath,
+                yangTypesPath);
+        assertNotNull(context);
         assertEquals(4, context.getModules().size());
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertEquals(57, genTypes.size());
         assertEquals(4, context.getModules().size());
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
         assertEquals(57, genTypes.size());
-        assertTrue(genTypes != null);
+        assertNotNull(genTypes);
 
         GeneratedTransferObject gtIfcKey = null;
         GeneratedType gtIfc = null;
 
         GeneratedTransferObject gtIfcKey = null;
         GeneratedType gtIfc = null;
@@ -142,7 +134,7 @@ public class GeneratedTypesTest {
         Type ifcIdPropType = ifcIdProp.getReturnType();
         assertNotNull(ifcIdPropType);
         assertFalse(ifcIdPropType.equals("java.lang.Void"));
         Type ifcIdPropType = ifcIdProp.getReturnType();
         assertNotNull(ifcIdPropType);
         assertFalse(ifcIdPropType.equals("java.lang.Void"));
-        assertTrue(ifcIdPropType.getName().equals("String"));
+        assertEquals(ifcIdPropType.getName(), "String");
 
         // Interface
         final List<MethodSignature> gtIfcMethods = gtIfc.getMethodDefinitions();
 
         // Interface
         final List<MethodSignature> gtIfcMethods = gtIfc.getMethodDefinitions();
@@ -160,17 +152,16 @@ public class GeneratedTypesTest {
         Type getIfcKeyType = getIfcKey.getReturnType();
         assertNotNull(getIfcKeyType);
         assertFalse(getIfcKeyType.equals("java.lang.Void"));
         Type getIfcKeyType = getIfcKey.getReturnType();
         assertNotNull(getIfcKeyType);
         assertFalse(getIfcKeyType.equals("java.lang.Void"));
-        assertTrue(getIfcKeyType.getName().equals("InterfaceKey"));
+        assertEquals(getIfcKeyType.getName(), "InterfaceKey");
 
         assertNotNull(getHigherLayerIf);
         Type getHigherLayerIfType = getHigherLayerIf.getReturnType();
         assertNotNull(getHigherLayerIfType);
         assertFalse(getHigherLayerIfType.equals("java.lang.Void"));
 
         assertNotNull(getHigherLayerIf);
         Type getHigherLayerIfType = getHigherLayerIf.getReturnType();
         assertNotNull(getHigherLayerIfType);
         assertFalse(getHigherLayerIfType.equals("java.lang.Void"));
-        assertTrue(getHigherLayerIfType.getName().equals("List"));
+        assertEquals(getHigherLayerIfType.getName(), "List");
 
         // NetworkLink
 
         // NetworkLink
-        final List<MethodSignature> gtNetworkLinkMethods = gtNetworkLink
-                .getMethodDefinitions();
+        final List<MethodSignature> gtNetworkLinkMethods = gtNetworkLink.getMethodDefinitions();
         assertNotNull(gtNetworkLinkMethods);
         MethodSignature getIfc = null;
         for (MethodSignature method : gtNetworkLinkMethods) {
         assertNotNull(gtNetworkLinkMethods);
         MethodSignature getIfc = null;
         for (MethodSignature method : gtNetworkLinkMethods) {
@@ -182,11 +173,10 @@ public class GeneratedTypesTest {
         Type getIfcType = getIfc.getReturnType();
         assertNotNull(getIfcType);
         assertFalse(getIfcType.equals("java.lang.Void"));
         Type getIfcType = getIfc.getReturnType();
         assertNotNull(getIfcType);
         assertFalse(getIfcType.equals("java.lang.Void"));
-        assertTrue(getIfcType.getName().equals("String"));
+        assertEquals(getIfcType.getName(), "String");
 
         // SourceNode
 
         // SourceNode
-        final List<MethodSignature> gtSourceMethods = gtSource
-                .getMethodDefinitions();
+        final List<MethodSignature> gtSourceMethods = gtSource.getMethodDefinitions();
         assertNotNull(gtSourceMethods);
         MethodSignature getIdSource = null;
         for (MethodSignature method : gtSourceMethods) {
         assertNotNull(gtSourceMethods);
         MethodSignature getIdSource = null;
         for (MethodSignature method : gtSourceMethods) {
@@ -198,11 +188,10 @@ public class GeneratedTypesTest {
         Type getIdType = getIdSource.getReturnType();
         assertNotNull(getIdType);
         assertFalse(getIdType.equals("java.lang.Void"));
         Type getIdType = getIdSource.getReturnType();
         assertNotNull(getIdType);
         assertFalse(getIdType.equals("java.lang.Void"));
-        assertTrue(getIdType.getName().equals("Uri"));
+        assertEquals(getIdType.getName(), "Uri");
 
         // DestinationNode
 
         // DestinationNode
-        final List<MethodSignature> gtDestMethods = gtDest
-                .getMethodDefinitions();
+        final List<MethodSignature> gtDestMethods = gtDest.getMethodDefinitions();
         assertNotNull(gtDestMethods);
         MethodSignature getIdDest = null;
         for (MethodSignature method : gtDestMethods) {
         assertNotNull(gtDestMethods);
         MethodSignature getIdDest = null;
         for (MethodSignature method : gtDestMethods) {
@@ -214,11 +203,10 @@ public class GeneratedTypesTest {
         Type getIdDestType = getIdDest.getReturnType();
         assertNotNull(getIdDestType);
         assertFalse(getIdDestType.equals("java.lang.Void"));
         Type getIdDestType = getIdDest.getReturnType();
         assertNotNull(getIdDestType);
         assertFalse(getIdDestType.equals("java.lang.Void"));
-        assertTrue(getIdDestType.getName().equals("Uri"));
+        assertEquals(getIdDestType.getName(), "Uri");
 
         // Tunnel
 
         // Tunnel
-        final List<MethodSignature> gtTunnelMethods = gtTunnel
-                .getMethodDefinitions();
+        final List<MethodSignature> gtTunnelMethods = gtTunnel.getMethodDefinitions();
         assertNotNull(gtTunnelMethods);
         MethodSignature getTunnelKey = null;
         for (MethodSignature method : gtTunnelMethods) {
         assertNotNull(gtTunnelMethods);
         MethodSignature getTunnelKey = null;
         for (MethodSignature method : gtTunnelMethods) {
@@ -230,11 +218,10 @@ public class GeneratedTypesTest {
         Type getTunnelKeyType = getTunnelKey.getReturnType();
         assertNotNull(getTunnelKeyType);
         assertFalse(getTunnelKeyType.equals("java.lang.Void"));
         Type getTunnelKeyType = getTunnelKey.getReturnType();
         assertNotNull(getTunnelKeyType);
         assertFalse(getTunnelKeyType.equals("java.lang.Void"));
-        assertTrue(getTunnelKeyType.getName().equals("TunnelKey"));
+        assertEquals(getTunnelKeyType.getName(), "TunnelKey");
 
         // TunnelKey
 
         // TunnelKey
-        final List<GeneratedProperty> gtTunnelKeyProps = gtTunnelKey
-                .getProperties();
+        final List<GeneratedProperty> gtTunnelKeyProps = gtTunnelKey.getProperties();
         assertNotNull(gtTunnelKeyProps);
         GeneratedProperty tunnelId = null;
         for (final GeneratedProperty property : gtTunnelKeyProps) {
         assertNotNull(gtTunnelKeyProps);
         GeneratedProperty tunnelId = null;
         for (final GeneratedProperty property : gtTunnelKeyProps) {
@@ -246,20 +233,19 @@ public class GeneratedTypesTest {
         Type tunnelIdType = tunnelId.getReturnType();
         assertNotNull(tunnelIdType);
         assertFalse(tunnelIdType.equals("java.lang.Void"));
         Type tunnelIdType = tunnelId.getReturnType();
         assertNotNull(tunnelIdType);
         assertFalse(tunnelIdType.equals("java.lang.Void"));
-        assertTrue(tunnelIdType.getName().equals("Uri"));
+        assertEquals(tunnelIdType.getName(), "Uri");
     }
 
     @Test
     public void testContainerResolving() {
     }
 
     @Test
     public void testContainerResolving() {
-        final String filePath = getClass().getResource(
-                "/simple-container-demo.yang").getPath();
+        final String filePath = getClass().getResource("/simple-container-demo.yang").getPath();
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
-        assertTrue(context != null);
+        assert (context != null);
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
-        assertTrue(genTypes != null);
+        assertNotNull(genTypes);
         assertEquals(4, genTypes.size());
 
         final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
         assertEquals(4, genTypes.size());
 
         final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
@@ -270,74 +256,117 @@ public class GeneratedTypesTest {
         assertEquals(5, simpleContainer.getMethodDefinitions().size());
         assertEquals(4, nestedContainer.getMethodDefinitions().size());
 
         assertEquals(5, simpleContainer.getMethodDefinitions().size());
         assertEquals(4, nestedContainer.getMethodDefinitions().size());
 
-        int methodsCount = 0;
-        for (final MethodSignature method : simpleContainer
-                .getMethodDefinitions()) {
+        int setFooMethodCounter = 0;
+        int getFooMethodCounter = 0;
+        int getBarMethodCounter = 0;
+        int getNestedContainerCounter = 0;
+
+        String getFooMethodReturnTypeName = "";
+        String setFooMethodInputParamName = "";
+        String setFooMethodInputParamTypeName = "";
+        String getBarMethodReturnTypeName = "";
+        String getNestedContainerReturnTypeName = "";
+        for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
             if (method.getName().equals("getFoo")) {
             if (method.getName().equals("getFoo")) {
-                method.getReturnType().getName().equals("Integer");
-                methodsCount++;
+                getFooMethodCounter++;
+                getFooMethodReturnTypeName = method.getReturnType().getName();
             }
 
             if (method.getName().equals("setFoo")) {
             }
 
             if (method.getName().equals("setFoo")) {
-                methodsCount++;
-                final MethodSignature.Parameter param = method.getParameters()
-                        .get(0);
-                assertEquals("foo", param.getName());
-                assertEquals("Integer", param.getType().getName());
+                setFooMethodCounter++;
+                final MethodSignature.Parameter param = method.getParameters().get(0);
+                setFooMethodInputParamName = param.getName();
+                setFooMethodInputParamTypeName = param.getType().getName();
             }
 
             if (method.getName().equals("getBar")) {
             }
 
             if (method.getName().equals("getBar")) {
-                method.getReturnType().getName().equals("String");
-                methodsCount++;
+                getBarMethodCounter++;
+                getBarMethodReturnTypeName = method.getReturnType().getName();
             }
 
             if (method.getName().equals("getNestedContainer")) {
             }
 
             if (method.getName().equals("getNestedContainer")) {
-                method.getReturnType().getName().equals("NestedContainer");
-                methodsCount++;
+                getNestedContainerCounter++;
+                getNestedContainerReturnTypeName = method.getReturnType().getName();
             }
         }
             }
         }
-        assertEquals(4, methodsCount);
 
 
-        methodsCount = 0;
-        for (final MethodSignature method : nestedContainer
-                .getMethodDefinitions()) {
+        assertEquals(getFooMethodCounter, 1);
+        assertEquals(getFooMethodReturnTypeName, "Integer");
+
+        assertEquals(setFooMethodCounter, 1);
+        assertEquals(setFooMethodInputParamName, "foo");
+        assertEquals(setFooMethodInputParamTypeName, "Integer");
+
+        assertEquals(getBarMethodCounter, 1);
+        assertEquals(getBarMethodReturnTypeName, "String");
+
+        assertEquals(getNestedContainerCounter, 1);
+        assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
+
+        setFooMethodCounter = 0;
+        getFooMethodCounter = 0;
+        getBarMethodCounter = 0;
+        int setBarMethodCounter = 0;
+
+        getFooMethodReturnTypeName = "";
+        setFooMethodInputParamName = "";
+        setFooMethodInputParamTypeName = "";
+        getBarMethodReturnTypeName = "";
+        String setBarMethodInputParamName = "";
+        String setBarMethodInputParamTypeName = "";
+
+        for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
+
             if (method.getName().equals("getFoo")) {
             if (method.getName().equals("getFoo")) {
-                method.getReturnType().getName().equals("Short");
-                methodsCount++;
+                getFooMethodCounter++;
+                getFooMethodReturnTypeName = method.getReturnType().getName();
             }
 
             if (method.getName().equals("setFoo")) {
             }
 
             if (method.getName().equals("setFoo")) {
-                methodsCount++;
-                final MethodSignature.Parameter param = method.getParameters()
-                        .get(0);
-                assertEquals("foo", param.getName());
-                assertEquals("Short", param.getType().getName());
+                setFooMethodCounter++;
+                final MethodSignature.Parameter param = method.getParameters().get(0);
+                setFooMethodInputParamName = param.getName();
+                setFooMethodInputParamTypeName = param.getType().getName();
             }
 
             if (method.getName().equals("getBar")) {
             }
 
             if (method.getName().equals("getBar")) {
-                method.getReturnType().getName().equals("String");
-                methodsCount++;
+                getBarMethodCounter++;
+                getBarMethodReturnTypeName = method.getReturnType().getName();
             }
 
             if (method.getName().equals("setBar")) {
             }
 
             if (method.getName().equals("setBar")) {
-                method.getReturnType().getName().equals("String");
-                methodsCount++;
+                setBarMethodCounter++;
+                final MethodSignature.Parameter param = method.getParameters().get(0);
+                setBarMethodInputParamName = param.getName();
+                setBarMethodInputParamTypeName = param.getType().getName();
             }
         }
             }
         }
-        assertEquals(4, methodsCount);
+
+        assertEquals(1, getFooMethodCounter);
+        assertEquals(getFooMethodReturnTypeName, "Short");
+
+        assertEquals(1, setFooMethodCounter);
+        assertEquals(setFooMethodInputParamName, "foo");
+        assertEquals(setFooMethodInputParamTypeName, "Short");
+
+        assertEquals(1, getBarMethodCounter);
+        assertEquals(getBarMethodReturnTypeName, "String");
+
+        assertEquals(1, setBarMethodCounter);
+        assertEquals(setBarMethodInputParamName, "bar");
+        assertEquals(setBarMethodInputParamTypeName, "String");
     }
 
     @Test
     public void testLeafListResolving() {
     }
 
     @Test
     public void testLeafListResolving() {
-        final String filePath = getClass().getResource(
-                "/simple-leaf-list-demo.yang").getPath();
+        final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath();
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
-        assertTrue(context != null);
+        assertNotNull(context);
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
-        assertTrue(genTypes != null);
+        assertNotNull(genTypes);
         assertEquals(4, genTypes.size());
 
         final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
         assertEquals(4, genTypes.size());
 
         final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
@@ -348,185 +377,270 @@ public class GeneratedTypesTest {
         assertEquals(5, simpleContainer.getMethodDefinitions().size());
         assertEquals(3, nestedContainer.getMethodDefinitions().size());
 
         assertEquals(5, simpleContainer.getMethodDefinitions().size());
         assertEquals(3, nestedContainer.getMethodDefinitions().size());
 
-        int methodsCount = 0;
-        for (final MethodSignature method : simpleContainer
-                .getMethodDefinitions()) {
+        int setFooMethodCounter = 0;
+        int getFooMethodCounter = 0;
+        int getBarMethodCounter = 0;
+        int getNestedContainerCounter = 0;
+
+        String getFooMethodReturnTypeName = "";
+        String setFooMethodInputParamName = "";
+        String setFooMethodInputParamTypeName = "";
+        String getBarMethodReturnTypeName = "";
+        String getNestedContainerReturnTypeName = "";
+        for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
             if (method.getName().equals("getFoo")) {
             if (method.getName().equals("getFoo")) {
-                method.getReturnType().getName().equals("List");
-                methodsCount++;
+                getFooMethodCounter++;
+                getFooMethodReturnTypeName = method.getReturnType().getName();
             }
 
             if (method.getName().equals("setFoo")) {
             }
 
             if (method.getName().equals("setFoo")) {
-                methodsCount++;
-                final MethodSignature.Parameter param = method.getParameters()
-                        .get(0);
-                assertEquals("foo", param.getName());
-                assertEquals("List", param.getType().getName());
+                setFooMethodCounter++;
+                final MethodSignature.Parameter param = method.getParameters().get(0);
+                setFooMethodInputParamName = param.getName();
+                setFooMethodInputParamTypeName = param.getType().getName();
             }
 
             if (method.getName().equals("getBar")) {
             }
 
             if (method.getName().equals("getBar")) {
-                method.getReturnType().getName().equals("String");
-                methodsCount++;
+                getBarMethodCounter++;
+                getBarMethodReturnTypeName = method.getReturnType().getName();
             }
 
             if (method.getName().equals("getNestedContainer")) {
             }
 
             if (method.getName().equals("getNestedContainer")) {
-                method.getReturnType().getName().equals("NestedContainer");
-                methodsCount++;
+                getNestedContainerCounter++;
+                getNestedContainerReturnTypeName = method.getReturnType().getName();
             }
         }
             }
         }
-        assertEquals(4, methodsCount);
 
 
-        methodsCount = 0;
-        for (final MethodSignature method : nestedContainer
-                .getMethodDefinitions()) {
+        assertEquals(1, getFooMethodCounter);
+        assertEquals(getFooMethodReturnTypeName, "List");
+
+        assertEquals(1, setFooMethodCounter);
+        assertEquals(setFooMethodInputParamName, "foo");
+        assertEquals(setFooMethodInputParamTypeName, "List");
+
+        assertEquals(1, getBarMethodCounter);
+        assertEquals(getBarMethodReturnTypeName, "String");
+
+        assertEquals(1, getNestedContainerCounter);
+        assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
+
+        setFooMethodCounter = 0;
+        getFooMethodCounter = 0;
+        getBarMethodCounter = 0;
+
+        getFooMethodReturnTypeName = "";
+        setFooMethodInputParamName = "";
+        setFooMethodInputParamTypeName = "";
+        getBarMethodReturnTypeName = "";
+
+        for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
             if (method.getName().equals("getFoo")) {
             if (method.getName().equals("getFoo")) {
-                method.getReturnType().getName().equals("Short");
-                methodsCount++;
+                getFooMethodCounter++;
+                getFooMethodReturnTypeName = method.getReturnType().getName();
             }
 
             if (method.getName().equals("setFoo")) {
             }
 
             if (method.getName().equals("setFoo")) {
-                methodsCount++;
-                final MethodSignature.Parameter param = method.getParameters()
-                        .get(0);
-                assertEquals("foo", param.getName());
-                assertEquals("Short", param.getType().getName());
+                setFooMethodCounter++;
+                final MethodSignature.Parameter param = method.getParameters().get(0);
+                setFooMethodInputParamName = param.getName();
+                setFooMethodInputParamTypeName = param.getType().getName();
             }
 
             if (method.getName().equals("getBar")) {
             }
 
             if (method.getName().equals("getBar")) {
-                method.getReturnType().getName().equals("List");
-                methodsCount++;
+                getBarMethodCounter++;
+                getBarMethodReturnTypeName = method.getReturnType().getName();
             }
         }
             }
         }
-        assertEquals(3, methodsCount);
+
+        assertEquals(1, getFooMethodCounter);
+        assertEquals(getFooMethodReturnTypeName, "Short");
+
+        assertEquals(1, setFooMethodCounter);
+        assertEquals(setFooMethodInputParamName, "foo");
+        assertEquals(setFooMethodInputParamTypeName, "Short");
+
+        assertEquals(1, getBarMethodCounter);
+        assertEquals(getBarMethodReturnTypeName, "List");
     }
 
     @Test
     public void testListResolving() {
     }
 
     @Test
     public void testListResolving() {
-        final String filePath = getClass()
-                .getResource("/simple-list-demo.yang").getPath();
+        final String filePath = getClass().getResource("/simple-list-demo.yang").getPath();
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
-        assertTrue(context != null);
+        assertNotNull(context);
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
-        assertTrue(genTypes != null);
+        assertNotNull(genTypes);
         assertEquals(6, genTypes.size());
 
         int genTypesCount = 0;
         int genTOsCount = 0;
         assertEquals(6, genTypes.size());
 
         int genTypesCount = 0;
         int genTOsCount = 0;
+
+        int listParentContainerMethodsCount = 0;
+        int simpleListMethodsCount = 0;
+        int listChildContainerMethodsCount = 0;
+        int listKeyClassCount = 0;
+
+        int getSimpleListKeyMethodCount = 0;
+        int getListChildContainerMethodCount = 0;
+        int getFooMethodCount = 0;
+        int setFooMethodCount = 0;
+        int getSimpleLeafListMethodCount = 0;
+        int setSimpleLeafListMethodCount = 0;
+        int getBarMethodCount = 0;
+
+        String getSimpleListKeyMethodReturnTypeName = "";
+        String getListChildContainerMethodReturnTypeName = "";
+
+        int listKeyClassPropertyCount = 0;
+        String listKeyClassPropertyName = "";
+        String listKeyClassPropertyTypeName = "";
+        boolean listKeyClassPropertyReadOnly = false;
+
+        int hashMethodParameterCount = 0;
+        String hashMethodParameterName = "";
+        String hashMethodParameterReturnTypeName = "";
+
+        int equalMethodParameterCount = 0;
+        String equalMethodParameterName = "";
+        String equalMethodParameterReturnTypeName = "";
+
         for (final Type type : genTypes) {
         for (final Type type : genTypes) {
-            if (type instanceof GeneratedType
-                    && !(type instanceof GeneratedTransferObject)) {
+            if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
                 final GeneratedType genType = (GeneratedType) type;
                 if (genType.getName().equals("ListParentContainer")) {
                 final GeneratedType genType = (GeneratedType) type;
                 if (genType.getName().equals("ListParentContainer")) {
-                    assertEquals(2, genType.getMethodDefinitions().size());
+                    listParentContainerMethodsCount = genType.getMethodDefinitions().size();
                     genTypesCount++;
                 } else if (genType.getName().equals("SimpleList")) {
                     genTypesCount++;
                 } else if (genType.getName().equals("SimpleList")) {
-                    assertEquals(8, genType.getMethodDefinitions().size());
-                    final List<MethodSignature> methods = genType
-                            .getMethodDefinitions();
-                    int methodsCount = 0;
+                    simpleListMethodsCount = genType.getMethodDefinitions().size();
+                    final List<MethodSignature> methods = genType.getMethodDefinitions();
                     for (final MethodSignature method : methods) {
                         if (method.getName().equals("getSimpleListKey")) {
                     for (final MethodSignature method : methods) {
                         if (method.getName().equals("getSimpleListKey")) {
-                            assertEquals("SimpleListKey", method
-                                    .getReturnType().getName());
-                            methodsCount++;
-                        } else if (method.getName().equals(
-                                "getListChildContainer")) {
-                            assertEquals("ListChildContainer", method
-                                    .getReturnType().getName());
-                            methodsCount++;
+                            getSimpleListKeyMethodCount++;
+                            getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
+                        } else if (method.getName().equals("getListChildContainer")) {
+                            getListChildContainerMethodCount++;
+                            getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
                         } else if (method.getName().equals("getFoo")) {
                         } else if (method.getName().equals("getFoo")) {
-                            methodsCount++;
+                            getFooMethodCount++;
                         } else if (method.getName().equals("setFoo")) {
                         } else if (method.getName().equals("setFoo")) {
-                            methodsCount++;
+                            setFooMethodCount++;
                         } else if (method.getName().equals("getSimpleLeafList")) {
                         } else if (method.getName().equals("getSimpleLeafList")) {
-                            methodsCount++;
+                            getSimpleLeafListMethodCount++;
                         } else if (method.getName().equals("setSimpleLeafList")) {
                         } else if (method.getName().equals("setSimpleLeafList")) {
-                            methodsCount++;
+                            setSimpleLeafListMethodCount++;
                         } else if (method.getName().equals("getBar")) {
                         } else if (method.getName().equals("getBar")) {
-                            methodsCount++;
+                            getBarMethodCount++;
                         }
                     }
                         }
                     }
-                    assertEquals(7, methodsCount);
                     genTypesCount++;
                 } else if (genType.getName().equals("ListChildContainer")) {
                     genTypesCount++;
                 } else if (genType.getName().equals("ListChildContainer")) {
-                    assertEquals(2, genType.getMethodDefinitions().size());
+                    listChildContainerMethodsCount = genType.getMethodDefinitions().size();
                     genTypesCount++;
                 }
             } else if (type instanceof GeneratedTransferObject) {
                 genTOsCount++;
                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
                     genTypesCount++;
                 }
             } else if (type instanceof GeneratedTransferObject) {
                 genTOsCount++;
                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
-                final List<GeneratedProperty> properties = genTO
-                        .getProperties();
-                final List<GeneratedProperty> hashProps = genTO
-                        .getHashCodeIdentifiers();
-                final List<GeneratedProperty> equalProps = genTO
-                        .getEqualsIdentifiers();
-
-                assertEquals(1, properties.size());
-                assertEquals("ListKey", properties.get(0).getName());
-                assertEquals("Byte", properties.get(0).getReturnType()
-                        .getName());
-                assertEquals(true, properties.get(0).isReadOnly());
-                assertEquals(1, hashProps.size());
-                assertEquals("ListKey", hashProps.get(0).getName());
-                assertEquals("Byte", hashProps.get(0).getReturnType().getName());
-                assertEquals(1, equalProps.size());
-                assertEquals("ListKey", equalProps.get(0).getName());
-                assertEquals("Byte", equalProps.get(0).getReturnType()
-                        .getName());
+                final List<GeneratedProperty> properties = genTO.getProperties();
+                final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
+                final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
+
+                listKeyClassCount++;
+                listKeyClassPropertyCount = properties.size();
+                listKeyClassPropertyName = properties.get(0).getName();
+                listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName();
+                listKeyClassPropertyReadOnly = properties.get(0).isReadOnly();
+
+                hashMethodParameterCount = hashProps.size();
+                hashMethodParameterName = hashProps.get(0).getName();
+                hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();
+
+                equalMethodParameterCount = equalProps.size();
+                equalMethodParameterName = equalProps.get(0).getName();
+                equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();
+
             }
         }
             }
         }
-        assertEquals(3, genTypesCount);
-        assertEquals(1, genTOsCount);
+
+        assertEquals(2, listParentContainerMethodsCount);
+        assertEquals(2, listChildContainerMethodsCount);
+        assertEquals(1, getSimpleListKeyMethodCount);
+        assertEquals(1, listKeyClassCount);
+
+        assertEquals(1, listKeyClassPropertyCount);
+        assertEquals("ListKey", listKeyClassPropertyName);
+        assertEquals("Byte", listKeyClassPropertyTypeName);
+        assertEquals(true, listKeyClassPropertyReadOnly);
+        assertEquals(1, hashMethodParameterCount);
+        assertEquals("ListKey", hashMethodParameterName);
+        assertEquals("Byte", hashMethodParameterReturnTypeName);
+        assertEquals(1, equalMethodParameterCount);
+        assertEquals("ListKey", equalMethodParameterName);
+        assertEquals("Byte", equalMethodParameterReturnTypeName);
+
+        assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);
+
+        assertEquals(1, getListChildContainerMethodCount);
+        assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName);
+        assertEquals(1, getFooMethodCount);
+        assertEquals(1, setFooMethodCount);
+        assertEquals(1, getSimpleLeafListMethodCount);
+        assertEquals(1, setSimpleLeafListMethodCount);
+        assertEquals(1, getBarMethodCount);
+
+        assertEquals(8, simpleListMethodsCount);
     }
 
     @Test
     public void testListCompositeKeyResolving() {
     }
 
     @Test
     public void testListCompositeKeyResolving() {
-        final String filePath = getClass().getResource(
-                "/list-composite-key.yang").getPath();
+        final String filePath = getClass().getResource("/list-composite-key.yang").getPath();
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
 
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
 
-        assertTrue(context != null);
+        assertNotNull(context);
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
-        assertTrue(genTypes != null);
+        assertNotNull(genTypes);
         assertEquals(8, genTypes.size());
 
         int genTypesCount = 0;
         int genTOsCount = 0;
         assertEquals(8, genTypes.size());
 
         int genTypesCount = 0;
         int genTOsCount = 0;
+
+        int compositeKeyListKeyPropertyCount = 0;
+        int compositeKeyListKeyCount = 0;
+        int innerListKeyPropertyCount = 0;
+
         for (final Type type : genTypes) {
         for (final Type type : genTypes) {
-            if (type instanceof GeneratedType
-                    && !(type instanceof GeneratedTransferObject)) {
+            if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
                 genTypesCount++;
             } else if (type instanceof GeneratedTransferObject) {
                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
 
                 if (genTO.getName().equals("CompositeKeyListKey")) {
                 genTypesCount++;
             } else if (type instanceof GeneratedTransferObject) {
                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
 
                 if (genTO.getName().equals("CompositeKeyListKey")) {
-                    final List<GeneratedProperty> properties = genTO
-                            .getProperties();
-                    int propertyCount = 0;
+                    compositeKeyListKeyCount++;
+                    final List<GeneratedProperty> properties = genTO.getProperties();
                     for (final GeneratedProperty prop : properties) {
                         if (prop.getName().equals("Key1")) {
                     for (final GeneratedProperty prop : properties) {
                         if (prop.getName().equals("Key1")) {
-                            propertyCount++;
+                            compositeKeyListKeyPropertyCount++;
                         } else if (prop.getName().equals("Key2")) {
                         } else if (prop.getName().equals("Key2")) {
-                            propertyCount++;
+                            compositeKeyListKeyPropertyCount++;
                         }
                     }
                         }
                     }
-                    assertEquals(2, propertyCount);
                     genTOsCount++;
                 } else if (genTO.getName().equals("InnerListKey")) {
                     genTOsCount++;
                 } else if (genTO.getName().equals("InnerListKey")) {
-                    final List<GeneratedProperty> properties = genTO
-                            .getProperties();
-                    assertEquals(1, properties.size());
+                    final List<GeneratedProperty> properties = genTO.getProperties();
+                    innerListKeyPropertyCount = properties.size();
                     genTOsCount++;
                 }
             }
         }
                     genTOsCount++;
                 }
             }
         }
+        assertEquals(1, compositeKeyListKeyCount);
+        assertEquals(2, compositeKeyListKeyPropertyCount);
+
+        assertEquals(1, innerListKeyPropertyCount);
 
         assertEquals(6, genTypesCount);
         assertEquals(2, genTOsCount);
 
         assertEquals(6, genTypesCount);
         assertEquals(2, genTOsCount);
@@ -534,22 +648,20 @@ public class GeneratedTypesTest {
 
     @Test
     public void testGeneratedTypes() {
 
     @Test
     public void testGeneratedTypes() {
-        final String filePath = getClass().getResource("/demo-topology.yang")
-                .getPath();
+        final String filePath = getClass().getResource("/demo-topology.yang").getPath();
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
         final SchemaContext context = resolveSchemaContextFromFiles(filePath);
-        assertTrue(context != null);
+        assertNotNull(context);
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
 
         final BindingGenerator bindingGen = new BindingGeneratorImpl();
         final List<Type> genTypes = bindingGen.generateTypes(context);
 
-        assertTrue(genTypes != null);
+        assertNotNull(genTypes);
         assertEquals(15, genTypes.size());
 
         int genTypesCount = 0;
         int genTOsCount = 0;
         for (final Type type : genTypes) {
         assertEquals(15, genTypes.size());
 
         int genTypesCount = 0;
         int genTOsCount = 0;
         for (final Type type : genTypes) {
-            if (type instanceof GeneratedType
-                    && !(type instanceof GeneratedTransferObject)) {
+            if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
                 genTypesCount++;
             } else if (type instanceof GeneratedTransferObject) {
                 genTOsCount++;
                 genTypesCount++;
             } else if (type instanceof GeneratedTransferObject) {
                 genTOsCount++;
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/simple-string-demo.yang b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/resources/simple-string-demo.yang
new file mode 100644 (file)
index 0000000..687d2a1
--- /dev/null
@@ -0,0 +1,23 @@
+module simple-string-demo {
+
+    namespace "urn:simple:string:demo";
+    prefix "sbd";
+
+    organization "OPEN DAYLIGHT";
+    contact "http://www.opendaylight.org/";
+
+    revision 2013-06-18 {
+        
+    }
+
+
+    typedef typedef-string {
+        type string {
+            length "40";
+            pattern "[0-9A-F]*";
+            pattern "[B-D]*";
+            pattern "[4-7]*";
+        }
+    }
+
+}
index b37f91fe4474acd8e4d6c5fd8697c80dda753121..a394edd906bc50de5f71d8a09eb54b393b3c42d4 100644 (file)
@@ -159,6 +159,13 @@ public final class BindingGeneratorUtil {
         return validateParameterName(correctStr);
     }
 
         return validateParameterName(correctStr);
     }
 
+    public static String convertToCapitalLetters(final String token) {
+        String convertedStr = token.replace(" ", "_");
+        convertedStr = convertedStr.replace(".", "_");
+        convertedStr = convertedStr.toUpperCase();
+        return convertedStr;
+    }
+
     private static String parseToCamelCase(String token) {
         if (token == null) {
             throw new NullPointerException("Name can not be null");
     private static String parseToCamelCase(String token) {
         if (token == null) {
             throw new NullPointerException("Name can not be null");
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/TypeConstants.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/TypeConstants.java
new file mode 100644 (file)
index 0000000..69443aa
--- /dev/null
@@ -0,0 +1,9 @@
+package org.opendaylight.controller.binding.generator.util;
+
+public final class TypeConstants {
+
+    public static final String PATTERN_CONSTANT_NAME = "PATTERN_CONSTANTS";
+
+    private TypeConstants() {
+    }
+}
index 8c7ee353442d7c2fb6ec221c08100bf3b26fb7c7..214459777292afa44d02ea67c34de9ae363d7317 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.controller.binding.generator.util.generated.type.builder;
 
  */
 package org.opendaylight.controller.binding.generator.util.generated.type.builder;
 
-
 import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
 import org.opendaylight.controller.sal.binding.model.api.*;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
 import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
 import org.opendaylight.controller.sal.binding.model.api.*;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
@@ -28,16 +27,11 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
     private final List<GeneratedType> enclosedTypes;
     private final boolean isAbstract;
 
     private final List<GeneratedType> enclosedTypes;
     private final boolean isAbstract;
 
-    public AbstractGeneratedType(final Type parent, final String packageName,
-                             final String name, final String comment,
-                             final List<AnnotationTypeBuilder> annotationBuilders,
-                             final boolean isAbstract,
-                             final List<Type> implementsTypes,
-                             final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
-                             final List<GeneratedTOBuilder> enclosedGenTOBuilders,
-                             final List<EnumBuilder> enumBuilders,
-                             final List<Constant> constants,
-                             final List<MethodSignatureBuilder> methodBuilders) {
+    public AbstractGeneratedType(final Type parent, final String packageName, final String name, final String comment,
+            final List<AnnotationTypeBuilder> annotationBuilders, final boolean isAbstract,
+            final List<Type> implementsTypes, final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
+            final List<GeneratedTOBuilder> enclosedGenTOBuilders, final List<EnumBuilder> enumBuilders,
+            final List<Constant> constants, final List<MethodSignatureBuilder> methodBuilders) {
         super(packageName, name);
         this.parent = parent;
         this.comment = comment;
         super(packageName, name);
         this.parent = parent;
         this.comment = comment;
@@ -51,7 +45,7 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
     }
 
     private List<GeneratedType> toUnmodifiableEnclosedTypes(final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
     }
 
     private List<GeneratedType> toUnmodifiableEnclosedTypes(final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
-                                                            final List<GeneratedTOBuilder> enclosedGenTOBuilders) {
+            final List<GeneratedTOBuilder> enclosedGenTOBuilders) {
         final List<GeneratedType> enclosedTypes = new ArrayList<>();
         for (final GeneratedTypeBuilder builder : enclosedGenTypeBuilders) {
             if (builder != null) {
         final List<GeneratedType> enclosedTypes = new ArrayList<>();
         for (final GeneratedTypeBuilder builder : enclosedGenTypeBuilders) {
             if (builder != null) {
@@ -67,8 +61,7 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
         return enclosedTypes;
     }
 
         return enclosedTypes;
     }
 
-    protected List<AnnotationType> toUnmodifiableAnnotations(
-            final List<AnnotationTypeBuilder> annotationBuilders) {
+    protected List<AnnotationType> toUnmodifiableAnnotations(final List<AnnotationTypeBuilder> annotationBuilders) {
         final List<AnnotationType> annotations = new ArrayList<>();
         for (final AnnotationTypeBuilder builder : annotationBuilders) {
             annotations.add(builder.toInstance());
         final List<AnnotationType> annotations = new ArrayList<>();
         for (final AnnotationTypeBuilder builder : annotationBuilders) {
             annotations.add(builder.toInstance());
@@ -76,8 +69,7 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
         return Collections.unmodifiableList(annotations);
     }
 
         return Collections.unmodifiableList(annotations);
     }
 
-    protected List<MethodSignature> toUnmodifiableMethods(
-            List<MethodSignatureBuilder> methodBuilders) {
+    protected List<MethodSignature> toUnmodifiableMethods(List<MethodSignatureBuilder> methodBuilders) {
         final List<MethodSignature> methods = new ArrayList<>();
         for (final MethodSignatureBuilder methodBuilder : methodBuilders) {
             methods.add(methodBuilder.toInstance(this));
         final List<MethodSignature> methods = new ArrayList<>();
         for (final MethodSignatureBuilder methodBuilder : methodBuilders) {
             methods.add(methodBuilder.toInstance(this));
@@ -85,8 +77,7 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
         return Collections.unmodifiableList(methods);
     }
 
         return Collections.unmodifiableList(methods);
     }
 
-    protected List<Enumeration> toUnmodifiableEnumerations(
-            List<EnumBuilder> enumBuilders) {
+    protected List<Enumeration> toUnmodifiableEnumerations(List<EnumBuilder> enumBuilders) {
         final List<Enumeration> enums = new ArrayList<>();
         for (final EnumBuilder enumBuilder : enumBuilders) {
             enums.add(enumBuilder.toInstance(this));
         final List<Enumeration> enums = new ArrayList<>();
         for (final EnumBuilder enumBuilder : enumBuilders) {
             enums.add(enumBuilder.toInstance(this));
@@ -111,10 +102,10 @@ abstract class AbstractGeneratedType extends AbstractBaseType implements Generat
 
     @Override
     public boolean isAbstract() {
 
     @Override
     public boolean isAbstract() {
-       return isAbstract;
+        return isAbstract;
     }
 
     }
 
-     @Override
+    @Override
     public List<Type> getImplements() {
         return implementsTypes;
     }
     public List<Type> getImplements() {
         return implementsTypes;
     }
index 877bcfce630113940aadbc238fd2b7700f02911c..b95ac48928b20d410de55ba5093046dd9de08abb 100644 (file)
@@ -16,7 +16,9 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import java.util.List;
 import java.util.Map;
 
+import org.opendaylight.controller.binding.generator.util.TypeConstants;
 import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
 import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
 import org.opendaylight.controller.sal.binding.model.api.Enumeration;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferIdentityObject;
 import org.opendaylight.controller.sal.binding.model.api.Enumeration;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferIdentityObject;
@@ -32,12 +34,13 @@ public final class ClassCodeGenerator implements CodeGenerator {
         final Writer writer = new StringWriter();
 
         if (type instanceof GeneratedTransferObject) {
         final Writer writer = new StringWriter();
 
         if (type instanceof GeneratedTransferObject) {
-            GeneratedTransferObject genTO = (GeneratedTransferObject) type;            
+            GeneratedTransferObject genTO = (GeneratedTransferObject) type;
             imports = GeneratorUtil.createImports(genTO);
             imports = GeneratorUtil.createImports(genTO);
-            
+
             final String currentPkg = genTO.getPackageName();
             final List<GeneratedProperty> fields = genTO.getProperties();
             final List<Enumeration> enums = genTO.getEnumerations();
             final String currentPkg = genTO.getPackageName();
             final List<GeneratedProperty> fields = genTO.getProperties();
             final List<Enumeration> enums = genTO.getEnumerations();
+            final List<Constant> consts = genTO.getConstantDefinitions();
 
             writer.write(GeneratorUtil.createPackageDeclaration(currentPkg));
             writer.write(NL);
 
             writer.write(GeneratorUtil.createPackageDeclaration(currentPkg));
             writer.write(NL);
@@ -48,54 +51,61 @@ public final class ClassCodeGenerator implements CodeGenerator {
             }
             writer.write(NL);
 
             }
             writer.write(NL);
 
-            writer.write(GeneratorUtil.createClassDeclaration(genTO, "",
-                    imports, genTO.isAbstract()));
+            writer.write(GeneratorUtil.createClassDeclaration(genTO, "", imports, genTO.isAbstract()));
             writer.write(NL);
             writer.write(NL);
             writer.write(NL);
             writer.write(NL);
-            
-            if (enums != null) {           
-                       EnumGenerator enumGenerator = new EnumGenerator();
-               for ( Enumeration e : enums ) {                         
-                       writer.write(enumGenerator.generateInnerEnumeration(e, TAB).toString());
-                       writer.write(NL);
-               }
+
+            if (consts != null) {
+                for (Constant con : consts) {
+                    writer.write(GeneratorUtil.createConstant(con, TAB, imports, currentPkg));
+                    writer.write(NL);
+                }
             }
 
             }
 
-            if (fields != null) {
-                for (GeneratedProperty field : fields) {
-                    writer.write(GeneratorUtil.createField(field, TAB, imports,
-                            currentPkg) + NL);
+            if (enums != null) {
+                EnumGenerator enumGenerator = new EnumGenerator();
+                for (Enumeration e : enums) {
+                    writer.write(enumGenerator.generateInnerEnumeration(e, TAB).toString());
+                    writer.write(NL);
+                }
+            }
+
+            boolean memberPatternListCodeRequired = false;
+            memberPatternListCodeRequired = (GeneratorUtil.isConstantInTO(TypeConstants.PATTERN_CONSTANT_NAME, genTO));
+            if (fields != null || memberPatternListCodeRequired) {
+                if (fields != null) {
+                    for (GeneratedProperty field : fields) {
+                        writer.write(GeneratorUtil.createField(field, TAB, imports, currentPkg) + NL);
+                    }
+                }
+                if (memberPatternListCodeRequired) {
+                    writer.write(TAB + PRIVATE + GAP + "List<Pattern>" + GAP + MEMBER_PATTERN_LIST + GAP + ASSIGN + GAP
+                            + "new ArrayList<Pattern>()" + GAP + SC + NL);
+
                 }
                 writer.write(NL);
                 }
                 writer.write(NL);
-                writer.write(GeneratorUtil.createConstructor(genTO, TAB,
-                        imports, genTO.isAbstract()) + NL);
+                writer.write(GeneratorUtil.createConstructor(genTO, TAB, imports, genTO.isAbstract()) + NL);
                 writer.write(NL);
                 writer.write(NL);
-                for (GeneratedProperty field : fields) {
-                    writer.write(GeneratorUtil.createGetter(field, TAB,
-                            imports, currentPkg) + NL);
-                    if (!field.isReadOnly()) {
-                        writer.write(GeneratorUtil.createSetter(field, TAB,
-                                imports, currentPkg) + NL);
+                if (fields != null) {
+                    for (GeneratedProperty field : fields) {
+                        writer.write(GeneratorUtil.createGetter(field, TAB, imports, currentPkg) + NL);
+                        if (!field.isReadOnly()) {
+                            writer.write(GeneratorUtil.createSetter(field, TAB, imports, currentPkg) + NL);
+                        }
                     }
                 }
                 writer.write(NL);
 
                 if (!genTO.getHashCodeIdentifiers().isEmpty()) {
                     }
                 }
                 writer.write(NL);
 
                 if (!genTO.getHashCodeIdentifiers().isEmpty()) {
-                    writer.write(GeneratorUtil.createHashCode(
-                            genTO.getHashCodeIdentifiers(), TAB)
-                            + NL);
+                    writer.write(GeneratorUtil.createHashCode(genTO.getHashCodeIdentifiers(), TAB) + NL);
                 }
 
                 if (!genTO.getEqualsIdentifiers().isEmpty()) {
                 }
 
                 if (!genTO.getEqualsIdentifiers().isEmpty()) {
-                    writer.write(GeneratorUtil.createEquals(genTO,
-                            genTO.getEqualsIdentifiers(), TAB)
-                            + NL);
+                    writer.write(GeneratorUtil.createEquals(genTO, genTO.getEqualsIdentifiers(), TAB) + NL);
                 }
 
                 if (!genTO.getToStringIdentifiers().isEmpty()) {
                 }
 
                 if (!genTO.getToStringIdentifiers().isEmpty()) {
-                    writer.write(GeneratorUtil.createToString(genTO,
-                            genTO.getToStringIdentifiers(), TAB)
-                            + NL);
+                    writer.write(GeneratorUtil.createToString(genTO, genTO.getToStringIdentifiers(), TAB) + NL);
 
                 }
 
 
                 }
 
index e5cb97f1a6e4fb7181a875f5342a40f06a7d7e87..f200538138272a6570babe1b5d4e0c8a2f69c163 100644 (file)
@@ -19,11 +19,16 @@ final class Constants {
     public static final String LB = "(";
     public static final String RB = ")";
 
     public static final String LB = "(";
     public static final String RB = ")";
 
+    public static final String LSB = "[";
+    public static final String RSB = "]";
+
     public static final String GAP = " ";
     public static final String COMMA = ",";
     public static final String NL = "\n";
     public static final String SC = ";";
     public static final String TAB = "    ";
     public static final String GAP = " ";
     public static final String COMMA = ",";
     public static final String NL = "\n";
     public static final String SC = ";";
     public static final String TAB = "    ";
+    public static final String ASSIGN = "=";
+    public static final String DOUBLE_QUOTE = "\"";
 
     public static final String PUBLIC = "public";
     public static final String PRIVATE = "private";
 
     public static final String PUBLIC = "public";
     public static final String PRIVATE = "private";
@@ -33,9 +38,13 @@ final class Constants {
     public static final String FINAL = "final";
     public static final String EXTENDS = "extends";
     public static final String IMPLEMENTS = "implements";
     public static final String FINAL = "final";
     public static final String EXTENDS = "extends";
     public static final String IMPLEMENTS = "implements";
-    
+
     public static final String ENUMERATION_NAME = "value";
     public static final String ENUMERATION_NAME = "value";
-    public static final String ENUMERATION_TYPE = "int";       
-    
-    private Constants() {}
+    public static final String ENUMERATION_TYPE = "int";
+
+    public static final String STRING_PATTERN_LIST = "STRING_PATTERNS";
+    public static final String MEMBER_PATTERN_LIST = "patterns";
+
+    private Constants() {
+    }
 }
 }
index 804ac99ff26138d1e36d18c6dbbd99755fc1b946..16074c7e98ba0b1fac549c2c1fa6c42c67abe71c 100644 (file)
@@ -15,6 +15,8 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import java.util.List;
 import java.util.Map;
 
+import org.opendaylight.controller.binding.generator.util.TypeConstants;
+import org.opendaylight.controller.binding.generator.util.Types;
 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
 import org.opendaylight.controller.sal.binding.model.api.Constant;
 import org.opendaylight.controller.sal.binding.model.api.Enumeration;
 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
 import org.opendaylight.controller.sal.binding.model.api.Constant;
 import org.opendaylight.controller.sal.binding.model.api.Enumeration;
@@ -33,30 +35,22 @@ public final class GeneratorUtil {
     private GeneratorUtil() {
     }
 
     private GeneratorUtil() {
     }
 
-    public static String createIfcDeclaration(final GeneratedType genType,
-            final String indent,
+    public static String createIfcDeclaration(final GeneratedType genType, final String indent,
             final Map<String, LinkedHashMap<String, Integer>> availableImports) {
             final Map<String, LinkedHashMap<String, Integer>> availableImports) {
-        return createFileDeclaration(IFC, genType, indent, availableImports,
-                false);
+        return createFileDeclaration(IFC, genType, indent, availableImports, false);
     }
 
     }
 
-    public static String createClassDeclaration(
-            final GeneratedTransferObject genTransferObject,
-            final String indent,
-            final Map<String, LinkedHashMap<String, Integer>> availableImports,
-            boolean isIdentity) {
-        return createFileDeclaration(CLASS, genTransferObject, indent,
-                availableImports, isIdentity);
+    public static String createClassDeclaration(final GeneratedTransferObject genTransferObject, final String indent,
+            final Map<String, LinkedHashMap<String, Integer>> availableImports, boolean isIdentity) {
+        return createFileDeclaration(CLASS, genTransferObject, indent, availableImports, isIdentity);
     }
 
     public static String createPackageDeclaration(final String packageName) {
         return PKG + GAP + packageName + SC;
     }
 
     }
 
     public static String createPackageDeclaration(final String packageName) {
         return PKG + GAP + packageName + SC;
     }
 
-    private static String createFileDeclaration(final String type,
-            final GeneratedType genType, final String indent,
-            final Map<String, LinkedHashMap<String, Integer>> availableImports,
-            boolean isIdentity) {
+    private static String createFileDeclaration(final String type, final GeneratedType genType, final String indent,
+            final Map<String, LinkedHashMap<String, Integer>> availableImports, boolean isIdentity) {
         final StringBuilder builder = new StringBuilder();
         final String currentPkg = genType.getPackageName();
 
         final StringBuilder builder = new StringBuilder();
         final String currentPkg = genType.getPackageName();
 
@@ -70,11 +64,9 @@ public final class GeneratorUtil {
 
         if (isIdentity) {
             if (!(CLASS.equals(type))) {
 
         if (isIdentity) {
             if (!(CLASS.equals(type))) {
-                throw new IllegalArgumentException(
-                        "'identity' has to be generated as a class");
+                throw new IllegalArgumentException("'identity' has to be generated as a class");
             }
             }
-            builder.append(PUBLIC + GAP + ABSTRACT + GAP + type + GAP
-                    + genType.getName() + GAP);
+            builder.append(PUBLIC + GAP + ABSTRACT + GAP + type + GAP + genType.getName() + GAP);
         } else {
             builder.append(PUBLIC + GAP + type + GAP + genType.getName() + GAP);
         }
         } else {
             builder.append(PUBLIC + GAP + type + GAP + genType.getName() + GAP);
         }
@@ -96,13 +88,11 @@ public final class GeneratorUtil {
             } else {
                 builder.append(EXTENDS + GAP);
             }
             } else {
                 builder.append(EXTENDS + GAP);
             }
-            builder.append(getExplicitType(genImplements.get(0),
-                    availableImports, currentPkg));
+            builder.append(getExplicitType(genImplements.get(0), availableImports, currentPkg));
 
             for (int i = 1; i < genImplements.size(); ++i) {
                 builder.append(", ");
 
             for (int i = 1; i < genImplements.size(); ++i) {
                 builder.append(", ");
-                builder.append(getExplicitType(genImplements.get(i),
-                        availableImports, currentPkg));
+                builder.append(getExplicitType(genImplements.get(i), availableImports, currentPkg));
             }
         }
 
             }
         }
 
@@ -110,8 +100,7 @@ public final class GeneratorUtil {
         return builder.toString();
     }
 
         return builder.toString();
     }
 
-    private static StringBuilder appendAnnotations(final StringBuilder builder,
-            final List<AnnotationType> annotations) {
+    private static StringBuilder appendAnnotations(final StringBuilder builder, final List<AnnotationType> annotations) {
         if ((builder != null) && (annotations != null)) {
             for (final AnnotationType annotation : annotations) {
                 builder.append("@");
         if ((builder != null) && (annotations != null)) {
             for (final AnnotationType annotation : annotations) {
                 builder.append("@");
@@ -121,8 +110,7 @@ public final class GeneratorUtil {
 
                 if (annotation.containsParameters()) {
                     builder.append("(");
 
                 if (annotation.containsParameters()) {
                     builder.append("(");
-                    final List<AnnotationType.Parameter> parameters = annotation
-                            .getParameters();
+                    final List<AnnotationType.Parameter> parameters = annotation.getParameters();
                     appendAnnotationParams(builder, parameters);
                     builder.append(")");
                 }
                     appendAnnotationParams(builder, parameters);
                     builder.append(")");
                 }
@@ -131,8 +119,7 @@ public final class GeneratorUtil {
         return builder;
     }
 
         return builder;
     }
 
-    private static StringBuilder appendAnnotationParams(
-            final StringBuilder builder,
+    private static StringBuilder appendAnnotationParams(final StringBuilder builder,
             final List<AnnotationType.Parameter> parameters) {
         if (parameters != null) {
             int i = 0;
             final List<AnnotationType.Parameter> parameters) {
         if (parameters != null) {
             int i = 0;
@@ -165,23 +152,44 @@ public final class GeneratorUtil {
         return builder;
     }
 
         return builder;
     }
 
-    public static String createConstant(final Constant constant,
-            final String indent,
-            final Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
+    public static String createConstant(final Constant constant, final String indent,
+            final Map<String, LinkedHashMap<String, Integer>> availableImports, final String currentPkg) {
         final StringBuilder builder = new StringBuilder();
         final StringBuilder builder = new StringBuilder();
+        if (constant == null)
+            throw new IllegalArgumentException();
         builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP);
         builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP);
-        builder.append(getExplicitType(constant.getType(), availableImports,
-                currentPkg) + GAP + constant.getName());
+        builder.append(getExplicitType(constant.getType(), availableImports, currentPkg) + GAP + constant.getName());
         builder.append(GAP + "=" + GAP);
         builder.append(GAP + "=" + GAP);
-        builder.append(constant.getValue() + SC);
+        final Object constValue = constant.getValue();
+
+        if (constant.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
+            if (constant.getName() == null || constant.getType() == null || constant.getValue() == null)
+                throw new IllegalArgumentException();
+            if (constValue instanceof List) {
+                builder.append("Arrays.asList" + LB);
+                final List<?> constantValues = (List<?>) constValue;
+                int stringsCount = 0;
+                for (Object value : constantValues) {
+                    if (value instanceof String) {
+                        if (stringsCount > 0) {
+                            builder.append(COMMA);
+                        }
+                        stringsCount++;
+                        builder.append(DOUBLE_QUOTE + (String) value + DOUBLE_QUOTE);
+                    }
+                }
+                builder.append(RB);
+            }
+        } else {
+            builder.append(constant.getValue());
+        }
+        builder.append(SC);
+
         return builder.toString();
     }
 
         return builder.toString();
     }
 
-    public static String createField(final GeneratedProperty property,
-            final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
+    public static String createField(final GeneratedProperty property, final String indent,
+            Map<String, LinkedHashMap<String, Integer>> availableImports, final String currentPkg) {
         final StringBuilder builder = new StringBuilder();
         if (!property.getAnnotations().isEmpty()) {
             final List<AnnotationType> annotations = property.getAnnotations();
         final StringBuilder builder = new StringBuilder();
         if (!property.getAnnotations().isEmpty()) {
             final List<AnnotationType> annotations = property.getAnnotations();
@@ -189,8 +197,8 @@ public final class GeneratorUtil {
             builder.append(NL);
         }
         builder.append(indent + PRIVATE + GAP);
             builder.append(NL);
         }
         builder.append(indent + PRIVATE + GAP);
-        builder.append(getExplicitType(property.getReturnType(),
-                availableImports, currentPkg) + GAP + property.getName());
+        builder.append(getExplicitType(property.getReturnType(), availableImports, currentPkg) + GAP
+                + property.getName());
         builder.append(SC);
         return builder.toString();
     }
         builder.append(SC);
         return builder.toString();
     }
@@ -202,15 +210,12 @@ public final class GeneratorUtil {
      * @param indent
      * @return
      */
      * @param indent
      * @return
      */
-    public static String createMethodDeclaration(final MethodSignature method,
-            final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
+    public static String createMethodDeclaration(final MethodSignature method, final String indent,
+            Map<String, LinkedHashMap<String, Integer>> availableImports, final String currentPkg) {
         final StringBuilder builder = new StringBuilder();
 
         if (method == null) {
         final StringBuilder builder = new StringBuilder();
 
         if (method == null) {
-            throw new IllegalArgumentException(
-                    "Method Signature parameter MUST be specified and cannot be NULL!");
+            throw new IllegalArgumentException("Method Signature parameter MUST be specified and cannot be NULL!");
         }
 
         final String comment = method.getComment();
         }
 
         final String comment = method.getComment();
@@ -221,8 +226,7 @@ public final class GeneratorUtil {
 
         final Type type = method.getReturnType();
         if (type == null) {
 
         final Type type = method.getReturnType();
         if (type == null) {
-            throw new IllegalStateException(
-                    "Method Return type cannot be NULL!");
+            throw new IllegalStateException("Method Return type cannot be NULL!");
         }
 
         final List<Parameter> parameters = method.getParameters();
         }
 
         final List<Parameter> parameters = method.getParameters();
@@ -237,9 +241,7 @@ public final class GeneratorUtil {
             builder.append(NL);
         }
 
             builder.append(NL);
         }
 
-        builder.append(indent
-                + getExplicitType(type, availableImports, currentPkg) + GAP
-                + name);
+        builder.append(indent + getExplicitType(type, availableImports, currentPkg) + GAP + name);
         builder.append(LB);
         for (int i = 0; i < parameters.size(); i++) {
             Parameter p = parameters.get(i);
         builder.append(LB);
         for (int i = 0; i < parameters.size(); i++) {
             Parameter p = parameters.get(i);
@@ -247,8 +249,7 @@ public final class GeneratorUtil {
             if (i + 1 == parameters.size()) {
                 separator = "";
             }
             if (i + 1 == parameters.size()) {
                 separator = "";
             }
-            builder.append(getExplicitType(p.getType(), availableImports,
-                    currentPkg) + GAP + p.getName() + separator);
+            builder.append(getExplicitType(p.getType(), availableImports, currentPkg) + GAP + p.getName() + separator);
         }
         builder.append(RB);
         builder.append(SC);
         }
         builder.append(RB);
         builder.append(SC);
@@ -256,19 +257,18 @@ public final class GeneratorUtil {
         return builder.toString();
     }
 
         return builder.toString();
     }
 
-    public static String createConstructor(
-            GeneratedTransferObject genTransferObject, final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            boolean isIdentity) {
+    public static String createConstructor(GeneratedTransferObject genTransferObject, final String indent,
+            Map<String, LinkedHashMap<String, Integer>> availableImports, boolean isIdentity) {
         final StringBuilder builder = new StringBuilder();
 
         final String currentPkg = genTransferObject.getPackageName();
         final StringBuilder builder = new StringBuilder();
 
         final String currentPkg = genTransferObject.getPackageName();
-        final List<GeneratedProperty> properties = genTransferObject
-                .getProperties();
+        final List<GeneratedProperty> properties = genTransferObject.getProperties();
         final List<GeneratedProperty> ctorParams = new ArrayList<GeneratedProperty>();
         final List<GeneratedProperty> ctorParams = new ArrayList<GeneratedProperty>();
-        for (final GeneratedProperty property : properties) {
-            if (property.isReadOnly()) {
-                ctorParams.add(property);
+        if (properties != null) {
+            for (final GeneratedProperty property : properties) {
+                if (property.isReadOnly()) {
+                    ctorParams.add(property);
+                }
             }
         }
 
             }
         }
 
@@ -279,15 +279,13 @@ public final class GeneratorUtil {
         builder.append(LB);
 
         if (!ctorParams.isEmpty()) {
         builder.append(LB);
 
         if (!ctorParams.isEmpty()) {
-            builder.append(getExplicitType(ctorParams.get(0).getReturnType(),
-                    availableImports, currentPkg));
+            builder.append(getExplicitType(ctorParams.get(0).getReturnType(), availableImports, currentPkg));
             builder.append(" ");
             builder.append(ctorParams.get(0).getName());
             for (int i = 1; i < ctorParams.size(); ++i) {
                 final GeneratedProperty param = ctorParams.get(i);
                 builder.append(", ");
             builder.append(" ");
             builder.append(ctorParams.get(0).getName());
             for (int i = 1; i < ctorParams.size(); ++i) {
                 final GeneratedProperty param = ctorParams.get(i);
                 builder.append(", ");
-                builder.append(getExplicitType(param.getReturnType(),
-                        availableImports, currentPkg));
+                builder.append(getExplicitType(param.getReturnType(), availableImports, currentPkg));
                 builder.append(GAP);
                 builder.append(param.getName());
             }
                 builder.append(GAP);
                 builder.append(param.getName());
             }
@@ -305,15 +303,37 @@ public final class GeneratorUtil {
                 builder.append(NL);
             }
         }
                 builder.append(NL);
             }
         }
+        List<Constant> consts = genTransferObject.getConstantDefinitions();
+        for (Constant con : consts) {
+            if (con.getName() == null || con.getType() == null || con.getValue() == null)
+                continue;
+            if (con.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
+                Object values = con.getValue();
+                if (values instanceof List) {
+                    for (Object regEx : (List<?>) values) {
+                        if (regEx instanceof String) {
+                            builder.append(indent + TAB + "for (String regEx : " + TypeConstants.PATTERN_CONSTANT_NAME
+                                    + ") {" + NL);
+                            builder.append(indent + TAB + TAB + "this." + MEMBER_PATTERN_LIST
+                                    + ".add(Pattern.compile(regEx))" + SC + NL);
+                            builder.append(indent + TAB + RCB + NL);
+
+                            break;
+                        }
+                    }
+
+                }
+            }
+
+        }
+
         builder.append(indent);
         builder.append(RCB);
         return builder.toString();
     }
 
         builder.append(indent);
         builder.append(RCB);
         return builder.toString();
     }
 
-    public static String createGetter(final GeneratedProperty property,
-            final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
+    public static String createGetter(final GeneratedProperty property, final String indent,
+            Map<String, LinkedHashMap<String, Integer>> availableImports, final String currentPkg) {
         final StringBuilder builder = new StringBuilder();
 
         final Type type = property.getReturnType();
         final StringBuilder builder = new StringBuilder();
 
         final Type type = property.getReturnType();
@@ -321,9 +341,7 @@ public final class GeneratorUtil {
         final char first = Character.toUpperCase(varName.charAt(0));
         final String methodName = "get" + first + varName.substring(1);
 
         final char first = Character.toUpperCase(varName.charAt(0));
         final String methodName = "get" + first + varName.substring(1);
 
-        builder.append(indent + PUBLIC + GAP
-                + getExplicitType(type, availableImports, currentPkg) + GAP
-                + methodName);
+        builder.append(indent + PUBLIC + GAP + getExplicitType(type, availableImports, currentPkg) + GAP + methodName);
         builder.append(LB + RB + LCB + NL);
 
         String currentIndent = indent + TAB;
         builder.append(LB + RB + LCB + NL);
 
         String currentIndent = indent + TAB;
@@ -334,10 +352,8 @@ public final class GeneratorUtil {
         return builder.toString();
     }
 
         return builder.toString();
     }
 
-    public static String createSetter(final GeneratedProperty property,
-            final String indent,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            String currentPkg) {
+    public static String createSetter(final GeneratedProperty property, final String indent,
+            Map<String, LinkedHashMap<String, Integer>> availableImports, String currentPkg) {
         final StringBuilder builder = new StringBuilder();
 
         final Type type = property.getReturnType();
         final StringBuilder builder = new StringBuilder();
 
         final Type type = property.getReturnType();
@@ -346,17 +362,14 @@ public final class GeneratorUtil {
         final String methodName = "set" + first + varName.substring(1);
 
         builder.append(indent + PUBLIC + GAP + "void" + GAP + methodName);
         final String methodName = "set" + first + varName.substring(1);
 
         builder.append(indent + PUBLIC + GAP + "void" + GAP + methodName);
-        builder.append(LB + getExplicitType(type, availableImports, currentPkg)
-                + GAP + varName + RB + LCB + NL);
+        builder.append(LB + getExplicitType(type, availableImports, currentPkg) + GAP + varName + RB + LCB + NL);
         String currentIndent = indent + TAB;
         String currentIndent = indent + TAB;
-        builder.append(currentIndent + "this." + varName + " = " + varName + SC
-                + NL);
+        builder.append(currentIndent + "this." + varName + " = " + varName + SC + NL);
         builder.append(indent + RCB);
         return builder.toString();
     }
 
         builder.append(indent + RCB);
         return builder.toString();
     }
 
-    public static String createHashCode(
-            final List<GeneratedProperty> properties, final String indent) {
+    public static String createHashCode(final List<GeneratedProperty> properties, final String indent) {
         StringBuilder builder = new StringBuilder();
         builder.append(indent + "public int hashCode() {" + NL);
         builder.append(indent + TAB + "final int prime = 31;" + NL);
         StringBuilder builder = new StringBuilder();
         builder.append(indent + "public int hashCode() {" + NL);
         builder.append(indent + TAB + "final int prime = 31;" + NL);
@@ -364,8 +377,7 @@ public final class GeneratorUtil {
 
         for (GeneratedProperty property : properties) {
             String fieldName = property.getName();
 
         for (GeneratedProperty property : properties) {
             String fieldName = property.getName();
-            builder.append(indent + TAB + "result = prime * result + (("
-                    + fieldName + " == null) ? 0 : " + fieldName
+            builder.append(indent + TAB + "result = prime * result + ((" + fieldName + " == null) ? 0 : " + fieldName
                     + ".hashCode());" + NL);
         }
 
                     + ".hashCode());" + NL);
         }
 
@@ -374,8 +386,8 @@ public final class GeneratorUtil {
         return builder.toString();
     }
 
         return builder.toString();
     }
 
-    public static String createEquals(final GeneratedTransferObject type,
-            final List<GeneratedProperty> properties, final String indent) {
+    public static String createEquals(final GeneratedTransferObject type, final List<GeneratedProperty> properties,
+            final String indent) {
         StringBuilder builder = new StringBuilder();
         final String indent1 = indent + TAB;
         final String indent2 = indent1 + TAB;
         StringBuilder builder = new StringBuilder();
         final String indent1 = indent + TAB;
         final String indent2 = indent1 + TAB;
@@ -393,18 +405,15 @@ public final class GeneratorUtil {
         builder.append(indent1 + "}" + NL);
 
         String typeStr = type.getName();
         builder.append(indent1 + "}" + NL);
 
         String typeStr = type.getName();
-        builder.append(indent1 + typeStr + " other = (" + typeStr + ") obj;"
-                + NL);
+        builder.append(indent1 + typeStr + " other = (" + typeStr + ") obj;" + NL);
 
         for (GeneratedProperty property : properties) {
             String fieldName = property.getName();
             builder.append(indent1 + "if (" + fieldName + " == null) {" + NL);
 
         for (GeneratedProperty property : properties) {
             String fieldName = property.getName();
             builder.append(indent1 + "if (" + fieldName + " == null) {" + NL);
-            builder.append(indent2 + "if (other." + fieldName + " != null) {"
-                    + NL);
+            builder.append(indent2 + "if (other." + fieldName + " != null) {" + NL);
             builder.append(indent3 + "return false;" + NL);
             builder.append(indent2 + "}" + NL);
             builder.append(indent3 + "return false;" + NL);
             builder.append(indent2 + "}" + NL);
-            builder.append(indent1 + "} else if (!" + fieldName
-                    + ".equals(other." + fieldName + ")) {" + NL);
+            builder.append(indent1 + "} else if (!" + fieldName + ".equals(other." + fieldName + ")) {" + NL);
             builder.append(indent2 + "return false;" + NL);
             builder.append(indent1 + "}" + NL);
         }
             builder.append(indent2 + "return false;" + NL);
             builder.append(indent1 + "}" + NL);
         }
@@ -415,8 +424,8 @@ public final class GeneratorUtil {
         return builder.toString();
     }
 
         return builder.toString();
     }
 
-    public static String createToString(final GeneratedTransferObject type,
-            final List<GeneratedProperty> properties, final String indent) {
+    public static String createToString(final GeneratedTransferObject type, final List<GeneratedProperty> properties,
+            final String indent) {
         StringBuilder builder = new StringBuilder();
         builder.append(indent);
         builder.append("public String toString() {");
         StringBuilder builder = new StringBuilder();
         builder.append(indent);
         builder.append("public String toString() {");
@@ -474,12 +483,11 @@ public final class GeneratorUtil {
         return builder.toString();
     }
 
         return builder.toString();
     }
 
-    public static String createEnum(final Enumeration enumeration,
-            final String indent) {
+    public static String createEnum(final Enumeration enumeration, final String indent) {
         if (enumeration == null || indent == null)
             throw new IllegalArgumentException();
         if (enumeration == null || indent == null)
             throw new IllegalArgumentException();
-        final StringBuilder builder = new StringBuilder(indent + PUBLIC + GAP
-                + ENUM + GAP + enumeration.getName() + GAP + LCB + NL);
+        final StringBuilder builder = new StringBuilder(indent + PUBLIC + GAP + ENUM + GAP + enumeration.getName()
+                + GAP + LCB + NL);
 
         String separator = COMMA + NL;
         final List<Pair> values = enumeration.getValues();
 
         String separator = COMMA + NL;
         final List<Pair> values = enumeration.getValues();
@@ -488,21 +496,17 @@ public final class GeneratorUtil {
             if (i + 1 == values.size()) {
                 separator = SC;
             }
             if (i + 1 == values.size()) {
                 separator = SC;
             }
-            builder.append(indent + TAB + values.get(i).getName() + LB
-                    + values.get(i).getValue() + RB + separator);
+            builder.append(indent + TAB + values.get(i).getName() + LB + values.get(i).getValue() + RB + separator);
         }
         builder.append(NL);
         builder.append(NL);
         final String ENUMERATION_NAME = "value";
         final String ENUMERATION_TYPE = "int";
         }
         builder.append(NL);
         builder.append(NL);
         final String ENUMERATION_NAME = "value";
         final String ENUMERATION_TYPE = "int";
-        builder.append(indent + TAB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME
-                + SC);
+        builder.append(indent + TAB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME + SC);
         builder.append(NL);
         builder.append(NL);
-        builder.append(indent + TAB + PRIVATE + GAP + enumeration.getName()
-                + LB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME + RB + GAP
-                + LCB + NL);
-        builder.append(indent + TAB + TAB + "this." + ENUMERATION_NAME + GAP
-                + "=" + GAP + ENUMERATION_NAME + SC + NL);
+        builder.append(indent + TAB + PRIVATE + GAP + enumeration.getName() + LB + ENUMERATION_TYPE + GAP
+                + ENUMERATION_NAME + RB + GAP + LCB + NL);
+        builder.append(indent + TAB + TAB + "this." + ENUMERATION_NAME + GAP + "=" + GAP + ENUMERATION_NAME + SC + NL);
         builder.append(indent + TAB + RCB + NL);
 
         builder.append(indent + RCB);
         builder.append(indent + TAB + RCB + NL);
 
         builder.append(indent + RCB);
@@ -511,27 +515,21 @@ public final class GeneratorUtil {
     }
 
     private static String getExplicitType(final Type type,
     }
 
     private static String getExplicitType(final Type type,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            final String currentPkg) {
+            Map<String, LinkedHashMap<String, Integer>> availableImports, final String currentPkg) {
         if (type == null) {
         if (type == null) {
-            throw new IllegalArgumentException(
-                    "Type parameter MUST be specified and cannot be NULL!");
+            throw new IllegalArgumentException("Type parameter MUST be specified and cannot be NULL!");
         }
         String packageName = type.getPackageName();
 
         }
         String packageName = type.getPackageName();
 
-        LinkedHashMap<String, Integer> imports = availableImports.get(type
-                .getName());
+        LinkedHashMap<String, Integer> imports = availableImports.get(type.getName());
 
 
-        if ((imports != null && packageName
-                .equals(findMaxValue(imports).get(0)))
-                || packageName.equals(currentPkg)) {
+        if ((imports != null && packageName.equals(findMaxValue(imports).get(0))) || packageName.equals(currentPkg)) {
             final StringBuilder builder = new StringBuilder(type.getName());
             if (type instanceof ParameterizedType) {
                 ParameterizedType pType = (ParameterizedType) type;
                 Type[] pTypes = pType.getActualTypeArguments();
                 builder.append("<");
             final StringBuilder builder = new StringBuilder(type.getName());
             if (type instanceof ParameterizedType) {
                 ParameterizedType pType = (ParameterizedType) type;
                 Type[] pTypes = pType.getActualTypeArguments();
                 builder.append("<");
-                builder.append(getParameters(pTypes, availableImports,
-                        currentPkg));
+                builder.append(getParameters(pTypes, availableImports, currentPkg));
                 builder.append(">");
             }
             if (builder.toString().equals("Void")) {
                 builder.append(">");
             }
             if (builder.toString().equals("Void")) {
@@ -554,8 +552,7 @@ public final class GeneratorUtil {
                 ParameterizedType pType = (ParameterizedType) type;
                 Type[] pTypes = pType.getActualTypeArguments();
                 builder.append("<");
                 ParameterizedType pType = (ParameterizedType) type;
                 Type[] pTypes = pType.getActualTypeArguments();
                 builder.append("<");
-                builder.append(getParameters(pTypes, availableImports,
-                        currentPkg));
+                builder.append(getParameters(pTypes, availableImports, currentPkg));
                 builder.append(">");
             }
             if (builder.toString().equals("Void")) {
                 builder.append(">");
             }
             if (builder.toString().equals("Void")) {
@@ -566,8 +563,7 @@ public final class GeneratorUtil {
     }
 
     private static String getParameters(final Type[] pTypes,
     }
 
     private static String getParameters(final Type[] pTypes,
-            Map<String, LinkedHashMap<String, Integer>> availableImports,
-            String currentPkg) {
+            Map<String, LinkedHashMap<String, Integer>> availableImports, String currentPkg) {
         final StringBuilder builder = new StringBuilder();
         for (int i = 0; i < pTypes.length; i++) {
             Type t = pTypes[i];
         final StringBuilder builder = new StringBuilder();
         for (int i = 0; i < pTypes.length; i++) {
             Type t = pTypes[i];
@@ -576,20 +572,18 @@ public final class GeneratorUtil {
             if (i + 1 == pTypes.length) {
                 separator = "";
             }
             if (i + 1 == pTypes.length) {
                 separator = "";
             }
-            
+
             String wildcardParam = "";
             String wildcardParam = "";
-            if(t instanceof WildcardType) {
+            if (t instanceof WildcardType) {
                 wildcardParam = "? extends ";
             }
                 wildcardParam = "? extends ";
             }
-            
-            builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg)
-                    + separator);
+
+            builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg) + separator);
         }
         return builder.toString();
     }
 
         }
         return builder.toString();
     }
 
-    private static List<String> findMaxValue(
-            LinkedHashMap<String, Integer> imports) {
+    private static List<String> findMaxValue(LinkedHashMap<String, Integer> imports) {
         final List<String> result = new ArrayList<String>();
 
         int maxValue = 0;
         final List<String> result = new ArrayList<String>();
 
         int maxValue = 0;
@@ -607,8 +601,7 @@ public final class GeneratorUtil {
         return result;
     }
 
         return result;
     }
 
-    private static void createComment(final StringBuilder builder,
-            final String comment, final String indent) {
+    private static void createComment(final StringBuilder builder, final String comment, final String indent) {
         if (comment != null && comment.length() > 0) {
             builder.append(indent + "/*" + NL);
             builder.append(indent + comment + NL);
         if (comment != null && comment.length() > 0) {
             builder.append(indent + "/*" + NL);
             builder.append(indent + comment + NL);
@@ -616,13 +609,12 @@ public final class GeneratorUtil {
         }
     }
 
         }
     }
 
-    public static Map<String, LinkedHashMap<String, Integer>> createImports(
-            GeneratedType genType) {
+    public static Map<String, LinkedHashMap<String, Integer>> createImports(GeneratedType genType) {
         final Map<String, LinkedHashMap<String, Integer>> imports = new HashMap<String, LinkedHashMap<String, Integer>>();
         final String genTypePkg = genType.getPackageName();
 
         final List<Constant> constants = genType.getConstantDefinitions();
         final Map<String, LinkedHashMap<String, Integer>> imports = new HashMap<String, LinkedHashMap<String, Integer>>();
         final String genTypePkg = genType.getPackageName();
 
         final List<Constant> constants = genType.getConstantDefinitions();
-               final List<MethodSignature> methods = genType.getMethodDefinitions();
+        final List<MethodSignature> methods = genType.getMethodDefinitions();
         List<Type> impl = genType.getImplements();
 
         // IMPLEMENTATIONS
         List<Type> impl = genType.getImplements();
 
         // IMPLEMENTATIONS
@@ -664,16 +656,23 @@ public final class GeneratorUtil {
             }
         }
 
             }
         }
 
+        // REGULAR EXPRESSION
+        if (genType instanceof GeneratedTransferObject) {
+            if (isConstantInTO(TypeConstants.PATTERN_CONSTANT_NAME, (GeneratedTransferObject) genType)) {
+                addTypeToImports(Types.typeForClass(java.util.regex.Pattern.class), imports, genTypePkg);
+                addTypeToImports(Types.typeForClass(java.util.Arrays.class), imports, genTypePkg);
+                addTypeToImports(Types.typeForClass(java.util.ArrayList.class), imports, genTypePkg);
+            }
+        }
+
         return imports;
     }
 
         return imports;
     }
 
-    private static void addTypeToImports(Type type,
-            Map<String, LinkedHashMap<String, Integer>> importedTypes,
+    private static void addTypeToImports(Type type, Map<String, LinkedHashMap<String, Integer>> importedTypes,
             String genTypePkg) {
         String typeName = type.getName();
         String typePkg = type.getPackageName();
             String genTypePkg) {
         String typeName = type.getName();
         String typePkg = type.getPackageName();
-               if (typePkg.startsWith("java.lang") || typePkg.equals(genTypePkg) ||
-                typePkg.isEmpty()) {
+        if (typePkg.startsWith("java.lang") || typePkg.equals(genTypePkg) || typePkg.isEmpty()) {
             return;
         }
         LinkedHashMap<String, Integer> packages = importedTypes.get(typeName);
             return;
         }
         LinkedHashMap<String, Integer> packages = importedTypes.get(typeName);
@@ -700,12 +699,10 @@ public final class GeneratorUtil {
         }
     }
 
         }
     }
 
-    public static List<String> createImportLines(
-            Map<String, LinkedHashMap<String, Integer>> imports) {
+    public static List<String> createImportLines(Map<String, LinkedHashMap<String, Integer>> imports) {
         List<String> importLines = new ArrayList<String>();
 
         List<String> importLines = new ArrayList<String>();
 
-        for (Map.Entry<String, LinkedHashMap<String, Integer>> entry : imports
-                .entrySet()) {
+        for (Map.Entry<String, LinkedHashMap<String, Integer>> entry : imports.entrySet()) {
             String typeName = entry.getKey();
             LinkedHashMap<String, Integer> typePkgMap = entry.getValue();
             String typePkg = typePkgMap.keySet().iterator().next();
             String typeName = entry.getKey();
             LinkedHashMap<String, Integer> typePkgMap = entry.getValue();
             String typePkg = typePkgMap.keySet().iterator().next();
@@ -714,4 +711,17 @@ public final class GeneratorUtil {
         return importLines;
     }
 
         return importLines;
     }
 
+    public static boolean isConstantInTO(String constName, GeneratedTransferObject genTO) {
+        if (constName == null || genTO == null)
+            throw new IllegalArgumentException();
+        List<Constant> consts = genTO.getConstantDefinitions();
+        for (Constant cons : consts) {
+            if (cons.getName().equals(constName)) {
+                return true;
+            }
+
+        }
+        return false;
+    }
+
 }
 }
diff --git a/opendaylight/sal/yang-prototype/code-generator/samples/maven-code-gen-sample/src/main/yang/simple-string-demo.yang b/opendaylight/sal/yang-prototype/code-generator/samples/maven-code-gen-sample/src/main/yang/simple-string-demo.yang
new file mode 100644 (file)
index 0000000..c0f87dd
--- /dev/null
@@ -0,0 +1,22 @@
+module simple-string-demo {
+
+    namespace "urn:simple:string:demo";
+    prefix "sbd";
+
+    organization "OPEN DAYLIGHT";
+    contact "http://www.opendaylight.org/";
+
+    revision 2013-06-18 {
+        
+    }
+
+    typedef typedef-string {
+        type string {
+            length "40";
+            pattern "[0-9A-F]\.*";
+            pattern "[B-D]*";
+            pattern "[4-7]*";
+        }
+    }
+
+}