import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
import org.opendaylight.yangtools.util.LazyCollections;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder<GeneratedTOBuilder> implements GeneratedTOBuilder {
private boolean isTypedef = false;
private boolean isUnionType = false;
private boolean isUnionTypeBuilder = false;
+ private TypeDefinition baseType = null;
private Restrictions restrictions;
private GeneratedPropertyBuilder SUID;
private String reference;
this.isTypedef = isTypedef;
}
+ @Override
+ public void setBaseType(final TypeDefinition typeDef) {
+ this.baseType = typeDef;
+ }
+
@Override
public void setIsUnion(final boolean isUnion) {
this.isUnionType = isUnion;
private final List<GeneratedProperty> stringProperties;
private final GeneratedTransferObject extendsType;
private final boolean isTypedef;
+ private final TypeDefinition baseType;
private final boolean isUnionType;
private final boolean isUnionTypeBuilder;
private final Restrictions restrictions;
this.stringProperties = toUnmodifiableProperties(builder.toStringProperties);
this.isTypedef = builder.isTypedef;
+ this.baseType = builder.baseType;
this.isUnionType = builder.isUnionType;
this.isUnionTypeBuilder = builder.isUnionTypeBuilder;
this.restrictions = builder.restrictions;
return isTypedef;
}
+ @Override
+ public TypeDefinition getBaseType() {
+ return baseType;
+ }
+
@Override
public boolean isUnionType() {
return isUnionType;
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
import org.opendaylight.yangtools.sal.binding.model.api.Restrictions
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
import com.google.common.base.Preconditions
/**
«ENDIF»
«ENDFOR»
+ «IF (genTO.isTypedef() && genTO.getBaseType instanceof BitsTypeDefinition)»
+ «generateGetValueForBitsTypeDef»
+ «ENDIF»
+
«generateHashCode»
«generateEquals»
«generateRangeMethod("range", "_range")»
}
+
+ '''
+
+ /**
+ * Template method which generates the method <code>getValue()</code> for typedef,
+ * which base type is BitsDefinition.
+ *
+ * @return string with the <code>getValue()</code> method definition in JAVA format
+ */
+ def protected generateGetValueForBitsTypeDef() '''
+
+ public boolean[] getValue() {
+ return new boolean[]{
+ «FOR property: genTO.properties SEPARATOR ','»
+ «property.fieldName»
+ «ENDFOR»
+ };
+ }
'''
def private generateLengthMethod(String methodName, String varName) '''
package org.opendaylight.yangtools.sal.binding.model.api;
import java.util.List;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
/**
* Generated Transfer Object extends {@link GeneratedType} and is designed to
boolean isTypedef();
+ /**
+ * Returns Base type of Java representation of YANG typedef if set, otherwise it returns null
+ *
+ * @return Base type of Java representation of YANG typedef if set, otherwise it returns null
+ */
+ TypeDefinition getBaseType();
+
/**
* Return boolean value which describe whether Generated Transfer Object
* was/wasn't created from union YANG type.
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
/**
* Generated Transfer Object Builder is interface that contains methods to build
void setTypedef(boolean isTypedef);
+ /**
+ * Sets the base type for Java representation of YANG typedef
+ *
+ * @param typeDef
+ * Type Definition
+ */
+ void setBaseType(TypeDefinition typeDef);
+
/**
*
* @param isUnion
genTOBuilder.setReference(typeDef.getReference());
genTOBuilder.setSchemaPath(typeDef.getPath().getPathFromRoot());
genTOBuilder.setModuleName(moduleName);
+ genTOBuilder.setBaseType(typeDef);
final List<Bit> bitList = bitsTypeDefinition.getBits();
GeneratedPropertyBuilder genPropertyBuilder;
parser.parseFiles(Arrays.asList(extdef, unionbug, inet));
}
+ @Test
+ public void testUnionWithBits() throws Exception {
+ File unionbits = new File(getClass().getResource("/types/union-with-bits/union-bits-model.yang").toURI());
+ YangContextParser parser = new YangParserImpl();
+ parser.parseFiles(Arrays.asList(unionbits));
+ }
+
}
--- /dev/null
+module unionbitsmodel {
+ namespace "urn:ubt";
+ prefix "ubt";
+
+ revision 2014-12-10 {
+ }
+
+ typedef port-state-v13 {
+ description
+ "Current state of the physical port. These are not configurable from the controller.";
+
+ type bits {
+ bit link_down {
+ //description "No physical link present.";
+ position 0;
+ }
+
+ bit blocked {
+ //description "Port is blocked";
+ position 1;
+ }
+
+ bit live {
+ //description "Live for Fast Failover Group.";
+ position 2;
+ }
+ }
+ }
+
+ typedef port-state-v10 {
+ description "Current state of the physical port. These are not configurable from the controller.";
+
+ type bits {
+ bit link_down {
+ description "No physical link present.";
+ position 0;
+ }
+
+ bit blocked {
+ description "Port is blocked";
+ position 1;
+ }
+ bit live {
+ description "Live for Fast Failover Group.";
+ position 2;
+ }
+ bit stp_listen {
+ description "Not learning or relaying frames.";
+ }
+ }
+ }
+
+ typedef my-union-type {
+ type union {
+ type port-state-v13;
+ type port-state-v10;
+ }
+ }
+}
\ No newline at end of file