Implemented length statement. Added new method to Builder classes. 44/2444/3
authorMartin Vitez <mvitez@cisco.com>
Wed, 6 Nov 2013 14:26:02 +0000 (15:26 +0100)
committerMartin Vitez <mvitez@cisco.com>
Thu, 7 Nov 2013 10:12:38 +0000 (11:12 +0100)
 - Implemented type length restriction in generated code (Bug 93).
 - Setters for binary and string fields contains check for valid length.

 - Added new "fieldsFrom(DataObject arg)" method to Builder classes.
 - Method accepts class generated from grouping and serves as setter of properties based on grouping type.

Change-Id: I402ef1d76a68cdde3f4a8a8c74d2100ac38a6487
Signed-off-by: Martin Vitez <mvitez@cisco.com>
16 files changed:
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend
code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BaseTemplate.xtend
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BuilderTemplate.xtend
code-generator/binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend
code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CascadeUsesCompilationTest.java
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/ConcreteType.java
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/GeneratedTransferObject.java
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/Restrictions.java [new file with mode: 0644]
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/builder/GeneratedTOBuilder.java
code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java
code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java
yang/yang-binding/pom.xml

index 257a5c4c76636b0d40f8548fa7c331b7b1c02d54..8a6d638c5d584bd30db6cad5e4a25717d2f5a26d 100644 (file)
@@ -71,6 +71,8 @@ import org.opendaylight.yangtools.yang.model.api.AugmentationTarget
 import java.util.Collection
 import org.opendaylight.yangtools.yang.model.api.YangNode
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
+import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions
 
 public class BindingGeneratorImpl implements BindingGenerator {
 
@@ -1322,8 +1324,9 @@ public class BindingGeneratorImpl implements BindingGenerator {
                     if (genTOBuilder !== null) {
                         returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
                     }
-                } else {
-                    returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
+                } else {\r
+                    val Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);\r
+                    returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf, restrictions);
                 }
                 if (returnType !== null) {
                     val MethodSignatureBuilder getter = constructGetter(typeBuilder, leafName, leafDesc, returnType);
index b0722b4164c6d39c2d49241a5ce2f3a67b483b2b..d8b13385938b3b39b9474c4deb406254de3ef14e 100644 (file)
@@ -7,6 +7,7 @@
  */\r
 package org.opendaylight.yangtools.sal.binding.generator.spi;\r
 \r
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;\r
 import org.opendaylight.yangtools.sal.binding.model.api.Type;\r
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;\r
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
@@ -33,4 +34,6 @@ public interface TypeProvider {
      * @return Resolved Type\r
      */\r
     Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode);\r
+\r
+    Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode, final Restrictions restrictions);\r
 }\r
index 092c47c72d0457fa80cd310d04cdc292bd60638e..f0b7b808f788f9f196112efc238545a1ad260ea0 100644 (file)
@@ -2,15 +2,21 @@ package org.opendaylight.yangtools.binding.generator.util;
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 
 /**
  * Contains the methods for converting strings to valid JAVA language strings
@@ -320,4 +326,37 @@ public final class BindingGeneratorUtil {
         }
         return sb.toString();
     }
+
+    public static Restrictions getRestrictions(TypeDefinition<?> type) {
+        final List<LengthConstraint> length = new ArrayList<>();
+        final List<PatternConstraint> pattern = new ArrayList<>();
+        final List<RangeConstraint> range = new ArrayList<>();
+
+        if (type instanceof ExtendedType) {
+            ExtendedType ext = (ExtendedType)type;
+            length.addAll(ext.getLengthConstraints());
+            pattern.addAll(ext.getPatternConstraints());
+            range.addAll(ext.getRangeConstraints());
+        }
+
+        return new Restrictions() {
+            @Override
+            public List<RangeConstraint> getRangeConstraints() {
+                return range;
+            }
+            @Override
+            public List<PatternConstraint> getPatternConstraints() {
+                return pattern;
+            }
+            @Override
+            public List<LengthConstraint> getLengthConstraints() {
+                return length;
+            }
+            @Override
+            public boolean isEmpty() {
+                return range.isEmpty() && pattern.isEmpty() && length.isEmpty();
+            }
+        };
+    }
+
 }
index a96e000b4ca7d001a6b34b55ac162be5d362439d..ffcbf175b6314817db87dbcffaf93a4a54c801f0 100644 (file)
@@ -7,18 +7,16 @@
  */
 package org.opendaylight.yangtools.binding.generator.util;
 
-import java.math.BigDecimal;
-import java.math.BigInteger;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.Callable;
 import java.util.concurrent.Future;
 
 import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
 import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType;
 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;
 import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.sal.binding.model.api.WildcardType;
 import org.opendaylight.yangtools.yang.binding.Augmentable;
@@ -29,24 +27,10 @@ public final class Types {
     private static final Type SET_TYPE = typeForClass(Set.class);
     private static final Type LIST_TYPE = typeForClass(List.class);
     private static final Type MAP_TYPE = typeForClass(Map.class);
-    public static final ConcreteType NUMBER = typeForClass(Number.class);
-    public static final ConcreteType BIG_DECIMAL = typeForClass(BigDecimal.class);
-    public static final ConcreteType BIG_INTEGER = typeForClass(BigInteger.class);
-    public static final ConcreteType BYTE = typeForClass(Byte.class);
+
     public static final ConcreteType BOOLEAN = typeForClass(Boolean.class);
-    public static final ConcreteType DOUBLE = typeForClass(Double.class);
-    public static final ConcreteType FLOAT = typeForClass(Float.class);
-    public static final ConcreteType INTEGER = typeForClass(Integer.class);
-    public static final ConcreteType LONG = typeForClass(Long.class);
-    public static final ConcreteType SHORT = typeForClass(Short.class);
-    public static final ConcreteType STRING = typeForClass(String.class);
-    public static final ConcreteType CHAR_SEQUENCE = typeForClass(CharSequence.class);
-    public static final ConcreteType THREAD = typeForClass(Thread.class);
     public static final ConcreteType FUTURE = typeForClass(Future.class);
-    public static final ConcreteType CALLABLE = typeForClass(Callable.class);
     public static final ConcreteType VOID = typeForClass(Void.class);
-    public static final ConcreteType THROWABLE = typeForClass(Throwable.class);
-    public static final ConcreteType EXCEPTION = typeForClass(Exception.class);
 
     /**
      * It is not desirable to create instance of this class
@@ -58,7 +42,7 @@ public final class Types {
      * Creates the instance of type
      * {@link org.opendaylight.yangtools.sal.binding.model.api.ConcreteType
      * ConcreteType} which represents JAVA <code>void</code> type.
-     * 
+     *
      * @return <code>ConcreteType</code> instance which represents JAVA
      *         <code>void</code>
      */
@@ -71,32 +55,36 @@ public final class Types {
      * {@link org.opendaylight.yangtools.sal.binding.model.api.ConcreteType
      * ConcreteType} which represents primitive JAVA type for which package
      * doesn't exist.
-     * 
+     *
      * @param primitiveType
      *            string containing programaticall construction based on
      *            primitive type (e.g byte[])
      * @return <code>ConcreteType</code> instance which represents programatic
      *         construction with primitive JAVA type
      */
-    public static Type primitiveType(final String primitiveType) {
-        return new ConcreteTypeImpl("", primitiveType);
+    public static Type primitiveType(final String primitiveType, final Restrictions restrictions) {
+        return new ConcreteTypeImpl("", primitiveType, restrictions);
     }
 
     /**
      * Returns an instance of {@link ConcreteType} describing the class
-     * 
+     *
      * @param cls
      *            Class to describe
      * @return Description of class
      */
     public static ConcreteType typeForClass(Class<?> cls) {
-        return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName());
+        return typeForClass(cls, null);
+    }
+
+    public static ConcreteType typeForClass(Class<?> cls, Restrictions restrictions) {
+        return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions);
     }
 
     /**
      * Returns an instance of {@link ParameterizedType} describing the typed
      * {@link Map}<K,V>
-     * 
+     *
      * @param keyType
      *            Key Type
      * @param valueType
@@ -110,7 +98,7 @@ public final class Types {
     /**
      * Returns an instance of {@link ParameterizedType} describing the typed
      * {@link Set}<V> with concrete type of value.
-     * 
+     *
      * @param valueType
      *            Value Type
      * @return Description of generic type instance of Set
@@ -122,7 +110,7 @@ public final class Types {
     /**
      * Returns an instance of {@link ParameterizedType} describing the typed
      * {@link List}<V> with concrete type of value.
-     * 
+     *
      * @param valueType
      *            Value Type
      * @return Description of type instance of List
@@ -134,7 +122,7 @@ public final class Types {
     /**
      * Creates generated transfer object for
      * {@link org.opendaylight.yangtools.yang.binding.BaseIdentity BaseIdentity}
-     * 
+     *
      * @return generated transfer object which is used as extension when YANG
      *         <code>identity</code> is mapped to generated TO
      */
@@ -148,7 +136,7 @@ public final class Types {
      * Creates instance of type
      * {@link org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType
      * ParameterizedType}
-     * 
+     *
      * @param type
      *            JAVA <code>Type</code> for raw type
      * @param parameters
@@ -164,7 +152,7 @@ public final class Types {
      * Creates instance of type
      * {@link org.opendaylight.yangtools.sal.binding.model.api.WildcardType
      * WildcardType}
-     * 
+     *
      * @param packageName
      *            string with the package name
      * @param typeName
@@ -182,7 +170,7 @@ public final class Types {
      * ParameterizedType} where raw type is
      * {@link org.opendaylight.yangtools.yang.binding.Augmentable} and actual
      * parameter is <code>valueType</code>.
-     * 
+     *
      * @param valueType
      *            JAVA <code>Type</code> with actual parameter
      * @return <code>ParametrizedType</code> reprezentation of raw type
@@ -200,7 +188,7 @@ public final class Types {
      * ParameterizedType} where raw type is
      * {@link org.opendaylight.yangtools.yang.binding.Augmentation} and actual
      * parameter is <code>valueType</code>.
-     * 
+     *
      * @param valueType
      *            JAVA <code>Type</code> with actual parameter
      * @return <code>ParametrizedType</code> reprezentation of raw type
@@ -213,29 +201,37 @@ public final class Types {
     }
 
     /**
-     * 
+     *
      * Represents concrete JAVA type.
-     * 
+     *
      */
     private static final class ConcreteTypeImpl extends AbstractBaseType implements ConcreteType {
+        private final Restrictions restrictions;
+
         /**
          * Creates instance of this class with package <code>pkName</code> and
          * with the type name <code>name</code>.
-         * 
+         *
          * @param pkName
          *            string with package name
          * @param name
          *            string with the name of the type
          */
-        private ConcreteTypeImpl(String pkName, String name) {
+        private ConcreteTypeImpl(String pkName, String name, Restrictions restrictions) {
             super(pkName, name);
+            this.restrictions = restrictions;
+        }
+
+        @Override
+        public Restrictions getRestrictions() {
+            return restrictions;
         }
     }
 
     /**
-     * 
+     *
      * Represents parametrized JAVA type.
-     * 
+     *
      */
     private static class ParametrizedTypeImpl extends AbstractBaseType implements ParameterizedType {
         /**
@@ -262,7 +258,7 @@ public final class Types {
         /**
          * Creates instance of this class with concrete rawType and array of
          * actual parameters.
-         * 
+         *
          * @param rawType
          *            JAVA <code>Type</code> for raw type
          * @param actTypes
@@ -277,14 +273,14 @@ public final class Types {
     }
 
     /**
-     * 
+     *
      * Represents JAVA bounded wildcard type.
-     * 
+     *
      */
     private static class WildcardTypeImpl extends AbstractBaseType implements WildcardType {
         /**
          * Creates instance of this class with concrete package and type name.
-         * 
+         *
          * @param packageName
          *            string with the package name
          * @param typeName
index 55223398c6031f1c593af70e3f5e282b52f7dddc..3b45b342a689424682c0e07115c85a6a35f3cbaa 100644 (file)
@@ -12,6 +12,7 @@ import java.util.List;
 \r
 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;\r
 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;\r
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;\r
 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;\r
 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder;\r
 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;\r
@@ -25,6 +26,7 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder<G
     private final List<GeneratedPropertyBuilder> hashProperties = new ArrayList<>();\r
     private final List<GeneratedPropertyBuilder> toStringProperties = new ArrayList<>();\r
     private boolean isUnionType = false;\r
+    private Restrictions restrictions;\r
 \r
     public GeneratedTOBuilderImpl(String packageName, String name) {\r
         super(packageName, name);\r
@@ -49,7 +51,7 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder<G
      * {@link MethodSignatureBuilder#setAbstract(boolean)},\r
      * {TypeMemberBuilder#setFinal(boolean)} and\r
      * {TypeMemberBuilder#setAccessModifier(boolean)}\r
-     * \r
+     *\r
      * @param name\r
      *            Name of Method\r
      * @return <code>new</code> instance of Method Signature Builder.\r
@@ -84,6 +86,11 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder<G
         return this;\r
     }\r
 \r
+    @Override\r
+    public void setRestrictions(Restrictions restrictions) {\r
+        this.restrictions = restrictions;\r
+    }\r
+\r
     @Override\r
     public GeneratedTransferObject toInstance() {\r
         return new GeneratedTransferObjectImpl(this);\r
@@ -131,6 +138,7 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder<G
         private final List<GeneratedProperty> stringProperties;\r
         private final GeneratedTransferObject extendsType;\r
         private final boolean isUnionType;\r
+        private final Restrictions restrictions;\r
 \r
         public GeneratedTransferObjectImpl(GeneratedTOBuilderImpl builder) {\r
             super(builder);\r
@@ -139,6 +147,7 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder<G
             this.hashCodeProperties = toUnmodifiableProperties(builder.hashProperties);\r
             this.stringProperties = toUnmodifiableProperties(builder.toStringProperties);\r
             this.isUnionType = builder.isUnionType;\r
+            this.restrictions = builder.restrictions;\r
         }\r
 \r
         @Override\r
@@ -166,6 +175,11 @@ public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder<G
             return stringProperties;\r
         }\r
 \r
+        @Override\r
+        public Restrictions getRestrictions() {\r
+            return restrictions;\r
+        }\r
+\r
         @Override\r
         public String toString() {\r
             StringBuilder builder = new StringBuilder();\r
index 4056c6f2f7f778c00b3fda5fce7d0dafa8c0dee2..ff56e94600231980da3c4098bee8cf9f99addeee 100644 (file)
@@ -7,6 +7,12 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type
 import org.opendaylight.yangtools.binding.generator.util.Types
 import com.google.common.base.Splitter
 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature
+import com.google.common.collect.Range
+import java.util.ArrayList
+import java.util.List
+import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
 
 abstract class BaseTemplate {
     
@@ -151,4 +157,40 @@ abstract class BaseTemplate {
             **/
             '''
     }
+
+    def generateLengthRestrictions(Type type, String paramName) '''
+        Â«IF type instanceof ConcreteType»
+            Â«val restrictions = (type as ConcreteType).restrictions»
+            Â«IF restrictions !== null && !restrictions.lengthConstraints.empty»
+                Â«generateLengthRestriction(type, restrictions, paramName)»
+            Â«ENDIF»
+        Â«ENDIF»
+        Â«IF type instanceof GeneratedTransferObject»
+            Â«val restrictions = (type as GeneratedTransferObject).restrictions»
+            Â«IF restrictions !== null && !restrictions.lengthConstraints.empty»
+                Â«generateLengthRestriction(type, restrictions, paramName)»
+            Â«ENDIF»
+        Â«ENDIF»
+    '''
+
+    def generateLengthRestriction(Type type, Restrictions restrictions, String paramName) '''
+            boolean isValidLength = false;
+            Â«List.importedName»<«Range.importedName»<«Integer.importedName»>> lengthConstraints = new Â«ArrayList.importedName»<>(); 
+            Â«FOR r : restrictions.lengthConstraints»
+                lengthConstraints.add(«Range.importedName».closed(«r.min», Â«r.max»));
+            Â«ENDFOR»
+            for («Range.importedName»<«Integer.importedName»> r : lengthConstraints) {
+                Â«IF type.name.contains("[")»
+                if (r.contains(«paramName».length)) {
+                Â«ELSE»
+                if (r.contains(«paramName».length())) {
+                Â«ENDIF»
+                    isValidLength = true;
+                }
+            }
+            if (!isValidLength) {
+                throw new IllegalArgumentException("illegal length");
+            }
+    '''
+
 }
\ No newline at end of file
index 7534f3895946dd66cbba2584545ada627ff17dad..0bf6252fbb2929423e5fea3ccfdca1ecccb7b6ff 100644 (file)
@@ -16,8 +16,9 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type
 import org.opendaylight.yangtools.yang.binding.Augmentable\r
 import static org.opendaylight.yangtools.binding.generator.util.Types.*\r
 import java.util.HashMap\r
-import java.util.Collections\r
-\r
+import java.util.Collections\rimport org.opendaylight.yangtools.yang.binding.DataObject
+import java.util.ArrayList
+
 /**\r
  * Template for generating JAVA builder classes. \r
  */\r
@@ -204,7 +205,9 @@ class BuilderTemplate extends BaseTemplate {
 \r
             Â«generateFields(false)»\r
 \r
-            Â«generateBuilderConstructor(type)»\r
+            Â«generateConstructorsFromIfcs(type)»\r
+\r
+            Â«generateSetterFromIfcs(type)»\r
 \r
             Â«generateGetters(false)»\r
 \r
@@ -232,39 +235,81 @@ class BuilderTemplate extends BaseTemplate {
         }\r
     '''\r
 \r
-\r
-    def private generateBuilderConstructor(Type type) '''\r
+    def private generateConstructorsFromIfcs(Type type) '''\r
         public Â«type.name»«BUILDER»() {\r
-        }\r
+        } \r
         Â«IF (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject))»\r
         Â«val ifc = type as GeneratedType»\r
         Â«FOR impl : ifc.implements»\r
-            Â«generateSingleBuilderConstructor(impl)»\r
+            Â«generateConstructorFromIfc(impl)»\r
         Â«ENDFOR»\r
         Â«ENDIF»\r
     '''\r
 \r
-    def private generateSingleBuilderConstructor(Type impl) '''\r
+    def private generateConstructorFromIfc(Type impl) '''\r
         Â«IF (impl instanceof GeneratedType) &&  !((impl as GeneratedType).methodDefinitions.empty)»\r
-        \r
         Â«val implType = impl as GeneratedType»\r
+\r
         public Â«type.name»«BUILDER»(«implType.fullyQualifiedName» arg) {\r
-            Â«printBuilderConstructorProperties(implType)»\r
+            Â«printConstructorProperties(implType)»\r
         }\r
         Â«FOR implTypeImplement : implType.implements»\r
-            Â«generateSingleBuilderConstructor(implTypeImplement)»\r
+            Â«generateConstructorFromIfc(implTypeImplement)»\r
         Â«ENDFOR»\r
         Â«ENDIF»\r
     '''\r
 \r
-    def private printBuilderConstructorProperties(Type implementedIfc) '''\r
+    def private printConstructorProperties(Type implementedIfc) '''\r
         Â«IF (implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))»\r
         Â«val ifc = implementedIfc as GeneratedType»\r
         Â«FOR getter : ifc.methodDefinitions»\r
             this._«getter.propertyNameFromGetter» = arg.«getter.name»();\r
         Â«ENDFOR»\r
         Â«FOR impl : ifc.implements»\r
-        Â«printBuilderConstructorProperties(impl)»\r
+        Â«printConstructorProperties(impl)»\r
+        Â«ENDFOR»\r
+        Â«ENDIF»\r
+    '''\r
+\r
+    def private generateSetterFromIfcs(Type type) '''\r
+        Â«IF (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject))»\r
+        Â«val ifc = type as GeneratedType»\r
+        Â«val List<Type> done = new ArrayList()»\r
+        public void fieldsFrom(«DataObject.importedName» arg) {\r
+            Â«FOR impl : ifc.implements»\r
+                Â«generateSettersForIfc(impl, done)»\r
+            Â«ENDFOR»\r
+        }\r
+        Â«ENDIF»\r
+    '''\r
+\r
+    def private generateSettersForIfc(Type impl, List<Type> done) '''\r
+        Â«IF (impl instanceof GeneratedType) &&  !((impl as GeneratedType).methodDefinitions.empty)»\r
+            Â«val implType = impl as GeneratedType»\r
+            Â«val boolean added = done.contains(impl)»\r
+            Â«IF !(added)»\r
+                if (arg instanceof Â«implType.fullyQualifiedName») {\r
+                    Â«printSetterProperties(implType, done)»\r
+                }\r
+            Â«ENDIF»\r
+            Â«FOR implTypeImplement : implType.implements»\r
+                Â«generateSettersForIfc(implTypeImplement, done)»\r
+            Â«ENDFOR»\r
+        Â«ENDIF»\r
+    '''\r
+\r
+    def private printSetterProperties(Type implementedIfc, List<Type> done) '''\r
+        Â«IF (implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))»\r
+        Â«val ifc = implementedIfc as GeneratedType»\r
+        Â«val boolean added = done.contains(ifc)»\r
+        Â«IF !(added)»\r
+        Â«FOR getter : ifc.methodDefinitions»\r
+            this._«getter.propertyNameFromGetter» = ((«implementedIfc.fullyQualifiedName»)arg).«getter.name»();\r
+        Â«ENDFOR»\r
+        Â«val add = done.add(ifc)»\r
+        Â«ENDIF»\r
+        Â«FOR impl : ifc.implements»\r
+        Â«printSetterProperties(impl, done)»\r
         Â«ENDFOR»\r
         Â«ENDIF»\r
     '''\r
@@ -294,6 +339,8 @@ class BuilderTemplate extends BaseTemplate {
     def private generateSetters() '''\r
         Â«FOR field : properties SEPARATOR '\n'»\r
             public Â«type.name»«BUILDER» set«field.name.toFirstUpper»(«field.returnType.importedName» value) {\r
+                Â«generateLengthRestrictions(field.returnType, "value")»\r
+\r
                 this.«field.fieldName» = value;\r
                 return this;\r
             }\r
@@ -306,7 +353,7 @@ class BuilderTemplate extends BaseTemplate {
             }\r
         Â«ENDIF»\r
     '''\r
-    \r
+\r
     /**\r
      * Template method which generate constructor for IMPL class.\r
      * \r
index 102c7c62b82a18e79bee3f7d9a1b8766800c2122..31c2e3831051e3039efb83a37bc5f48bf92caa7f 100644 (file)
@@ -142,6 +142,7 @@ class ClassTemplate extends BaseTemplate {
             super(«parentProperties.asArguments»);\r
         Â«ENDIF»\r
         Â«FOR p : properties» \r
+            Â«generateLengthRestrictions(p.returnType, p.fieldName.toString)»\r
             this.«p.fieldName» = Â«p.fieldName»;\r
         Â«ENDFOR»\r
     }\r
index 6528c48dee1010ee07b980102c1360e10e330df6..06ac678afe5c9a0e00abcbfb5f4579ee24eabfb7 100644 (file)
@@ -12,6 +12,7 @@ import static org.opendaylight.yangtools.sal.java.api.generator.test.Compilation
 
 import java.io.File;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.HashSet;
@@ -117,6 +118,16 @@ public class CascadeUsesCompilationTest extends BaseCompilationTest {
         assertNotNull(usesBarGr1);
         assertNotNull(usesBazGr1);
 
+        Method fieldsFromMethod = null;
+        for (Method m : nodesBuilderClass.getDeclaredMethods()) {
+            String methodName = m.getName();
+            if ("fieldsFrom".equals(methodName)) {
+                fieldsFromMethod = m;
+            }
+        }
+        assertNotNull(fieldsFromMethod);
+        assertEquals(1, fieldsFromMethod.getParameterTypes().length);
+
         cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
index 2bfe8ed6bb0a385f3dbc9aeac01c785791d5d68d..f26b4cab27b389ec5c68c5e8f383cf49f4dc7bdd 100644 (file)
@@ -20,14 +20,14 @@ import java.util.List;
  * definitions. For this purpose retrieve definitions through
  * {@link #getEqualsIdentifiers ()}, {@link #getHashCodeIdentifiers()} and
  * {@link #getToStringIdentifiers ()}.
- * 
+ *
  */
 public interface GeneratedTransferObject extends GeneratedType {
 
     /**
      * Returns the extending Generated Transfer Object or <code>null</code> if
      * there is no extending Generated Transfer Object.
-     * 
+     *
      * @return the extending Generated Transfer Object or <code>null</code> if
      *         there is no extending Generated Transfer Object.
      */
@@ -36,7 +36,7 @@ public interface GeneratedTransferObject extends GeneratedType {
     /**
      * Returns List of Properties that are designated to define equality for
      * Generated Transfer Object.
-     * 
+     *
      * @return List of Properties that are designated to define equality for
      *         Generated Transfer Object.
      */
@@ -45,7 +45,7 @@ public interface GeneratedTransferObject extends GeneratedType {
     /**
      * Returns List of Properties that are designated to define identity for
      * Generated Transfer Object.
-     * 
+     *
      * @return List of Properties that are designated to define identity for
      *         Generated Transfer Object.
      */
@@ -54,7 +54,7 @@ public interface GeneratedTransferObject extends GeneratedType {
     /**
      * Returns List of Properties that will be members of toString definition
      * for Generated Transfer Object.
-     * 
+     *
      * @return List of Properties that will be members of toString definition
      *         for Generated Transfer Object.
      */
@@ -63,10 +63,12 @@ public interface GeneratedTransferObject extends GeneratedType {
     /**
      * Return boolean value which describe whether Generated Transfer Object
      * was/wasn't created from union YANG type.
-     * 
+     *
      * @return true value if Generated Transfer Object was created from union
      *         YANG type.
      */
     @Deprecated
     boolean isUnionType();
+
+    Restrictions getRestrictions();
 }
diff --git a/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/Restrictions.java b/code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/Restrictions.java
new file mode 100644 (file)
index 0000000..292b632
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.sal.binding.model.api;
+
+import java.util.List;
+
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+public interface Restrictions {
+
+    List<LengthConstraint> getLengthConstraints();
+    List<PatternConstraint> getPatternConstraints();
+    List<RangeConstraint> getRangeConstraints();
+    boolean isEmpty();
+
+}
index a0c81617bea38c07f128e2cee08b28b69292f034..0f12f780089556788d04c197ee1b9dcb09d94b9f 100644 (file)
@@ -8,11 +8,12 @@
 package org.opendaylight.yangtools.sal.binding.model.api.type.builder;
 
 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;
 
 /**
  * Generated Transfer Object Builder is interface that contains methods to build
  * and instantiate Generated Transfer Object definition.
- * 
+ *
  * @see GeneratedTransferObject
  */
 public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase<GeneratedTOBuilder> {
@@ -25,7 +26,7 @@ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase<GeneratedTO
      * be overwritten by lastly added Generated Transfer Object. <br>
      * If Generated Transfer Object is <code>null</code> the method SHOULD throw
      * {@link IllegalArgumentException}
-     * 
+     *
      * @param genTransObj
      *            Generated Transfer Object
      * @return This instance of builder
@@ -36,7 +37,7 @@ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase<GeneratedTO
      * Add Property that will be part of <code>equals</code> definition. <br>
      * If Generated Property Builder is <code>null</code> the method SHOULD
      * throw {@link IllegalArgumentException}
-     * 
+     *
      * @param property
      *            Generated Property Builder
      * @return This instance of builder
@@ -47,7 +48,7 @@ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase<GeneratedTO
      * Add Property that will be part of <code>hashCode</code> definition. <br>
      * If Generated Property Builder is <code>null</code> the method SHOULD
      * throw {@link IllegalArgumentException}
-     * 
+     *
      * @param property
      *            Generated Property Builder
      * @return This instance of builder
@@ -58,23 +59,25 @@ public interface GeneratedTOBuilder extends GeneratedTypeBuilderBase<GeneratedTO
      * Add Property that will be part of <code>toString</code> definition. <br>
      * If Generated Property Builder is <code>null</code> the method SHOULD
      * throw {@link IllegalArgumentException}
-     * 
+     *
      * @param property
      *            Generated Property Builder
      * @return This instance of builder
      */
     GeneratedTOBuilder addToStringProperty(final GeneratedPropertyBuilder property);
 
+    void setRestrictions(Restrictions restrictions);
+
     /**
      * Returns instance of <code>GeneratedTransferObject</code> which data are
      * build from the data of this builder
-     * 
+     *
      * @return generated transfer object instance
      */
     GeneratedTransferObject toInstance();
 
     /**
-     * 
+     *
      * @param isUnion
      */
     void setIsUnion(boolean isUnion);
index b77878ffc44fa89cb595619c2cc0fc31a02562bc..adffbf0105c618a3d1bd97de0c57fd5ba8c3b613 100644 (file)
@@ -14,6 +14,7 @@ import java.util.Map;
 \r
 import org.opendaylight.yangtools.binding.generator.util.Types;\r
 import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider;\r
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;\r
 import org.opendaylight.yangtools.sal.binding.model.api.Type;\r
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;\r
@@ -90,7 +91,7 @@ public final class BaseYangTypes {
     /**\r
      * <code>Type</code> representation of <code>binary</code> YANG type\r
      */\r
-    public static final Type BINARY_TYPE = Types.primitiveType("byte[]");\r
+    public static final Type BINARY_TYPE = Types.primitiveType("byte[]", null);\r
 \r
     public static final Type INSTANCE_IDENTIFIER = Types.parameterizedTypeFor(Types\r
             .typeForClass(InstanceIdentifier.class));\r
@@ -151,5 +152,24 @@ public final class BaseYangTypes {
 \r
             return null;\r
         }\r
+\r
+        @Override\r
+        public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode, Restrictions restrictions) {\r
+            String typeName = type.getQName().getLocalName();\r
+            switch (typeName) {\r
+            case "binary" : return Types.primitiveType("byte[]", restrictions);\r
+            case "decimal64": return Types.typeForClass(BigDecimal.class, restrictions);\r
+            case "int8": return Types.typeForClass(Byte.class, restrictions);\r
+            case "int16": return Types.typeForClass(Short.class, restrictions);\r
+            case "int32": return Types.typeForClass(Integer.class, restrictions);\r
+            case "int64": return Types.typeForClass(Long.class, restrictions);\r
+            case "string": return Types.typeForClass(String.class, restrictions);\r
+            case "uint8": return Types.typeForClass(Short.class, restrictions);\r
+            case "uint16": Types.typeForClass(Integer.class, restrictions);\r
+            case "uint32": Types.typeForClass(Long.class, restrictions);\r
+            case "uint64": Types.typeForClass(BigInteger.class, restrictions);\r
+            default: return javaTypeForSchemaDefinitionType(type, parentNode);\r
+            }\r
+        }\r
     };\r
 }\r
index 063cbc61ca4d8aba14d29ca702e1ca4a1525fc1f..b7d1657e85eca6c5a2859002d65b9987936745cd 100644 (file)
@@ -27,8 +27,10 @@ import org.opendaylight.yangtools.binding.generator.util.Types;
 import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.EnumerationBuilderImpl;
 import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
 import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider;
+import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType;
 import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;
 import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.EnumBuilder;
 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
@@ -79,7 +81,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Creates new instance of class <code>TypeProviderImpl</code>.
-     * 
+     *
      * @param schemaContext
      *            contains the schema data red from YANG files
      * @throws IllegalArgumentException
@@ -96,7 +98,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Puts <code>refType</code> to map with key <code>refTypePath</code>
-     * 
+     *
      * @param refTypePath
      *            schema path used as the map key
      * @param refType
@@ -106,7 +108,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             <li>if <code>refTypePath</code> equal null</li>
      *             <li>if <code>refType</code> equal null</li>
      *             </ul>
-     * 
+     *
      */
     public void putReferencedType(final SchemaPath refTypePath, final Type refType) {
         Preconditions.checkArgument(refTypePath != null,
@@ -116,9 +118,9 @@ public final class TypeProviderImpl implements TypeProvider {
     }
 
     /**
-     * 
+     *
      * Converts basic YANG type <code>type</code> to JAVA <code>Type</code>.
-     * 
+     *
      * @param type
      *            string with YANG name of type
      * @return JAVA <code>Type</code> for YANG type <code>type</code>
@@ -129,10 +131,15 @@ public final class TypeProviderImpl implements TypeProvider {
         return BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForYangType(type);
     }
 
+    @Override
+    public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode) {
+        return javaTypeForSchemaDefinitionType(typeDefinition, parentNode, null);
+    }
+
     /**
      * Converts schema definition type <code>typeDefinition</code> to JAVA
      * <code>Type</code>
-     * 
+     *
      * @param typeDefinition
      *            type definition which is converted to JAVA type
      * @throws IllegalArgumentException
@@ -143,7 +150,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             </ul>
      */
     @Override
-    public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode) {
+    public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode, Restrictions r) {
         Type returnType = null;
         Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!");
         if (typeDefinition.getQName() == null) {
@@ -159,7 +166,7 @@ public final class TypeProviderImpl implements TypeProvider {
             returnType = javaTypeForLeafrefOrIdentityRef(typeDefinition, parentNode);
             if (returnType == null) {
                 returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition,
-                        parentNode);
+                        parentNode, r);
             }
         }
         // TODO: add throw exception when we will be able to resolve ALL yang
@@ -175,7 +182,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * Returns JAVA <code>Type</code> for instances of the type
      * <code>LeafrefTypeDefinition</code> or
      * <code>IdentityrefTypeDefinition</code>.
-     * 
+     *
      * @param typeDefinition
      *            type definition which is converted to JAVA <code>Type</code>
      * @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
@@ -195,7 +202,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Returns JAVA <code>Type</code> for instances of the type
      * <code>ExtendedType</code>.
-     * 
+     *
      * @param typeDefinition
      *            type definition which is converted to JAVA <code>Type</code>
      * @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
@@ -211,6 +218,7 @@ public final class TypeProviderImpl implements TypeProvider {
                 returnType = provideTypeForEnum(enumTypeDef, typedefName, typeDefinition);
             } else {
                 final Module module = findParentModule(schemaContext, typeDefinition);
+                Restrictions r = BindingGeneratorUtil.getRestrictions(typeDefinition);
                 if (module != null) {
                     final Map<String, Type> genTOs = genTypeDefsContextMap.get(module.getName());
                     if (genTOs != null) {
@@ -218,7 +226,7 @@ public final class TypeProviderImpl implements TypeProvider {
                     }
                     if (returnType == null) {
                         returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
-                                baseTypeDef, typeDefinition);
+                                baseTypeDef, typeDefinition, r);
                     }
                 }
             }
@@ -236,11 +244,11 @@ public final class TypeProviderImpl implements TypeProvider {
      * Seeks for identity reference <code>idref</code> the JAVA
      * <code>type</code>.<br />
      * <br />
-     * 
+     *
      * <i>Example:<br />
      * If identy which is referenced via <code>idref</code> has name <b>Idn</b>
      * then returning type is <b>{@code Class<? extends Idn>}</b></i>
-     * 
+     *
      * @param idref
      *            identityref type definition for which JAVA <code>Type</code>
      *            is sought
@@ -270,7 +278,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Converts <code>typeDefinition</code> to concrete JAVA <code>Type</code>.
-     * 
+     *
      * @param typeDefinition
      *            type definition which should be converted to JAVA
      *            <code>Type</code>
@@ -315,7 +323,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Gets base type definition for <code>extendTypeDef</code>. The method is
      * recursivelly called until non <code>ExtendedType</code> type is found.
-     * 
+     *
      * @param extendTypeDef
      *            type definition for which is the base type definition sought
      * @return type definition which is base type for <code>extendTypeDef</code>
@@ -335,10 +343,10 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Converts <code>leafrefType</code> to JAVA <code>Type</code>.
-     * 
+     *
      * The path of <code>leafrefType</code> is followed to find referenced node
      * and its <code>Type</code> is returned.
-     * 
+     *
      * @param leafrefType
      *            leafref type definition for which is the type sought
      * @return JAVA <code>Type</code> of data schema node which is referenced in
@@ -348,7 +356,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             <li>if <code>leafrefType</code> equal null</li>
      *             <li>if path statement of <code>leafrefType</code> equal null</li>
      *             </ul>
-     * 
+     *
      */
     public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType, final SchemaNode parentNode) {
         Type returnType = null;
@@ -389,7 +397,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Checks if <code>dataNode</code> is <code>LeafSchemaNode</code> and if it
      * so then checks if it is of type <code>EnumTypeDefinition</code>.
-     * 
+     *
      * @param dataNode
      *            data schema node for which is checked if it is leaf and if it
      *            is of enum type
@@ -412,7 +420,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Checks if <code>dataNode</code> is <code>LeafListSchemaNode</code> and if
      * it so then checks if it is of type <code>EnumTypeDefinition</code>.
-     * 
+     *
      * @param dataNode
      *            data schema node for which is checked if it is leaflist and if
      *            it is of enum type
@@ -437,7 +445,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * Converts <code>enumTypeDef</code> to
      * {@link org.opendaylight.yangtools.sal.binding.model.api.Enumeration
      * enumeration}.
-     * 
+     *
      * @param enumTypeDef
      *            enumeration type definition which is converted to enumeration
      * @param enumName
@@ -474,7 +482,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Adds enumeration to <code>typeBuilder</code>. The enumeration data are
      * taken from <code>enumTypeDef</code>.
-     * 
+     *
      * @param enumTypeDef
      *            enumeration type definition is source of enumeration data for
      *            <code>typeBuilder</code>
@@ -492,7 +500,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             <li>if name of <code>enumTypeDef</code> equal null</li>
      *             <li>if name of <code>typeBuilder</code> equal null</li>
      *             </ul>
-     * 
+     *
      */
     private Enumeration addInnerEnumerationToTypeBuilder(final EnumTypeDefinition enumTypeDef, final String enumName,
             final GeneratedTypeBuilderBase<?> typeBuilder) {
@@ -513,7 +521,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Converts <code>dataNode</code> to JAVA <code>Type</code>.
-     * 
+     *
      * @param dataNode
      *            contains information about YANG type
      * @return JAVA <code>Type</code> representation of <code>dataNode</code>
@@ -535,7 +543,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Passes through all modules and through all its type definitions and
      * convert it to generated types.
-     * 
+     *
      * The modules are firstly sorted by mutual dependencies. The modules are
      * sequentially passed. All type definitions of a module are at the
      * beginning sorted so that type definition with less amount of references
@@ -544,7 +552,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * {@link TypeProviderImpl#genTypeDefsContextMap genTypeDefsContextMap}
      * which map current module name to the map which maps type names to
      * returned types (generated types).
-     * 
+     *
      */
     private void resolveTypeDefsFromContext() {
         final Set<Module> modules = schemaContext.getModules();
@@ -579,7 +587,7 @@ public final class TypeProviderImpl implements TypeProvider {
     }
 
     /**
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param moduleName
@@ -604,7 +612,7 @@ public final class TypeProviderImpl implements TypeProvider {
                 Type returnType = null;
                 if (innerTypeDefinition instanceof ExtendedType) {
                     ExtendedType innerExtendedType = (ExtendedType) innerTypeDefinition;
-                    returnType = provideGeneratedTOFromExtendedType(innerExtendedType, basePackageName, typedefName);
+                    returnType = provideGeneratedTOFromExtendedType(typedef, innerExtendedType, basePackageName);
                 } else if (innerTypeDefinition instanceof UnionTypeDefinition) {
                     final GeneratedTOBuilder genTOBuilder = provideGeneratedTOBuilderForUnionTypeDef(basePackageName,
                             (UnionTypeDefinition) innerTypeDefinition, typedefName, typedef);
@@ -620,8 +628,9 @@ public final class TypeProviderImpl implements TypeProvider {
                     returnType = genTOBuilder.toInstance();
 
                 } else {
+                    Restrictions r = BindingGeneratorUtil.getRestrictions(typedef);
                     final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
-                            innerTypeDefinition, typedef);
+                            innerTypeDefinition, typedef, r);
 
                     returnType = wrapJavaTypeIntoTO(basePackageName, typedef, javaType);
                 }
@@ -639,7 +648,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Wraps base YANG type to generated TO.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typedef
@@ -659,7 +668,7 @@ public final class TypeProviderImpl implements TypeProvider {
             genTOBuilder.addEqualsIdentity(genPropBuilder);
             genTOBuilder.addHashIdentity(genPropBuilder);
             genTOBuilder.addToStringProperty(genPropBuilder);
-            if (javaType == BaseYangTypes.STRING_TYPE && typedef instanceof ExtendedType) {
+            if (javaType instanceof ConcreteType && "String".equals(javaType.getName()) && typedef instanceof ExtendedType) {
                 final List<String> regExps = resolveRegExpressionsFromTypedef((ExtendedType) typedef);
                 addStringRegExAsConstant(genTOBuilder, regExps);
             }
@@ -671,7 +680,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Converts output list of generated TO builders to one TO builder (first
      * from list) which contains the remaining builders as its enclosing TO.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typedef
@@ -701,7 +710,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * Converts <code>typedef</code> to generated TO with
      * <code>typeDefName</code>. Every union type from <code>typedef</code> is
      * added to generated TO builder as property.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typedef
@@ -769,14 +778,14 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Wraps code which handle case when union subtype is also of the type
      * <code>UnionType</code>.
-     * 
+     *
      * In this case the new generated TO is created for union subtype (recursive
      * call of method
      * {@link #provideGeneratedTOBuildersForUnionTypeDef(String, TypeDefinition, String)
      * provideGeneratedTOBuilderForUnionTypeDef} and in parent TO builder
      * <code>parentUnionGenTOBuilder</code> is created property which type is
      * equal to new generated TO.
-     * 
+     *
      * @param parentUnionGenTOBuilder
      *            generated TO builder to which is the property with the child
      *            union subtype added
@@ -807,11 +816,11 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Wraps code which handle case when union subtype is of the type
      * <code>ExtendedType</code>.
-     * 
+     *
      * If TO for this type already exists it is used for the creation of the
      * property in <code>parentUnionGenTOBuilder</code>. In other case the base
      * type is used for the property creation.
-     * 
+     *
      * @param parentUnionGenTOBuilder
      *            generated TO builder in which new property is created
      * @param unionSubtype
@@ -846,7 +855,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Searches for generated TO for <code>searchedTypeDef</code> type
      * definition in {@link #genTypeDefsContextMap genTypeDefsContextMap}
-     * 
+     *
      * @param searchedTypeName
      *            string with name of <code>searchedTypeDef</code>
      * @return generated TO for <code>searchedTypeDef</code> or
@@ -867,7 +876,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * Stores generated TO created from <code>genTOBuilder</code> for
      * <code>newTypeDef</code> to {@link #genTypeDefsContextMap
      * genTypeDefsContextMap} if the module for <code>newTypeDef</code> exists
-     * 
+     *
      * @param newTypeDef
      *            type definition for which is <code>genTOBuilder</code> created
      * @param genTOBuilder
@@ -888,7 +897,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Adds a new property with the name <code>propertyName</code> and with type
      * <code>type</code> to <code>unonGenTransObject</code>.
-     * 
+     *
      * @param unionGenTransObject
      *            generated TO to which should be property added
      * @param type
@@ -913,7 +922,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Converts <code>typedef</code> to the generated TO builder.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typedef
@@ -938,10 +947,10 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Converts <code>typeDef</code> which should be of the type
      * <code>BitsTypeDefinition</code> to <code>GeneratedTOBuilder</code>.
-     * 
+     *
      * All the bits of the typeDef are added to returning generated TO as
      * properties.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typeDef
@@ -988,13 +997,13 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Converts the pattern constraints from <code>typedef</code> to the list of
      * the strings which represents these constraints.
-     * 
+     *
      * @param typedef
      *            extended type in which are the pattern constraints sought
      * @return list of strings which represents the constraint patterns
      * @throws IllegalArgumentException
      *             if <code>typedef</code> equals null
-     * 
+     *
      */
     private List<String> resolveRegExpressionsFromTypedef(ExtendedType typedef) {
         final List<String> regExps = new ArrayList<String>();
@@ -1016,10 +1025,10 @@ public final class TypeProviderImpl implements TypeProvider {
     }
 
     /**
-     * 
+     *
      * Adds to the <code>genTOBuilder</code> the constant which contains regular
      * expressions from the <code>regularExpressions</code>
-     * 
+     *
      * @param genTOBuilder
      *            generated TO builder to which are
      *            <code>regular expressions</code> added
@@ -1049,11 +1058,11 @@ public final class TypeProviderImpl implements TypeProvider {
      * <code>innerExtendedType</code>, about the package name
      * <code>typedefName</code> and about the generated TO name
      * <code>typedefName</code>.
-     * 
+     *
      * It is supposed that <code>innerExtendedType</code> is already present in
      * {@link TypeProviderImpl#genTypeDefsContextMap genTypeDefsContextMap} to
      * be possible set it as extended type for the returning generated TO.
-     * 
+     *
      * @param innerExtendedType
      *            extended type which is part of some other extended type
      * @param basePackageName
@@ -1069,16 +1078,17 @@ public final class TypeProviderImpl implements TypeProvider {
      *             <li>if <code>typedefName</code> equals null</li>
      *             </ul>
      */
-    private GeneratedTransferObject provideGeneratedTOFromExtendedType(final ExtendedType innerExtendedType,
-            final String basePackageName, final String typedefName) {
-
+    private GeneratedTransferObject provideGeneratedTOFromExtendedType(final TypeDefinition<?> typedef, final ExtendedType innerExtendedType,
+            final String basePackageName) {
         Preconditions.checkArgument(innerExtendedType != null, "Extended type cannot be NULL!");
         Preconditions.checkArgument(basePackageName != null, "String with base package name cannot be NULL!");
-        Preconditions.checkArgument(typedefName != null, "String with type definition name cannot be NULL!");
 
+        final String typedefName = typedef.getQName().getLocalName();
         final String classTypedefName = parseToClassName(typedefName);
         final String innerTypeDef = innerExtendedType.getQName().getLocalName();
         final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, classTypedefName);
+        Restrictions r = BindingGeneratorUtil.getRestrictions(typedef);
+        genTOBuilder.setRestrictions(r);
 
         Map<String, Type> typeMap = null;
         final Module parentModule = findParentModule(schemaContext, innerExtendedType);
@@ -1103,7 +1113,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * equal depth. In next step are lists from this map concatenated to one
      * list in ascending order according to their depth. All type definitions
      * are in the list behind all type definitions on which depends.
-     * 
+     *
      * @param unsortedTypeDefinitions
      *            list of type definitions which should be sorted by depth
      * @return list of type definitions sorted according their each other
@@ -1136,7 +1146,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Returns how many immersion is necessary to get from the type definition
      * to the base type.
-     * 
+     *
      * @param typeDefinition
      *            type definition for which is depth sought.
      * @return number of immersions which are necessary to get from the type
@@ -1170,7 +1180,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * Returns string which contains the same value as <code>name</code> but
      * integer suffix is incremented by one. If <code>name</code> contains no
      * number suffix then number 1 is added.
-     * 
+     *
      * @param name
      *            string with name of augmented node
      * @return string with the number suffix incremented by one (or 1 is added)
index 8efa9ac92d90e42c93127721d2264bce3749da14..34727ec373f02ac76a70eb93b85d91c7dcda3528 100644 (file)
             <artifactId>yang-common</artifactId>\r
             <version>0.5.9-SNAPSHOT</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>com.google.guava</groupId>\r
+            <artifactId>guava</artifactId>\r
+        </dependency>\r
     </dependencies>\r
     <version>0.6.0-SNAPSHOT</version>\r
 </project>\r