Added support for implements and extends of GeneratedType; 14/314/1
authorlsedlak <lsedlak@cisco.com>
Tue, 7 May 2013 11:11:59 +0000 (13:11 +0200)
committerlsedlak <lsedlak@cisco.com>
Tue, 7 May 2013 12:51:29 +0000 (14:51 +0200)
Added functionality to store List of implementing Generation Types into
GeneratedType and GeneratedTypeBuilder;
Added functionality to store Extending Transfer Object for
GeneratedTransferObject and GeneratedTOBuilder;

Fixed:
DataNodeIterator no longer returns augmented containers, lists, leafs
and leaflists - only non augmented module schema tree;
Added findDataSchemaNode for given SchemaPath into SchemaContextUtil;

Signed-off-by: Lukas Sedlak <lsedlak@cisco.com>
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedTransferObject.java
opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/GeneratedType.java
opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTOBuilder.java
opendaylight/sal/yang-prototype/code-generator/binding-model-api/src/main/java/org/opendaylight/controller/sal/binding/model/api/type/builder/GeneratedTypeBuilder.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/DataNodeIterator.java
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/SchemaContextUtil.java

index e2cb0aa..81104d2 100644 (file)
@@ -17,6 +17,7 @@ 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.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
 import org.opendaylight.controller.sal.binding.model.api.Type;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
@@ -30,7 +31,9 @@ public final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
     private String packageName;
     private final String name;
     private String comment = "";
-
+    
+    private GeneratedTransferObject extendsType;
+    private final List<GeneratedType> implementsTypes = new ArrayList<GeneratedType>();
     private final List<EnumBuilder> enumerations = new ArrayList<EnumBuilder>();
     private final List<GeneratedPropertyBuilder> properties = new ArrayList<GeneratedPropertyBuilder>();
     private final List<GeneratedPropertyBuilder> equalsProperties = new ArrayList<GeneratedPropertyBuilder>();
@@ -79,7 +82,24 @@ public final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
         }
         return null;
     }
+    
+    @Override
+    public boolean addImplementsType(final GeneratedType genType) {
+        if (genType != null) {
+            return implementsTypes.add(genType);
+        }
+        return false;
+    }
 
+    @Override
+    public boolean addExtendsType(final GeneratedTransferObject genTransObj) {
+        if (genTransObj != null) {
+            extendsType = genTransObj;
+            return true;
+        }
+        return false;
+    }
+    
     @Override
     public EnumBuilder addEnumeration(String name) {
         final EnumBuilder builder = new EnumerationBuilderImpl(packageName,
@@ -130,7 +150,7 @@ public final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
     @Override
     public GeneratedTransferObject toInstance() {
         return new GeneratedTransferObjectImpl(packageName, name, comment, 
-                annotationBuilders, constantDefintions, enumerations,
+                annotationBuilders, extendsType, implementsTypes, constantDefintions, enumerations,
                 methodDefinitions, properties, equalsProperties,
                 hashProperties, toStringProperties);
     }
@@ -388,11 +408,15 @@ public final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
         private final List<GeneratedProperty> stringProperties;
         private final List<AnnotationType> annotations;
         private final List<MethodSignature> methods;
+        private final GeneratedTransferObject extendsType;
+        private final List<GeneratedType> implementsTypes;
 
         public GeneratedTransferObjectImpl(final String packageName,
                 final String name,
                 final String comment,
                 final List<AnnotationTypeBuilder> annotationBuilders,
+                final GeneratedTransferObject extendsType,
+                final List<GeneratedType> implementsTypes,
                 final List<ConstantBuilder> constantBuilders,
                 final List<EnumBuilder> enumBuilders,
                 final List<MethodSignatureBuilder> methodBuilders,
@@ -405,6 +429,8 @@ public final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
             this.name = name;
             this.comment = comment;
             this.annotations = toUnmodifiableAnnotations(annotationBuilders);
+            this.extendsType = extendsType;
+            this.implementsTypes = Collections.unmodifiableList(implementsTypes);
             this.constants = toUnmodifiableConstant(constantBuilders);
             this.enumerations = toUnmodifiableEnumerations(enumBuilders);
             this.properties = toUnmodifiableProperties(propBuilers);
@@ -483,7 +509,17 @@ public final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
         public List<AnnotationType> getAnnotations() {
             return annotations;
         }
+        
+        @Override
+        public List<GeneratedType> getImplements() {
+            return implementsTypes;
+        }
 
+        @Override
+        public GeneratedTransferObject getExtends() {
+            return extendsType;
+        }
+        
         @Override
         public List<Enumeration> getEnumDefintions() {
             return enumerations;
index deeda77..46b5cf4 100644 (file)
@@ -29,10 +29,11 @@ public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {
     private String comment = "";
     private final String name;
     private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
+    private final List<GeneratedType> implementsTypes = new ArrayList<GeneratedType>();
     private final List<EnumBuilder> enumDefinitions = new ArrayList<EnumBuilder>();
     private final List<ConstantBuilder> constantDefintions = new ArrayList<ConstantBuilder>();
     private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<MethodSignatureBuilder>();
-
+    
     public GeneratedTypeBuilderImpl(final String packageName, final String name) {
         this.packageName = packageName;
         this.name = name;
@@ -95,13 +96,21 @@ public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {
         return builder;
     }
 
+    @Override
+    public boolean addImplementsType(final GeneratedType genType) {
+        if (genType != null) {
+            return implementsTypes.add(genType);
+        }
+        return false;
+    }
+    
     @Override
     public GeneratedType toInstance() {
         return new GeneratedTypeImpl(this, packageName, name, comment,
-                annotationBuilders, enumDefinitions, constantDefintions,
+                annotationBuilders, implementsTypes, enumDefinitions, constantDefintions,
                 methodDefinitions);
     }
-
+    
     private static final class GeneratedTypeImpl implements GeneratedType {
 
         private final Type parent;
@@ -109,6 +118,7 @@ public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {
         private final String name;
         private final String comment;
         private final List<AnnotationType> annotations;
+        private final List<GeneratedType> implementsTypes;
         private final List<Enumeration> enumDefinitions;
         private final List<Constant> constantDefintions;
         private final List<MethodSignature> methodDefinitions;
@@ -116,6 +126,7 @@ public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {
         public GeneratedTypeImpl(final Type parent, final String packageName,
                 final String name, final String comment,
                 final List<AnnotationTypeBuilder> annotationBuilders,
+                final List<GeneratedType> implementsTypes,
                 final List<EnumBuilder> enumBuilders,
                 final List<ConstantBuilder> constantBuilders,
                 final List<MethodSignatureBuilder> methodBuilders) {
@@ -125,6 +136,7 @@ public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {
             this.name = name;
             this.comment = comment;
             this.annotations = toUnmodifiableAnnotations(annotationBuilders);
+            this.implementsTypes = Collections.unmodifiableList(implementsTypes); 
             this.constantDefintions = toUnmodifiableConstants(constantBuilders);
             this.enumDefinitions = toUnmodifiableEnums(enumBuilders);
             this.methodDefinitions = toUnmodifiableMethods(methodBuilders);
@@ -190,7 +202,12 @@ public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {
         public List<AnnotationType> getAnnotations() {
             return annotations;
         }
-
+        
+        @Override
+        public List<GeneratedType> getImplements() {
+            return implementsTypes;
+        }
+        
         @Override
         public List<Enumeration> getEnumDefintions() {
             return enumDefinitions;
index 2fc4ccf..c014254 100644 (file)
@@ -13,7 +13,9 @@ import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject
 
  */
 public interface GeneratedTOBuilder extends GeneratedTypeBuilder {
-
+    
+    public boolean addExtendsType(final GeneratedTransferObject genTransObj);
+    
     public GeneratedPropertyBuilder addProperty(final String name);
 
     public boolean addEqualsIdentity(final GeneratedPropertyBuilder property);
index 55c6abc..55da97a 100644 (file)
@@ -22,6 +22,8 @@ public interface GeneratedTypeBuilder extends Type {
     
     public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
     
+    public boolean addImplementsType(final GeneratedType genType);
+    
     public ConstantBuilder addConstant(final Type type, final String name,
             final Object value);
 
index ded4a75..b4eaed7 100644 (file)
@@ -61,6 +61,9 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
         final Set<DataSchemaNode> childs = dataNode.getChildNodes();
         if (childs != null) {
             for (DataSchemaNode childNode : childs) {
+                if (childNode.isAugmenting()) {
+                    continue;
+                }
                 allChilds.add(childNode);
                 if (childNode instanceof ContainerSchemaNode) {
                     final ContainerSchemaNode container = (ContainerSchemaNode) childNode;
index ab50982..8554f68 100644 (file)
@@ -31,7 +31,23 @@ public final class SchemaContextUtil {
     public SchemaContextUtil(final SchemaContext context) {
         this.context = context;
     }
-
+    
+    public SchemaContext getContext() {
+        return context;
+    }
+    
+    public DataSchemaNode findDataSchemaNode(final SchemaPath schemaPath) {
+        if (schemaPath != null) {
+            final Module module = resolveModuleFromSchemaPath(schemaPath);
+            final Queue<String> prefixedPath = schemaPathToQueuedPath(schemaPath);
+            
+            if ((module != null) && (prefixedPath != null)) {
+                return findSchemaNodeForGivenPath(module, prefixedPath);
+            }
+        }
+        return null;
+    }
+    
     public DataSchemaNode findDataSchemaNode(final Module module,
             final RevisionAwareXPath nonCondXPath) {
         if (nonCondXPath != null) {
@@ -187,7 +203,30 @@ public final class SchemaContextUtil {
         }
         return retQueue;
     }
-
+    
+    private Queue<String> schemaPathToQueuedPath(final SchemaPath schemaPath) {
+        final Queue<String> retQueue = new LinkedList<String>();
+        if ((schemaPath != null) && (schemaPath.getPath() != null)) {
+            final List<QName> listPath = schemaPath.getPath();
+            
+            for (final QName qname : listPath) {
+                if (qname != null) {
+                    final String prefix = qname.getPrefix();
+                    final String localName = qname.getLocalName();
+                    
+                    final StringBuilder builder = new StringBuilder();
+                    if (prefix != null) {
+                        builder.append(prefix);
+                        builder.append(":");
+                    }
+                    builder.append(localName);
+                    retQueue.add(builder.toString());
+                }
+            }
+        }
+        return retQueue;
+    }
+    
     private Queue<String> resolveRelativeXPath(
             final RevisionAwareXPath relativeXPath,
             final SchemaPath leafrefSchemaPath) {

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.