final Type rpcRes = Types.parameterizedTypeFor(
Types.typeForClass(RpcResult.class), outTypeInstance);
- method.addReturnType(Types.parameterizedTypeFor(future, rpcRes));
+ method.setReturnType(Types.parameterizedTypeFor(future, rpcRes));
for (DataNodeIterator it : rpcInOut) {
List<ContainerSchemaNode> nContainers = it.allContainers();
if ((nContainers != null) && !nContainers.isEmpty()) {
GeneratedTransferObject gto = new GeneratedTOBuilderImpl(
returnTypePkgName, returnTypeName).toInstance();
- newType.addExtendsType(gto);
+ newType.setExtendsType(gto);
} else {
- newType.addExtendsType(Types.getBaseIdentityTO());
+ newType.setExtendsType(Types.getBaseIdentityTO());
}
-
- return newType.toIdentityInstance();
+ newType.setAbstract(true);
+ return newType.toInstance();
}
private List<Type> allGroupingsToGenTypes(Module module) {
- final List<Type> genTypes = new ArrayList<Type>();
+ final List<Type> genTypes = new ArrayList<>();
final String basePackageName = moduleNamespaceToPackageName(module);
Set<GroupingDefinition> groupings = module.getGroupings();
if (groupings != null && !groupings.isEmpty()) {
.addProperty(parseToClassName(leafName));
propBuilder.setReadOnly(isReadOnly);
- propBuilder.addReturnType(returnType);
- propBuilder.addComment(leafDesc);
+ propBuilder.setReturnType(returnType);
+ propBuilder.setComment(leafDesc);
toBuilder.addEqualsIdentity(propBuilder);
toBuilder.addHashIdentity(propBuilder);
final MethodSignatureBuilder getMethod = interfaceBuilder
.addMethod(getterMethodName(schemaNodeName));
- getMethod.addComment(comment);
- getMethod.addReturnType(returnType);
+ getMethod.setComment(comment);
+ getMethod.setReturnType(returnType);
return getMethod;
}
final MethodSignatureBuilder setMethod = interfaceBuilder
.addMethod(setterMethodName(schemaNodeName));
- setMethod.addComment(comment);
+ setMethod.setComment(comment);
setMethod.addParameter(parameterType,
parseToValidParamName(schemaNodeName));
- setMethod.addReturnType(Types.voidType());
+ setMethod.setReturnType(Types.voidType());
return setMethod;
}
import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.*;
-import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.controller.yang.model.api.type.*;
+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.api.type.IdentityrefTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.controller.yang.model.util.ExtendedType;
import java.util.HashMap;
public void putReferencedType(final SchemaPath refTypePath,
final Type refType) {
if (refTypePath == null) {
- throw new IllegalArgumentException("Path reference of " +
- "Enumeration Type Definition cannot be NULL!");
+ throw new IllegalArgumentException("Path reference of "
+ + "Enumeration Type Definition cannot be NULL!");
}
if (refType == null) {
- throw new IllegalArgumentException("Reference to Enumeration " +
- "Type cannot be NULL!");
+ throw new IllegalArgumentException("Reference to Enumeration "
+ + "Type cannot be NULL!");
}
referencedTypes.put(refTypePath, refType);
}
final TypeDefinition<?> typeDefinition) {
Type returnType = null;
if (typeDefinition == null) {
- throw new IllegalArgumentException("Type Definition cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Type Definition cannot be NULL!");
}
if (typeDefinition.getQName() == null) {
- throw new IllegalArgumentException("Type Definition cannot have " +
- "non specified QName (QName cannot be NULL!)");
+ throw new IllegalArgumentException("Type Definition cannot have non specified QName (QName cannot be NULL!)");
}
if (typeDefinition.getQName().getLocalName() == null) {
- throw new IllegalArgumentException("Type Definitions Local Name " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!");
}
final String typedefName = typeDefinition.getQName().getLocalName();
if (typeDefinition instanceof ExtendedType) {
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) baseTypeDef;
returnType = provideTypeForLeafref(leafref);
} else if (baseTypeDef instanceof IdentityrefTypeDefinition) {
- final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition)typeDefinition;
+ final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) baseTypeDef;
returnType = returnTypeForIdentityref(idref);
} else if (baseTypeDef instanceof EnumTypeDefinition) {
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
returnType = resolveEnumFromTypeDefinition(enumTypeDef,
typedefName);
} else {
- final Module module = findParentModuleForTypeDefinition(schemaContext,
- typeDefinition);
+ final Module module = findParentModuleForTypeDefinition(
+ schemaContext, typeDefinition);
if (module != null) {
final Map<String, Type> genTOs = genTypeDefsContextMap
.get(module.getName());
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
returnType = provideTypeForLeafref(leafref);
} else if (typeDefinition instanceof IdentityrefTypeDefinition) {
- final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition)typeDefinition;
+ final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) typeDefinition;
returnType = returnTypeForIdentityref(idref);
} else {
returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
.javaTypeForSchemaDefinitionType(typeDefinition);
}
}
- //TODO: add throw exception when we will be able to resolve ALL yang
+ // TODO: add throw exception when we will be able to resolve ALL yang
// types!
-// if (returnType == null) {
-// throw new IllegalArgumentException("Type Provider can't resolve " +
-// "type for specified Type Definition " + typedefName);
-// }
+ // if (returnType == null) {
+ // throw new IllegalArgumentException("Type Provider can't resolve " +
+ // "type for specified Type Definition " + typedefName);
+ // }
return returnType;
}
-
+
private Type returnTypeForIdentityref(IdentityrefTypeDefinition idref) {
QName baseIdQName = idref.getIdentity();
Module module = schemaContext.findModuleByNamespace(baseIdQName.getNamespace());
IdentitySchemaNode identity = null;
- for(IdentitySchemaNode id : module.getIdentities()) {
- if(id.getQName().equals(baseIdQName)) {
+ for (IdentitySchemaNode id : module.getIdentities()) {
+ if (id.getQName().equals(baseIdQName)) {
identity = id;
}
}
- if(identity == null) {
+ if (identity == null) {
throw new IllegalArgumentException("Target identity '" + baseIdQName + "' do not exists");
}
final TypeDefinition<?> typeDefinition) {
Type returnType = null;
if (typeDefinition == null) {
- throw new IllegalArgumentException("Type Definition cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Type Definition cannot be NULL!");
}
if (typeDefinition.getQName() == null) {
- throw new IllegalArgumentException("Type Definition cannot have " +
- "non specified QName (QName cannot be NULL!)");
+ throw new IllegalArgumentException("Type Definition cannot have non specified QName (QName cannot be NULL!)");
}
if (typeDefinition.getQName() == null) {
- throw new IllegalArgumentException("Type Definitions Local Name " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("Type Definitions Local Name cannot be NULL!");
}
final String typedefName = typeDefinition.getQName().getLocalName();
if (!(baseTypeDef instanceof LeafrefTypeDefinition)
&& !(baseTypeDef instanceof IdentityrefTypeDefinition)) {
- final Module module = findParentModuleForTypeDefinition(schemaContext,
- typeDefinition);
+ final Module module = findParentModuleForTypeDefinition(
+ schemaContext, typeDefinition);
if (module != null) {
final Map<String, Type> genTOs = genTypeDefsContextMap
private TypeDefinition<?> baseTypeDefForExtendedType(
final TypeDefinition<?> extendTypeDef) {
if (extendTypeDef == null) {
- throw new IllegalArgumentException("Type Definiition reference " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("Type Definiition reference cannot be NULL!");
}
final TypeDefinition<?> baseTypeDef = extendTypeDef.getBaseType();
if (baseTypeDef instanceof ExtendedType) {
public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType) {
Type returnType = null;
if (leafrefType == null) {
- throw new IllegalArgumentException("Leafref Type Definition " +
- "reference cannot be NULL!");
+ throw new IllegalArgumentException("Leafref Type Definition reference cannot be NULL!");
}
if (leafrefType.getPathStatement() == null) {
- throw new IllegalArgumentException("The Path Statement for " +
- "Leafref Type Definition cannot be NULL!");
+ throw new IllegalArgumentException("The Path Statement for Leafref Type Definition cannot be NULL!");
}
final RevisionAwareXPath xpath = leafrefType.getPathStatement();
if (strXPath.matches(".*//[.* | .*//].*")) {
returnType = Types.typeForClass(Object.class);
} else {
- final Module module = findParentModuleForTypeDefinition(schemaContext, leafrefType);
+ final Module module = findParentModuleForTypeDefinition(
+ schemaContext, leafrefType);
if (module != null) {
final DataSchemaNode dataNode;
if (xpath.isAbsolute()) {
dataNode = findDataSchemaNode(schemaContext, module,
xpath);
} else {
- dataNode = findDataSchemaNodeForRelativeXPath(schemaContext,
- module, leafrefType, xpath);
+ dataNode = findDataSchemaNodeForRelativeXPath(
+ schemaContext, module, leafrefType, xpath);
}
if (leafContainsEnumDefinition(dataNode)) {
returnType = referencedTypes.get(dataNode.getPath());
} else if (leafListContainsEnumDefinition(dataNode)) {
- returnType = Types.listTypeFor(referencedTypes.get(
- dataNode.getPath()));
+ returnType = Types.listTypeFor(referencedTypes
+ .get(dataNode.getPath()));
} else {
returnType = resolveTypeFromDataSchemaNode(dataNode);
}
return false;
}
- private boolean leafListContainsEnumDefinition(
- final DataSchemaNode dataNode) {
+ private boolean leafListContainsEnumDefinition(final DataSchemaNode dataNode) {
if (dataNode instanceof LeafListSchemaNode) {
final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode;
if (leafList.getType() instanceof EnumTypeDefinition) {
private Enumeration resolveEnumFromTypeDefinition(
final EnumTypeDefinition enumTypeDef, final String enumName) {
if (enumTypeDef == null) {
- throw new IllegalArgumentException("EnumTypeDefinition reference " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!");
}
if (enumTypeDef.getValues() == null) {
- throw new IllegalArgumentException("EnumTypeDefinition MUST " +
- "contain at least ONE value definition!");
+ throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!");
}
if (enumTypeDef.getQName() == null) {
- throw new IllegalArgumentException("EnumTypeDefinition MUST " +
- "contain NON-NULL QName!");
+ throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!");
}
if (enumTypeDef.getQName().getLocalName() == null) {
- throw new IllegalArgumentException("Local Name in " +
- "EnumTypeDefinition QName cannot be NULL!");
+ throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!");
}
final String enumerationName = parseToClassName(enumName);
- Module module = findParentModuleForTypeDefinition(schemaContext, enumTypeDef);
+ Module module = findParentModuleForTypeDefinition(schemaContext,
+ enumTypeDef);
final String basePackageName = moduleNamespaceToPackageName(module);
final EnumBuilder enumBuilder = new EnumerationBuilderImpl(
final EnumTypeDefinition enumTypeDef, final String enumName,
final GeneratedTypeBuilder typeBuilder) {
if (enumTypeDef == null) {
- throw new IllegalArgumentException("EnumTypeDefinition reference " +
- "cannot be NULL!");
+ throw new IllegalArgumentException("EnumTypeDefinition reference cannot be NULL!");
}
if (enumTypeDef.getValues() == null) {
- throw new IllegalArgumentException("EnumTypeDefinition MUST " +
- "contain at least ONE value definition!");
+ throw new IllegalArgumentException("EnumTypeDefinition MUST contain at least ONE value definition!");
}
if (enumTypeDef.getQName() == null) {
- throw new IllegalArgumentException("EnumTypeDefinition MUST " +
- "contain NON-NULL QName!");
+ throw new IllegalArgumentException("EnumTypeDefinition MUST contain NON-NULL QName!");
}
if (enumTypeDef.getQName().getLocalName() == null) {
- throw new IllegalArgumentException("Local Name in " +
- "EnumTypeDefinition QName cannot be NULL!");
+ throw new IllegalArgumentException("Local Name in EnumTypeDefinition QName cannot be NULL!");
}
if (typeBuilder == null) {
- throw new IllegalArgumentException("Generated Type Builder " +
- "reference cannot be NULL!");
+ throw new IllegalArgumentException("Generated Type Builder reference cannot be NULL!");
}
final String enumerationName = parseToClassName(enumName);
}
private void updateEnumPairsFromEnumTypeDef(
- final EnumTypeDefinition enumTypeDef,
- final EnumBuilder enumBuilder) {
+ final EnumTypeDefinition enumTypeDef, final EnumBuilder enumBuilder) {
if (enumBuilder != null) {
final List<EnumPair> enums = enumTypeDef.getValues();
if (enums != null) {
private void resolveTypeDefsFromContext() {
final Set<Module> modules = schemaContext.getModules();
if (modules == null) {
- throw new IllegalArgumentException("Sef of Modules cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Sef of Modules cannot be NULL!");
}
for (final Module module : modules) {
if (module == null) {
final List<ExtendedType> extUnions = UnionDependencySort
.sort(typeDefinitions);
for (final ExtendedType extUnionType : extUnions) {
- addUnionGeneratedTypeDefinition(basePackageName, extUnionType);
+ addUnionGeneratedTypeDefinition(basePackageName,
+ extUnionType);
}
}
}
if ((basePackageName != null) && (moduleName != null)
&& (typedef != null) && (typedef.getQName() != null)) {
-
final String typedefName = typedef.getQName().getLocalName();
final TypeDefinition<?> baseTypeDefinition = baseTypeDefForExtendedType(typedef);
if (!(baseTypeDefinition instanceof LeafrefTypeDefinition)
returnType = resolveEnumFromTypeDefinition(enumTypeDef,
typedefName);
+ } else if (baseTypeDefinition instanceof BitsTypeDefinition) {
+ final BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) baseTypeDefinition;
+ returnType = bitsTypedefToTransferObject(bitsTypeDefinition,
+ basePackageName, typedefName);
+
} else {
final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
.javaTypeForSchemaDefinitionType(baseTypeDefinition);
javaType);
}
if (returnType != null) {
- final Map<String, Type> typeMap = genTypeDefsContextMap.get
- (moduleName);
+ final Map<String, Type> typeMap = genTypeDefsContextMap
+ .get(moduleName);
if (typeMap != null) {
typeMap.put(typedefName, returnType);
}
final GeneratedPropertyBuilder genPropBuilder = genTOBuilder
.addProperty(propertyName);
- genPropBuilder.addReturnType(javaType);
+ genPropBuilder.setReturnType(javaType);
genTOBuilder.addEqualsIdentity(genPropBuilder);
genTOBuilder.addHashIdentity(genPropBuilder);
genTOBuilder.addToStringProperty(genPropBuilder);
private void addUnionGeneratedTypeDefinition(final String basePackageName,
final TypeDefinition<?> typedef) {
if (basePackageName == null) {
- throw new IllegalArgumentException("Base Package Name cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
}
if (typedef == null) {
- throw new IllegalArgumentException("Type Definition cannot be " +
- "NULL!");
+ throw new IllegalArgumentException("Type Definition cannot be NULL!");
}
if (typedef.getQName() == null) {
- throw new IllegalArgumentException("Type Definition cannot have " +
- "non specified QName (QName cannot be NULL!)");
+ throw new IllegalArgumentException("Type Definition cannot have non specified QName (QName cannot be NULL!)");
}
final TypeDefinition<?> baseTypeDefinition = typedef.getBaseType();
if ((baseTypeDefinition != null)
&& (baseTypeDefinition instanceof UnionTypeDefinition)) {
final UnionTypeDefinition unionTypeDef = (UnionTypeDefinition) baseTypeDefinition;
- final List<TypeDefinition<?>> unionTypes = unionTypeDef
- .getTypes();
- final Module parentModule = findParentModuleForTypeDefinition(schemaContext,
- typedef);
+ final List<TypeDefinition<?>> unionTypes = unionTypeDef.getTypes();
+ final Module parentModule = findParentModuleForTypeDefinition(
+ schemaContext, typedef);
Map<String, Type> genTOsMap = null;
if (parentModule != null && parentModule.getName() != null) {
basePackageName, typedef);
if ((unionTypes != null) && (unionGenTransObject != null)) {
for (final TypeDefinition<?> unionType : unionTypes) {
- final String typeName = unionType.getQName()
- .getLocalName();
+ final String typeName = unionType.getQName().getLocalName();
if (unionType instanceof ExtendedType) {
- final Module unionTypeModule = findParentModuleForTypeDefinition(schemaContext,
- unionType);
- if (unionTypeModule != null && unionTypeModule.getName() != null) {
+ final Module unionTypeModule = findParentModuleForTypeDefinition(
+ schemaContext, unionType);
+ if (unionTypeModule != null
+ && unionTypeModule.getName() != null) {
final Map<String, Type> innerGenTOs = genTypeDefsContextMap
.get(unionTypeModule.getName());
- final GeneratedTransferObject genTransferObject =
- (GeneratedTransferObject) innerGenTOs.get(typeName);
+ final GeneratedTransferObject genTransferObject = (GeneratedTransferObject) innerGenTOs
+ .get(typeName);
if (genTransferObject != null) {
updateUnionTypeAsProperty(unionGenTransObject,
genTransferObject,
}
}
} else if (unionType instanceof EnumTypeDefinition) {
- final EnumBuilder
- enumBuilder = resolveInnerEnumFromTypeDefinition(
+ final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(
(EnumTypeDefinition) unionType, typeName,
unionGenTransObject);
final Type enumRefType = new ReferencedTypeImpl(
final GeneratedTOBuilder unionGenTransObject, final Type type,
final String propertyName) {
if (unionGenTransObject != null && type != null) {
- final GeneratedPropertyBuilder propBuilder =
- unionGenTransObject.addProperty(parseToValidParamName(
- propertyName));
- propBuilder.addReturnType(type);
+ final GeneratedPropertyBuilder propBuilder = unionGenTransObject
+ .addProperty(parseToValidParamName(propertyName));
+ propBuilder.setReturnType(type);
propBuilder.setReadOnly(false);
if (!(type instanceof Enumeration)) {
}
return null;
}
+
+ private GeneratedTransferObject bitsTypedefToTransferObject(
+ final BitsTypeDefinition bitsTypeDefinition, final String basePackageName, final String typedefName) {
+
+ if (bitsTypeDefinition == null) {
+ throw new IllegalArgumentException("Bits TypeDefinition cannot be NULL!");
+ }
+ if (basePackageName == null) {
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+ }
+ if (typedefName == null) {
+ throw new IllegalArgumentException("Type Definition Local Name cannot be NULL!");
+ }
+
+ final String typeDefName = parseToClassName(typedefName);
+ final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeDefName);
+
+ final List<Bit> bitList = bitsTypeDefinition.getBits();
+ GeneratedPropertyBuilder genPropertyBuilder;
+ for (final Bit bit : bitList) {
+ String name = bit.getName();
+ genPropertyBuilder = genTOBuilder.addProperty(parseToValidParamName(name));
+ genPropertyBuilder.setReadOnly(false);
+ genPropertyBuilder.setReturnType(BaseYangTypes.BOOLEAN_TYPE);
+
+ genTOBuilder.addEqualsIdentity(genPropertyBuilder);
+ genTOBuilder.addHashIdentity(genPropertyBuilder);
+ genTOBuilder.addToStringProperty(genPropertyBuilder);
+ }
+ return genTOBuilder.toInstance();
+ }
}
Enumeration linkUpDownTrapEnable = null;
Enumeration operStatus = null;
- final List<Enumeration> enums = genInterface.getEnumDefintions();
+ final List<Enumeration> enums = genInterface.getEnumerations();
assertNotNull("Generated Type Interface cannot contain NULL reference" +
" to Enumeration types!", enums);
assertEquals("Generated Type Interface MUST contain 2 Enumeration " +
import org.junit.Test;
import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
-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;
--- /dev/null
+package org.opendaylight.controller.sal.binding.generator.impl;
+
+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.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+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.MethodSignature.Parameter;
+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 GeneretedTypesBitsTest {
+
+ private SchemaContext resolveSchemaContextFromFiles(
+ final String... yangFiles) {
+ final YangModelParser parser = new YangParserImpl();
+
+ final List<File> inputFiles = new ArrayList<File>();
+ for (int i = 0; i < yangFiles.length; ++i) {
+ inputFiles.add(new File(yangFiles[i]));
+ }
+
+ final Set<Module> modules = parser.parseYangModels(inputFiles);
+ return parser.resolveSchemaContext(modules);
+ }
+
+ @Test
+ public void testGeneretedTypesBitsTest() {
+ final String yangTypesPath = getClass().getResource(
+ "/simple-bits-demo.yang").getPath();
+
+ final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
+ assertTrue(context != null);
+
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
+ final List<Type> genTypes = bindingGen.generateTypes(context);
+ assertTrue(genTypes != null);
+
+ List<MethodSignature> methodSignaturesList = null;
+
+ boolean leafParentFound = false;
+
+ boolean byteTypeFound = false;
+ int classPropertiesNumb = 0;
+ int toStringPropertiesNum = 0;
+ int equalPropertiesNum = 0;
+ int hashPropertiesNum = 0;
+
+ String nameReturnParamType = "";
+ String nameMethodeParamType = "";
+ boolean getByteLeafMethodFound = false;
+ boolean setByteLeafMethodFound = false;
+ int setByteLeafMethodParamNum = 0;
+
+ for (final Type type : genTypes) {
+ if (type instanceof GeneratedTransferObject) { // searching for
+ // ByteType
+ final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
+ if (genTO.getName().equals("ByteType")) {
+ byteTypeFound = true;
+ List<GeneratedProperty> genProperties = genTO
+ .getProperties();
+ classPropertiesNumb = genProperties.size();
+
+ genProperties = null;
+ genProperties = genTO.getToStringIdentifiers();
+ toStringPropertiesNum = genProperties.size();
+
+ genProperties = null;
+ genProperties = genTO.getEqualsIdentifiers();
+ equalPropertiesNum = genProperties.size();
+
+ genProperties = null;
+ genProperties = genTO.getHashCodeIdentifiers();
+ hashPropertiesNum = genProperties.size();
+
+ }
+ } else if (type instanceof GeneratedType) { // searching for
+ // interface
+ // LeafParameterContainer
+ final GeneratedType genType = (GeneratedType) type;
+ if (genType.getName().compareTo("LeafParentContainer") == 0) {
+ 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) {
+ getByteLeafMethodFound = true;
+
+ nameReturnParamType = methodSignature
+ .getReturnType().getName();
+ } else if (methodSignature.getName().compareTo(
+ "setByteLeaf") == 0) {
+ setByteLeafMethodFound = true;
+
+ List<Parameter> parameters = methodSignature
+ .getParameters();
+ setByteLeafMethodParamNum = parameters.size();
+ for (Parameter parameter : parameters) {
+ nameMethodeParamType = parameter.getType()
+ .getName();
+ }
+
+ }
+
+ }
+ }
+ }
+ }
+
+ }
+
+ 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);
+
+ }
+
+}
\ No newline at end of file
--- /dev/null
+module simple-bits-demo {
+
+ namespace "urn:simple:bits:demo";
+ prefix "sbd";
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision 2013-06-11 {
+
+ }
+
+ typedef byte-type {
+ type bits {
+ bit first-bit {
+ position 10;
+ }
+ bit second-bit {
+ position 20;
+ }
+ bit third-bit {
+ position 30;
+ }
+ bit forth-bit {
+ position 40;
+ }
+ bit fifth-bit {
+ position 50;
+ }
+ bit sixth-bit {
+ position 60;
+ }
+ bit seventh-bit {
+ position 70;
+ }
+ bit eight-bit {
+ position 80;
+ }
+
+ }
+
+ typedef jo {
+ type uint32;
+ }
+
+
+ container leaf-parent-container {
+ leaf byte-leaf {
+ type byte-type;
+ }
+
+ }
+
+}
\ No newline at end of file
return name;\r
}\r
\r
+ @Override\r
+ public String getFullyQualifiedName() {\r
+ if (packageName.isEmpty()) {\r
+ return name;\r
+ } else {\r
+ return packageName + "." + name;\r
+ }\r
+ }\r
+\r
protected AbstractBaseType(String pkName, String name) {\r
this.packageName = pkName;\r
this.name = name;\r
}\r
return "Type (" + packageName + "." + name + ")";\r
}\r
-\r
}\r
*/
package org.opendaylight.controller.binding.generator.util;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+public final class ReferencedTypeImpl extends AbstractBaseType {
-
-public final class ReferencedTypeImpl implements Type {
-
- private final String packageName;
- private final String name;
-
public ReferencedTypeImpl(String packageName, String name) {
- super();
- this.packageName = packageName;
- this.name = name;
- }
-
- /* (non-Javadoc)
- * @see org.opendaylight.controller.sal.binding.model.api.Type#getPackageName()
- */
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- /* (non-Javadoc)
- * @see org.opendaylight.controller.sal.binding.model.api.Type#getName()
- */
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((packageName == null) ? 0 : packageName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- ReferencedTypeImpl other = (ReferencedTypeImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (packageName == null) {
- if (other.packageName != null) {
- return false;
- }
- } else if (!packageName.equals(other.packageName)) {
- return false;
- }
- return true;
+ super(packageName, name);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ReferencedTypeImpl [packageName=");
- builder.append(packageName);
+ builder.append(getPackageName());
builder.append(", name=");
- builder.append(name);
+ builder.append(getName());
builder.append("]");
return builder.toString();
}
--- /dev/null
+/*
+ * 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.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 java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+abstract class AbstractGeneratedType extends AbstractBaseType implements GeneratedType {
+
+ private final Type parent;
+ private final String comment;
+ private final List<AnnotationType> annotations;
+ private final List<Type> implementsTypes;
+ private final List<Enumeration> enumerations;
+ private final List<Constant> constants;
+ private final List<MethodSignature> methodSignatures;
+ 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) {
+ super(packageName, name);
+ this.parent = parent;
+ this.comment = comment;
+ this.annotations = toUnmodifiableAnnotations(annotationBuilders);
+ this.implementsTypes = Collections.unmodifiableList(implementsTypes);
+ this.constants = toUnmodifiableConstants(constants);
+ this.enumerations = toUnmodifiableEnumerations(enumBuilders);
+ this.methodSignatures = toUnmodifiableMethods(methodBuilders);
+ this.enclosedTypes = toUnmodifiableEnclosedTypes(enclosedGenTypeBuilders, enclosedGenTOBuilders);
+ this.isAbstract = isAbstract;
+ }
+
+ private List<GeneratedType> toUnmodifiableEnclosedTypes(final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
+ final List<GeneratedTOBuilder> enclosedGenTOBuilders) {
+ final List<GeneratedType> enclosedTypes = new ArrayList<>();
+ for (final GeneratedTypeBuilder builder : enclosedGenTypeBuilders) {
+ if (builder != null) {
+ enclosedTypes.add(builder.toInstance());
+ }
+ }
+
+ for (final GeneratedTOBuilder builder : enclosedGenTOBuilders) {
+ if (builder != null) {
+ enclosedTypes.add(builder.toInstance());
+ }
+ }
+ return enclosedTypes;
+ }
+
+ protected List<AnnotationType> toUnmodifiableAnnotations(
+ final List<AnnotationTypeBuilder> annotationBuilders) {
+ final List<AnnotationType> annotations = new ArrayList<>();
+ for (final AnnotationTypeBuilder builder : annotationBuilders) {
+ annotations.add(builder.toInstance());
+ }
+ return Collections.unmodifiableList(annotations);
+ }
+
+ protected List<MethodSignature> toUnmodifiableMethods(
+ List<MethodSignatureBuilder> methodBuilders) {
+ final List<MethodSignature> methods = new ArrayList<>();
+ for (final MethodSignatureBuilder methodBuilder : methodBuilders) {
+ methods.add(methodBuilder.toInstance(this));
+ }
+ return Collections.unmodifiableList(methods);
+ }
+
+ protected List<Enumeration> toUnmodifiableEnumerations(
+ List<EnumBuilder> enumBuilders) {
+ final List<Enumeration> enums = new ArrayList<>();
+ for (final EnumBuilder enumBuilder : enumBuilders) {
+ enums.add(enumBuilder.toInstance(this));
+ }
+ return Collections.unmodifiableList(enums);
+ }
+
+ protected List<Constant> toUnmodifiableConstants(
+ List<Constant> constants) {
+ for (final Constant constant : constants) {
+ constants.add(new ConstantImpl(this, constant.getType(),
+ constant.getName(), constant.getValue()));
+ }
+ return Collections.unmodifiableList(constants);
+ }
+
+ @Override
+ public Type getParentType() {
+ return parent;
+ }
+
+ @Override
+ public String getComment() {
+ return comment;
+ }
+
+ @Override
+ public List<AnnotationType> getAnnotations() {
+ return annotations;
+ }
+
+ @Override
+ public boolean isAbstract() {
+ return isAbstract;
+ }
+
+ @Override
+ public List<Type> getImplements() {
+ return implementsTypes;
+ }
+
+ @Override
+ public List<GeneratedType> getEnclosedTypes() {
+ return enclosedTypes;
+ }
+
+ @Override
+ public List<Enumeration> getEnumerations() {
+ return enumerations;
+ }
+
+ @Override
+ public List<Constant> getConstantDefinitions() {
+ return constants;
+ }
+
+ @Override
+ public List<MethodSignature> getMethodDefinitions() {
+ return methodSignatures;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedType [packageName=");
+ builder.append(getPackageName());
+ builder.append(", name=");
+ builder.append(getName());
+ if (parent != null) {
+ builder.append(", parent=");
+ builder.append(parent.getFullyQualifiedName());
+ } else {
+ builder.append(", parent=null");
+ }
+ builder.append(", comment=");
+ builder.append(comment);
+ builder.append(", annotations=");
+ builder.append(annotations);
+ builder.append(", enclosedTypes=");
+ builder.append(enclosedTypes);
+ builder.append(", enumerations=");
+ builder.append(enumerations);
+ builder.append(", constants=");
+ builder.append(constants);
+ builder.append(", methodSignatures=");
+ builder.append(methodSignatures);
+ builder.append("]");
+ return builder.toString();
+ }
+}
--- /dev/null
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+abstract class AbstractGeneratedTypeBuilder implements GeneratedTypeBuilder {
+
+ private final String packageName;
+ private String comment = "";
+ private final String name;
+
+ private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<>();
+ private final List<Type> implementsTypes = new ArrayList<>();
+ private final List<EnumBuilder> enumDefinitions = new ArrayList<>();
+ private final List<Constant> constants = new ArrayList<>();
+ private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<>();
+ private final List<GeneratedTypeBuilder> enclosedTypes = new ArrayList<>();
+ private final List<GeneratedTOBuilder> enclosingTransferObjects = new ArrayList<>();
+ private boolean isAbstract;
+
+ public AbstractGeneratedTypeBuilder(final String packageName, final String name) {
+ if (packageName == null) {
+ throw new IllegalArgumentException("Package Name for Generated Type cannot be null!");
+ }
+ if (name == null) {
+ throw new IllegalArgumentException("Name of Generated Type cannot be null!");
+ }
+ this.packageName = packageName;
+ this.name = name;
+ }
+
+ @Override
+ public String getPackageName() {
+ return packageName;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getFullyQualifiedName() {
+ return packageName + "." + name;
+ }
+
+
+ protected String getComment() {
+ return comment;
+ }
+
+ protected List<AnnotationTypeBuilder> getAnnotations() {
+ return annotationBuilders;
+ }
+
+ protected boolean isAbstract() {
+ return isAbstract;
+ }
+
+ protected List<Type> getImplementsTypes() {
+ return implementsTypes;
+ }
+
+ protected List<EnumBuilder> getEnumerations() {
+ return enumDefinitions;
+ }
+
+ protected List<Constant> getConstants() {
+ return constants;
+ }
+
+ protected List<MethodSignatureBuilder> getMethodDefinitions() {
+ return methodDefinitions;
+ }
+
+ protected List<GeneratedTypeBuilder> getEnclosedTypes() {
+ return enclosedTypes;
+ }
+
+ protected List<GeneratedTOBuilder> getEnclosedTransferObjects() {
+ return enclosingTransferObjects;
+ }
+
+ @Override
+ public GeneratedTypeBuilder addEnclosingType(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name for Enclosing Generated Type cannot be null!");
+ }
+ GeneratedTypeBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
+ enclosedTypes.add(builder);
+ return builder;
+ }
+
+ @Override
+ public GeneratedTOBuilder addEnclosingTransferObject(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name for Enclosing Generated Transfer Object cannot be null!");
+ }
+ GeneratedTOBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
+ enclosingTransferObjects.add(builder);
+ return builder;
+ }
+
+ @Override
+ public void addComment(String comment) {
+ this.comment = comment;
+ }
+
+ @Override
+ public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
+ if (packageName == null) {
+ throw new IllegalArgumentException("Package Name for Annotation Type cannot be null!");
+ }
+ if (name == null) {
+ throw new IllegalArgumentException("Name of Annotation Type cannot be null!");
+ }
+
+ final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name);
+ annotationBuilders.add(builder);
+ return builder;
+ }
+
+ @Override
+ public void setAbstract(boolean isAbstract) {
+ this.isAbstract = isAbstract;
+ }
+
+ @Override
+ public boolean addImplementsType(Type genType) {
+ if (genType == null) {
+ throw new IllegalArgumentException("Type cannot be null");
+ }
+ return implementsTypes.add(genType);
+ }
+
+ @Override
+ public Constant addConstant(Type type, String name, Object value) {
+ if (type == null) {
+ throw new IllegalArgumentException("Returning Type for Constant cannot be null!");
+ }
+ if (name == null) {
+ throw new IllegalArgumentException("Name of constant cannot be null!");
+ }
+
+ final Constant constant = new ConstantImpl(this, type, name, value);
+ constants.add(constant);
+ return constant;
+ }
+
+ @Override
+ public EnumBuilder addEnumeration(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name of enumeration cannot be null!");
+ }
+ final EnumBuilder builder = new EnumerationBuilderImpl(
+ getFullyQualifiedName(), name);
+ enumDefinitions.add(builder);
+ return builder;
+ }
+
+ @Override
+ public MethodSignatureBuilder addMethod(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name of method cannot be null!");
+ }
+ final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(name);
+ builder.setAccessModifier(AccessModifier.PUBLIC);
+ builder.setAbstract(true);
+ methodDefinitions.add(builder);
+ return builder;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result
+ + ((getPackageName() == null) ? 0 : getPackageName().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ AbstractGeneratedTypeBuilder other = (AbstractGeneratedTypeBuilder) obj;
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ if (getPackageName() == null) {
+ if (other.getPackageName() != null) {
+ return false;
+ }
+ } else if (!getPackageName().equals(other.getPackageName())) {
+ return false;
+ }
+ return true;
+ }
+}
--- /dev/null
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
+
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.TypeMember;
+
+import java.util.Collections;
+import java.util.List;
+
+abstract class AbstractTypeMember implements TypeMember {
+
+ private final String name;
+ private final String comment;
+ private final Type definingType;
+ private final Type returnType;
+ private final List<AnnotationType> annotations;
+ private final boolean isFinal;
+ private final AccessModifier accessModifier;
+
+ public AbstractTypeMember(final Type definingType, final String name, final List<AnnotationType> annotations,
+ final String comment, final AccessModifier accessModifier, final Type returnType,
+ boolean isFinal) {
+ super();
+ this.definingType = definingType;
+ this.name = name;
+ this.annotations = Collections.unmodifiableList(annotations);
+ this.comment = comment;
+ this.accessModifier = accessModifier;
+ this.returnType = returnType;
+ this.isFinal = isFinal;
+ }
+
+ @Override
+ public List<AnnotationType> getAnnotations() {
+ return annotations;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getComment() {
+ return comment;
+ }
+
+ @Override
+ public Type getDefiningType() {
+ return definingType;
+ }
+
+ @Override
+ public AccessModifier getAccessModifier() {
+ return accessModifier;
+ }
+
+ @Override
+ public Type getReturnType() {
+ return returnType;
+ }
+
+ @Override
+ public boolean isFinal() {
+ return isFinal;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result
+ + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MethodSignatureImpl other = (MethodSignatureImpl) obj;
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ if (getReturnType() == null) {
+ if (other.getReturnType() != null) {
+ return false;
+ }
+ } else if (!getReturnType().equals(other.getReturnType())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("MethodSignatureImpl [name=");
+ builder.append(getName());
+ builder.append(", comment=");
+ builder.append(getComment());
+ if (getDefiningType() != null) {
+ builder.append(", definingType=");
+ builder.append(getDefiningType().getPackageName());
+ builder.append(".");
+ builder.append(getDefiningType().getName());
+ } else {
+ builder.append(", definingType= null");
+ }
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append("]");
+ return builder.toString();
+ }
+}
--- /dev/null
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.TypeMemberBuilder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+abstract class AbstractTypeMemberBuilder implements TypeMemberBuilder {
+ private final String name;
+ private Type returnType;
+ private final List<AnnotationTypeBuilder> annotationBuilders;
+ private String comment = "";
+ private boolean isFinal;
+ private AccessModifier accessModifier;
+
+ public AbstractTypeMemberBuilder(final String name) {
+ this.name = name;
+ this.annotationBuilders = new ArrayList<>();
+ }
+
+ @Override
+ public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
+ if (packageName == null) {
+ throw new IllegalArgumentException("Annotation Type cannot have package name null!");
+ }
+ if (name == null) {
+ throw new IllegalArgumentException("Annotation Type cannot have name as null!");
+ }
+ final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
+ packageName, name);
+ annotationBuilders.add(builder);
+ return builder;
+ }
+
+ protected Type getReturnType() {
+ return returnType;
+ }
+
+ protected List<AnnotationTypeBuilder> getAnnotationBuilders() {
+ return annotationBuilders;
+ }
+
+ protected String getComment() {
+ return comment;
+ }
+
+ protected boolean isFinal() {
+ return isFinal;
+ }
+
+ protected AccessModifier getAccessModifier() {
+ return accessModifier;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setReturnType(Type returnType) {
+ if (returnType == null) {
+ throw new IllegalArgumentException("Return Type of member cannot be null!");
+ }
+ this.returnType = returnType;
+ }
+
+ @Override
+ public void setAccessModifier(AccessModifier modifier) {
+ if (modifier == null) {
+ throw new IllegalArgumentException("Access Modifier for member type cannot be null!");
+ }
+ this.accessModifier = modifier;
+ }
+
+ @Override
+ public void setComment(String comment) {
+ if (comment == null) {
+ throw new IllegalArgumentException("Comment string cannot be null!");
+ }
+ this.comment = comment;
+ }
+
+ @Override
+ public void setFinal(boolean isFinal) {
+ this.isFinal = isFinal;
+ }
+
+ protected List<AnnotationType> toAnnotationTypes() {
+ final List<AnnotationType> annotations = new ArrayList<>();
+ for (final AnnotationTypeBuilder annotBuilder : getAnnotationBuilders()) {
+ if (annotBuilder != null) {
+ annotations.add(annotBuilder.toInstance());
+ }
+ }
+ return annotations;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result
+ + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ if (getReturnType() == null) {
+ if (other.getReturnType() != null) {
+ return false;
+ }
+ } else if (!getReturnType().equals(other.getReturnType())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedPropertyImpl [name=");
+ builder.append(getName());
+ builder.append(", annotations=");
+ builder.append(getAnnotationBuilders());
+ builder.append(", comment=");
+ builder.append(getComment());
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", isFinal=");
+ builder.append(isFinal());
+ builder.append(", modifier=");
+ builder.append(getAccessModifier());
+ builder.append("]");
+ return builder.toString();
+ }
+}
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
import java.util.ArrayList;
super();
this.packageName = packageName;
this.name = name;
-
- annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
- parameters = new ArrayList<AnnotationType.Parameter>();
+ annotationBuilders = new ArrayList<>();
+ parameters = new ArrayList<>();
}
@Override
return name;
}
+ @Override
+ public String getFullyQualifiedName() {
+ return packageName + "." + name;
+ }
+
@Override
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
if (packageName != null && name != null) {
this.packageName = packageName;
this.name = name;
- this.annotations = new ArrayList<AnnotationType>();
+ this.annotations = new ArrayList<>();
for (final AnnotationTypeBuilder builder : annotationBuilders) {
annotations.add(builder.toInstance());
}
this.annotations = Collections.unmodifiableList(annotations);
this.parameters = Collections.unmodifiableList(parameters);
- paramNames = new ArrayList<String>();
+ paramNames = new ArrayList<>();
for (final AnnotationType.Parameter parameter : parameters) {
paramNames.add(parameter.getName());
}
return name;
}
+ @Override
+ public String getFullyQualifiedName() {
+ return packageName + "." + name;
+ }
+
@Override
public List<AnnotationType> getAnnotations() {
return annotations;
+++ /dev/null
-/*
- * 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.controller.binding.generator.util.generated.type.builder;
-
-import org.opendaylight.controller.sal.binding.model.api.Constant;
-import org.opendaylight.controller.sal.binding.model.api.Type;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
-
-final class ConstantBuilderImpl implements ConstantBuilder {
-
- private final Type type;
- private final String name;
- private Object value;
-
- public ConstantBuilderImpl(Type type, String name, Object value) {
- super();
- this.type = type;
- this.name = name;
- this.value = value;
- }
-
- public ConstantBuilderImpl(Type type, String name) {
- super();
- this.type = type;
- this.name = name;
- }
-
- @Override
- public void assignValue(Object value) {
- this.value = value;
- }
-
- @Override
- public Constant toInstance(final Type definingType) {
- return new ConstantImpl(definingType, type, name, value);
- }
-
- private static final class ConstantImpl implements Constant {
-
- final Type definingType;
- private final Type type;
- private final String name;
- private final Object value;
-
- public ConstantImpl(final Type definingType, final Type type,
- final String name, final Object value) {
- super();
- this.definingType = definingType;
- this.type = type;
- this.name = name;
- this.value = value;
- }
-
- @Override
- public Type getDefiningType() {
- return definingType;
- }
-
- @Override
- public Type getType() {
- return type;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Object getValue() {
- return value;
- }
-
- @Override
- public String toFormattedString() {
- StringBuilder builder = new StringBuilder();
- builder.append(type);
- builder.append(" ");
- builder.append(name);
- builder.append(" ");
- builder.append(value);
- return builder.toString();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- ConstantImpl other = (ConstantImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
- if (value == null) {
- if (other.value != null) {
- return false;
- }
- } else if (!value.equals(other.value)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Constant [type=");
- builder.append(type);
- builder.append(", name=");
- builder.append(name);
- builder.append(", value=");
- builder.append(value);
- if (definingType != null) {
- builder.append(", definingType=");
- builder.append(definingType.getPackageName());
- builder.append(".");
- builder.append(definingType.getName());
- } else {
- builder.append(", definingType= null");
- }
- builder.append("]");
- return builder.toString();
- }
- }
-}
--- /dev/null
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.Constant;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+final class ConstantImpl implements Constant {
+
+ final Type definingType;
+ private final Type type;
+ private final String name;
+ private final Object value;
+
+ public ConstantImpl(final Type definingType, final Type type,
+ final String name, final Object value) {
+ super();
+ this.definingType = definingType;
+ this.type = type;
+ this.name = name;
+ this.value = value;
+ }
+
+ @Override
+ public Type getDefiningType() {
+ return definingType;
+ }
+
+ @Override
+ public Type getType() {
+ return type;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Object getValue() {
+ return value;
+ }
+
+ @Override
+ public String toFormattedString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(type);
+ builder.append(" ");
+ builder.append(name);
+ builder.append(" ");
+ builder.append(value);
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ConstantImpl other = (ConstantImpl) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (type == null) {
+ if (other.type != null) {
+ return false;
+ }
+ } else if (!type.equals(other.type)) {
+ return false;
+ }
+ if (value == null) {
+ if (other.value != null) {
+ return false;
+ }
+ } else if (!value.equals(other.value)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Constant [type=");
+ builder.append(type);
+ builder.append(", name=");
+ builder.append(name);
+ builder.append(", value=");
+ builder.append(value);
+ if (definingType != null) {
+ builder.append(", definingType=");
+ builder.append(definingType.getPackageName());
+ builder.append(".");
+ builder.append(definingType.getName());
+ } else {
+ builder.append(", definingType= null");
+ }
+ builder.append("]");
+ return builder.toString();
+ }
+}
super();
this.packageName = packageName;
this.name = name;
- values = new ArrayList<Enumeration.Pair>();
+ values = new ArrayList<>();
}
@Override
public String getName() {
return name;
}
-
+
+ @Override
+ public String getFullyQualifiedName() {
+ return packageName + "." + name;
+ }
+
@Override
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
if (packageName != null && name != null) {
private final String packageName;
private final String name;
private final List<Pair> values;
- private List<AnnotationType> annotations = new ArrayList<AnnotationType>();
+ private List<AnnotationType> annotations = new ArrayList<>();
public EnumerationImpl(final Type definingType,
final List<AnnotationTypeBuilder> annotationBuilders,
return name;
}
+ @Override
+ public String getFullyQualifiedName() {
+ return packageName + "." + name;
+ }
+
@Override
public List<Pair> getValues() {
return values;
--- /dev/null
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
+
+import java.util.List;
+
+final class GeneratedPropertyBuilderImpl extends AbstractTypeMemberBuilder implements GeneratedPropertyBuilder {
+
+ private boolean isReadOnly;
+
+ public GeneratedPropertyBuilderImpl(String name) {
+ super(name);
+ }
+
+ @Override
+ public void setReadOnly(boolean isReadOnly) {
+ this.isReadOnly = isReadOnly;
+ }
+
+ @Override
+ public GeneratedProperty toInstance(Type definingType) {
+ final List<AnnotationType> annotations = toAnnotationTypes();
+ return new GeneratedPropertyImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
+ getReturnType(), isFinal(), isReadOnly);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedPropertyImpl [name=");
+ builder.append(getName());
+ builder.append(", annotations=");
+ builder.append(getAnnotationBuilders());
+ builder.append(", comment=");
+ builder.append(getComment());
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", isFinal=");
+ builder.append(isFinal());
+ builder.append(", isReadOnly=");
+ builder.append(isReadOnly);
+ builder.append(", modifier=");
+ builder.append(getAccessModifier());
+ builder.append("]");
+ return builder.toString();
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+import java.util.List;
+
+final class GeneratedPropertyImpl extends AbstractTypeMember implements GeneratedProperty {
+
+ private boolean isReadOnly;
+
+ public GeneratedPropertyImpl(Type definingType, String name, List<AnnotationType> annotations, String comment,
+ AccessModifier accessModifier, Type returnType, boolean isFinal, boolean isReadOnly) {
+ super(definingType, name, annotations, comment, accessModifier, returnType, isFinal);
+ this.isReadOnly = isReadOnly;
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return isReadOnly;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedPropertyImpl [name=");
+ builder.append(getName());
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append(", comment=");
+ builder.append(getComment());
+ if (getDefiningType() != null) {
+ builder.append(", parent=");
+ builder.append(getDefiningType().getPackageName());
+ builder.append(".");
+ builder.append(getDefiningType().getName());
+ } else {
+ builder.append(", parent=null");
+ }
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", isFinal=");
+ builder.append(isFinal());
+ builder.append(", isReadOnly=");
+ builder.append(isReadOnly);
+ builder.append(", modifier=");
+ builder.append(getAccessModifier());
+ builder.append("]");
+ return builder.toString();
+ }
+}
*/
package org.opendaylight.controller.binding.generator.util.generated.type.builder;
+import org.opendaylight.controller.sal.binding.model.api.*;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
-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.GeneratedProperty;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferIdentityObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-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;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
-
-public class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
- private String packageName;
- private final String name;
- private String comment = "";
+public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder implements GeneratedTOBuilder {
private GeneratedTransferObject extendsType;
- private final List<Type> implementsTypes = new ArrayList<Type>();
- private final List<EnumBuilder> enumerations = new ArrayList<EnumBuilder>();
- private final List<GeneratedPropertyBuilder> properties = new ArrayList<GeneratedPropertyBuilder>();
- private final List<GeneratedPropertyBuilder> equalsProperties = new ArrayList<GeneratedPropertyBuilder>();
- private final List<GeneratedPropertyBuilder> hashProperties = new ArrayList<GeneratedPropertyBuilder>();
- private final List<GeneratedPropertyBuilder> toStringProperties = new ArrayList<GeneratedPropertyBuilder>();
-
- private final List<ConstantBuilder> constantDefintions = new ArrayList<ConstantBuilder>();
- private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<MethodSignatureBuilder>();
- private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
+ private final List<GeneratedPropertyBuilder> properties = new ArrayList<>();
+ private final List<GeneratedPropertyBuilder> equalsProperties = new ArrayList<>();
+ private final List<GeneratedPropertyBuilder> hashProperties = new ArrayList<>();
+ private final List<GeneratedPropertyBuilder> toStringProperties = new ArrayList<>();
public GeneratedTOBuilderImpl(String packageName, String name) {
- super();
- this.packageName = packageName;
- this.name = name;
- }
-
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Type getParentType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void addComment(final String comment) {
- this.comment = comment;
- }
-
- @Override
- public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
- if (packageName != null && name != null) {
- final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
- packageName, name);
- if (annotationBuilders.add(builder)) {
- return builder;
- }
- }
- return null;
- }
-
- @Override
- public boolean addImplementsType(final Type genType) {
- if (genType != null) {
- return implementsTypes.add(genType);
- }
- return false;
+ super(packageName, name);
+ setAbstract(false);
}
@Override
- public boolean addExtendsType(final GeneratedTransferObject genTransObj) {
- if (genTransObj != null) {
- extendsType = genTransObj;
- return true;
+ public void setExtendsType(final GeneratedTransferObject genTransObj) {
+ if (genTransObj == null) {
+ throw new IllegalArgumentException("Generated Transfer Object cannot be null!");
}
- return false;
- }
-
- @Override
- public EnumBuilder addEnumeration(String name) {
- final String innerPackageName = packageName + "." + this.name;
- final EnumBuilder builder = new EnumerationBuilderImpl(innerPackageName,
- name);
- enumerations.add(builder);
- return builder;
+ extendsType = genTransObj;
}
@Override
- public ConstantBuilder addConstant(Type type, String name, Object value) {
- final ConstantBuilder builder = new ConstantBuilderImpl(type, name,
- value);
- constantDefintions.add(builder);
+ public GeneratedPropertyBuilder addProperty(String name) {
+ final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(name);
+ builder.setAccessModifier(AccessModifier.PUBLIC);
+ properties.add(builder);
return builder;
}
+ /**
+ * Add new Method Signature definition for Generated Type Builder and
+ * returns Method Signature Builder for specifying all Method parameters.
+ * <br>
+ * Name of Method cannot be <code>null</code>,
+ * if it is <code>null</code> the method SHOULD throw {@link IllegalArgumentException}
+ * <br>
+ * By <i>Default</i> the MethodSignatureBuilder SHOULD be pre-set as
+ * {@link MethodSignatureBuilder#setAbstract(false)}, {@link MethodSignatureBuilder#setFinal(false)} and
+ * {@link MethodSignatureBuilder#setAccessModifier(PUBLIC)}
+ *
+ * @param name Name of Method
+ * @return <code>new</code> instance of Method Signature Builder.
+ */
@Override
public MethodSignatureBuilder addMethod(String name) {
- final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(
- this, name);
- methodDefinitions.add(builder);
- return builder;
- }
-
- @Override
- public GeneratedPropertyBuilder addProperty(String name) {
- final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(
- name);
- properties.add(builder);
+ final MethodSignatureBuilder builder = super.addMethod(name);
+ builder.setAbstract(false);
return builder;
}
@Override
public GeneratedTransferObject toInstance() {
- return new GeneratedTransferObjectImpl(packageName, name, comment,
- annotationBuilders, extendsType, implementsTypes,
- constantDefintions, enumerations, methodDefinitions,
- properties, equalsProperties, hashProperties,
- toStringProperties);
- }
-
- @Override
- public GeneratedTransferObject toIdentityInstance() {
- return new GeneratedTransferIdentityObjectImpl(packageName, name, comment,
- annotationBuilders, extendsType, implementsTypes,
- constantDefintions, enumerations, methodDefinitions,
- properties, equalsProperties, hashProperties,
- toStringProperties);
- }
-
- private static final class GeneratedPropertyBuilderImpl implements
- GeneratedPropertyBuilder {
-
- private final String name;
- private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
- private Type returnType;
- private final List<MethodSignature.Parameter> parameters;
- private String comment = "";
- private AccessModifier accessModifier;
- private boolean isFinal;
- private boolean isReadOnly;
-
- public GeneratedPropertyBuilderImpl(final String name) {
- super();
- this.name = name;
- parameters = new ArrayList<MethodSignature.Parameter>();
- isFinal = true;
- this.isReadOnly = true;
- accessModifier = AccessModifier.PUBLIC;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public AnnotationTypeBuilder addAnnotation(String packageName,
- String name) {
- if (packageName != null && name != null) {
- final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
- packageName, name);
- if (annotationBuilders.add(builder)) {
- return builder;
- }
- }
- return null;
- }
-
- @Override
- public boolean addReturnType(Type returnType) {
- if (returnType != null) {
- this.returnType = returnType;
- this.parameters.add(new MethodParameterImpl(name, returnType));
- return true;
- }
- return false;
- }
-
- @Override
- public void accessorModifier(final AccessModifier modifier) {
- accessModifier = modifier;
- }
-
- @Override
- public void addComment(String comment) {
- if (comment != null) {
- this.comment = comment;
- }
- }
-
- @Override
- public void setFinal(boolean isFinal) {
- this.isFinal = isFinal;
- }
-
- @Override
- public void setReadOnly(boolean isReadOnly) {
- this.isReadOnly = isReadOnly;
- }
-
- @Override
- public GeneratedProperty toInstance(final Type definingType) {
- return new GeneratedPropertyImpl(name, comment, annotationBuilders,
- definingType, returnType, isFinal, isReadOnly, parameters,
- accessModifier);
- }
- }
-
- private static final class GeneratedPropertyImpl implements
- GeneratedProperty {
-
- private final String name;
- private List<AnnotationType> annotations;
- private final String comment;
- private final Type parent;
- private final Type returnType;
- private final boolean isFinal;
- private final boolean isReadOnly;
- private final List<MethodSignature.Parameter> parameters;
- private final AccessModifier modifier;
-
- public GeneratedPropertyImpl(final String name, final String comment,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final Type parent, final Type returnType,
- final boolean isFinal, final boolean isReadOnly,
- final List<Parameter> parameters, final AccessModifier modifier) {
- super();
- this.name = name;
- this.annotations = new ArrayList<AnnotationType>();
- for (final AnnotationTypeBuilder builder : annotationBuilders) {
- this.annotations.add(builder.toInstance());
- }
- this.annotations = Collections.unmodifiableList(this.annotations);
- this.comment = comment;
- this.parent = parent;
- this.returnType = returnType;
- this.isFinal = isFinal;
- this.isReadOnly = isReadOnly;
- this.parameters = Collections.unmodifiableList(parameters);
- this.modifier = modifier;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getComment() {
- return comment;
- }
-
- @Override
- public Type getDefiningType() {
- return parent;
- }
-
- @Override
- public List<AnnotationType> getAnnotations() {
- return annotations;
- }
-
- @Override
- public Type getReturnType() {
- return returnType;
- }
-
- @Override
- public List<Parameter> getParameters() {
- return parameters;
- }
-
- @Override
- public AccessModifier getAccessModifier() {
- return modifier;
- }
-
- @Override
- public boolean isReadOnly() {
- return isReadOnly;
- }
-
- @Override
- public boolean isFinal() {
- return isFinal;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((parameters == null) ? 0 : parameters.hashCode());
- result = prime * result
- + ((returnType == null) ? 0 : returnType.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- GeneratedPropertyImpl other = (GeneratedPropertyImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (parameters == null) {
- if (other.parameters != null) {
- return false;
- }
- } else if (!parameters.equals(other.parameters)) {
- return false;
- }
- if (returnType == null) {
- if (other.returnType != null) {
- return false;
- }
- } else if (!returnType.getPackageName().equals(
- other.returnType.getPackageName())) {
- return false;
- } else if (!returnType.getName().equals(other.returnType.getName())) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("GeneratedPropertyImpl [name=");
- builder.append(name);
- builder.append(", annotations=");
- builder.append(annotations);
- builder.append(", comment=");
- builder.append(comment);
- if (parent != null) {
- builder.append(", parent=");
- builder.append(parent.getPackageName());
- builder.append(".");
- builder.append(parent.getName());
- } else {
- builder.append(", parent=null");
- }
- builder.append(", returnType=");
- builder.append(returnType);
- builder.append(", isFinal=");
- builder.append(isFinal);
- builder.append(", isReadOnly=");
- builder.append(isReadOnly);
- builder.append(", parameters=");
- builder.append(parameters);
- builder.append(", modifier=");
- builder.append(modifier);
- builder.append("]");
- return builder.toString();
- }
- }
-
- private static class GeneratedTransferObjectImpl implements
+ return new GeneratedTransferObjectImpl(null, getPackageName(), getName(), getComment(),
+ getAnnotations(), isAbstract(), extendsType, getImplementsTypes(), getEnclosedTypes(),
+ getEnclosedTransferObjects(), getConstants(), getEnumerations(), getMethodDefinitions(), properties,
+ equalsProperties, hashProperties, toStringProperties);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedTransferObject [packageName=");
+ builder.append(getPackageName());
+ builder.append(", name=");
+ builder.append(getName());
+ builder.append(", comment=");
+ builder.append(getComment());
+ builder.append(", constants=");
+ builder.append(getConstants());
+ builder.append(", enumerations=");
+ builder.append(getEnumerations());
+ builder.append(", properties=");
+ builder.append(properties);
+ builder.append(", equalsProperties=");
+ builder.append(equalsProperties);
+ builder.append(", hashCodeProperties=");
+ builder.append(hashProperties);
+ builder.append(", stringProperties=");
+ builder.append(toStringProperties);
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append(", methods=");
+ builder.append(getMethodDefinitions());
+ builder.append("]");
+ return builder.toString();
+ }
+
+ private static final class GeneratedTransferObjectImpl extends AbstractGeneratedType implements
GeneratedTransferObject {
- private final String packageName;
- private final String name;
- private final String comment;
- private final List<Constant> constants;
- private final List<Enumeration> enumerations;
private final List<GeneratedProperty> properties;
private final List<GeneratedProperty> equalsProperties;
private final List<GeneratedProperty> hashCodeProperties;
private final List<GeneratedProperty> stringProperties;
- private final List<AnnotationType> annotations;
- private final List<MethodSignature> methods;
private final GeneratedTransferObject extendsType;
- private final List<Type> implementsTypes;
- public GeneratedTransferObjectImpl(final String packageName,
- final String name, final String comment,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final GeneratedTransferObject extendsType,
- final List<Type> implementsTypes,
- final List<ConstantBuilder> constantBuilders,
- final List<EnumBuilder> enumBuilders,
- final List<MethodSignatureBuilder> methodBuilders,
- final List<GeneratedPropertyBuilder> propBuilers,
- final List<GeneratedPropertyBuilder> equalsBuilers,
- final List<GeneratedPropertyBuilder> hashCodeBuilers,
- final List<GeneratedPropertyBuilder> stringBuilers) {
- super();
- this.packageName = packageName;
- this.name = name;
- this.comment = comment;
- this.annotations = toUnmodifiableAnnotations(annotationBuilders);
+ GeneratedTransferObjectImpl(final Type parent,
+ final String packageName,
+ final String name, final String comment,
+ final List<AnnotationTypeBuilder> annotationBuilders,
+ final boolean isAbstract,
+ final GeneratedTransferObject extendsType,
+ final List<Type> implementsTypes,
+ final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
+ final List<GeneratedTOBuilder> enclosedGenTOBuilders,
+ final List<Constant> constants,
+ final List<EnumBuilder> enumBuilders,
+ final List<MethodSignatureBuilder> methodBuilders,
+ final List<GeneratedPropertyBuilder> propBuilders,
+ final List<GeneratedPropertyBuilder> equalsBuilders,
+ final List<GeneratedPropertyBuilder> hashCodeBuilders,
+ final List<GeneratedPropertyBuilder> stringBuilders) {
+ super(parent, packageName, name, comment, annotationBuilders, isAbstract, implementsTypes,
+ enclosedGenTypeBuilders,
+ enclosedGenTOBuilders, enumBuilders, constants, methodBuilders);
this.extendsType = extendsType;
- this.implementsTypes = Collections
- .unmodifiableList(implementsTypes);
- this.constants = toUnmodifiableConstant(constantBuilders);
- this.enumerations = toUnmodifiableEnumerations(enumBuilders);
- this.properties = toUnmodifiableProperties(propBuilers);
- this.methods = toUnmodifiableMethods(methodBuilders);
- this.equalsProperties = toUnmodifiableProperties(equalsBuilers);
- this.hashCodeProperties = toUnmodifiableProperties(hashCodeBuilers);
- this.stringProperties = toUnmodifiableProperties(stringBuilers);
- }
-
- private List<AnnotationType> toUnmodifiableAnnotations(
- final List<AnnotationTypeBuilder> annotationBuilders) {
- final List<AnnotationType> annotations = new ArrayList<AnnotationType>();
- for (final AnnotationTypeBuilder builder : annotationBuilders) {
- annotations.add(builder.toInstance());
- }
- return Collections.unmodifiableList(annotations);
- }
-
- private List<Enumeration> toUnmodifiableEnumerations(
- final List<EnumBuilder> enumBuilders) {
- final List<Enumeration> enumerations = new ArrayList<Enumeration>();
- for (final EnumBuilder builder : enumBuilders) {
- enumerations.add(builder.toInstance(this));
- }
- return Collections.unmodifiableList(enumerations);
- }
-
- private List<Constant> toUnmodifiableConstant(
- final List<ConstantBuilder> constBuilders) {
- final List<Constant> constants = new ArrayList<Constant>();
- for (final ConstantBuilder builder : constBuilders) {
- constants.add(builder.toInstance(this));
- }
- return Collections.unmodifiableList(constants);
- }
-
- private List<MethodSignature> toUnmodifiableMethods(
- final List<MethodSignatureBuilder> methodBuilders) {
- final List<MethodSignature> methods = new ArrayList<MethodSignature>();
- for (final MethodSignatureBuilder builder : methodBuilders) {
- methods.add(builder.toInstance(this));
- }
- return Collections.unmodifiableList(methods);
+ this.properties = toUnmodifiableProperties(propBuilders);
+ this.equalsProperties = toUnmodifiableProperties(equalsBuilders);
+ this.hashCodeProperties = toUnmodifiableProperties(hashCodeBuilders);
+ this.stringProperties = toUnmodifiableProperties(stringBuilders);
}
private List<GeneratedProperty> toUnmodifiableProperties(
final List<GeneratedPropertyBuilder> propBuilders) {
- final List<GeneratedProperty> constants = new ArrayList<GeneratedProperty>();
+ final List<GeneratedProperty> properties = new ArrayList<>();
for (final GeneratedPropertyBuilder builder : propBuilders) {
- constants.add(builder.toInstance(this));
+ properties.add(builder.toInstance(this));
}
- return Collections.unmodifiableList(constants);
- }
-
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Type getParentType() {
- return null;
- }
-
- @Override
- public String getComment() {
- return comment;
- }
-
- @Override
- public List<AnnotationType> getAnnotations() {
- return annotations;
- }
-
- @Override
- public List<Type> getImplements() {
- return implementsTypes;
+ return Collections.unmodifiableList(properties);
}
@Override
return extendsType;
}
- @Override
- public List<Enumeration> getEnumDefintions() {
- return enumerations;
- }
-
- @Override
- public List<Constant> getConstantDefinitions() {
- return constants;
- }
-
- @Override
- public List<MethodSignature> getMethodDefinitions() {
- return methods;
- }
-
@Override
public List<GeneratedProperty> getProperties() {
return properties;
return stringProperties;
}
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((packageName == null) ? 0 : packageName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- GeneratedTransferObjectImpl other = (GeneratedTransferObjectImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (packageName == null) {
- if (other.packageName != null) {
- return false;
- }
- } else if (!packageName.equals(other.packageName)) {
- return false;
- }
- return true;
- }
-
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GeneratedTransferObject [packageName=");
- builder.append(packageName);
+ builder.append(getPackageName());
builder.append(", name=");
- builder.append(name);
+ builder.append(getName());
builder.append(", comment=");
- builder.append(comment);
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append(getComment());
+ builder.append(", extends=");
+ builder.append(getExtends());
+ builder.append(", implements=");
+ builder.append(getImplements());
+ builder.append(", enclosedTypes=");
+ builder.append(getEnclosedTypes());
builder.append(", constants=");
- builder.append(constants);
+ builder.append(getConstantDefinitions());
builder.append(", enumerations=");
- builder.append(enumerations);
+ builder.append(getEnumerations());
builder.append(", properties=");
builder.append(properties);
builder.append(", equalsProperties=");
builder.append(hashCodeProperties);
builder.append(", stringProperties=");
builder.append(stringProperties);
- builder.append(", annotations=");
- builder.append(annotations);
builder.append(", methods=");
- builder.append(methods);
+ builder.append(getMethodDefinitions());
builder.append("]");
return builder.toString();
}
}
-
- private static final class GeneratedTransferIdentityObjectImpl extends
- GeneratedTransferObjectImpl implements
- GeneratedTransferIdentityObject {
- public GeneratedTransferIdentityObjectImpl(final String packageName,
- final String name, final String comment,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final GeneratedTransferObject extendsType,
- final List<Type> implementsTypes,
- final List<ConstantBuilder> constantBuilders,
- final List<EnumBuilder> enumBuilders,
- final List<MethodSignatureBuilder> methodBuilders,
- final List<GeneratedPropertyBuilder> propBuilers,
- final List<GeneratedPropertyBuilder> equalsBuilers,
- final List<GeneratedPropertyBuilder> hashCodeBuilers,
- final List<GeneratedPropertyBuilder> stringBuilers) {
- super(packageName, name, comment, annotationBuilders, extendsType,
- implementsTypes, constantBuilders, enumBuilders,
- methodBuilders, propBuilers, equalsBuilers,
- hashCodeBuilers, stringBuilers);
- }
- }
}
*/
package org.opendaylight.controller.binding.generator.util.generated.type.builder;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-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.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;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
-
-public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {
-
- private final String packageName;
- private String comment = "";
- private final String name;
- private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
- private final List<Type> implementsTypes = new ArrayList<Type>();
- 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;
- }
-
- @Override
- public Type getParentType() {
- return this;
- }
-
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void addComment(String comment) {
- this.comment = comment;
- }
+import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
- @Override
- public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
- if (packageName != null && name != null) {
- final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
- packageName, name);
- if (annotationBuilders.add(builder)) {
- return builder;
- }
- }
- return null;
- }
+import java.util.List;
- @Override
- public ConstantBuilder addConstant(Type type, String name, Object value) {
- final ConstantBuilder builder = new ConstantBuilderImpl(type, name,
- value);
- constantDefintions.add(builder);
- return builder;
- }
+public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder {
- @Override
- public EnumBuilder addEnumeration(final String name) {
- final String innerPackageName = packageName + "." + this.name;
- final EnumBuilder builder = new EnumerationBuilderImpl(
- innerPackageName, name);
- enumDefinitions.add(builder);
- return builder;
+ public GeneratedTypeBuilderImpl(String packageName, String name) {
+ super(packageName, name);
+ setAbstract(true);
}
@Override
- public MethodSignatureBuilder addMethod(final String name) {
- final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(
- this, name);
- methodDefinitions.add(builder);
- return builder;
+ public GeneratedType toInstance() {
+ return new GeneratedTypeImpl(null, getPackageName(), getName(), getComment(), getAnnotations(), isAbstract(),
+ getImplementsTypes(), getEnclosedTypes(), getEnclosedTransferObjects(), getEnumerations(),
+ getConstants(), getMethodDefinitions());
}
@Override
- public boolean addImplementsType(final Type genType) {
- if (genType != null) {
- return implementsTypes.add(genType);
- }
- return false;
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedTransferObject [packageName=");
+ builder.append(getPackageName());
+ builder.append(", name=");
+ builder.append(getName());
+ builder.append(", comment=");
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append(getComment());
+ builder.append(", implements=");
+ builder.append(getImplementsTypes());
+ builder.append(", enclosedTypes=");
+ builder.append(getEnclosedTypes());
+ builder.append(", constants=");
+ builder.append(getConstants());
+ builder.append(", enumerations=");
+ builder.append(getEnumerations());
+ builder.append(", properties=");
+ builder.append(", methods=");
+ builder.append(getMethodDefinitions());
+ builder.append("]");
+ return builder.toString();
}
-
- @Override
- public GeneratedType toInstance() {
- return new GeneratedTypeImpl(this, packageName, name, comment,
- annotationBuilders, implementsTypes, enumDefinitions, constantDefintions,
- methodDefinitions);
- }
-
- private static final class GeneratedTypeImpl implements GeneratedType {
-
- private final Type parent;
- private final String packageName;
- private final String name;
- private final String comment;
- private final List<AnnotationType> annotations;
- private final List<Type> implementsTypes;
- private final List<Enumeration> enumDefinitions;
- private final List<Constant> constantDefintions;
- private final List<MethodSignature> methodDefinitions;
-
- public GeneratedTypeImpl(final Type parent, final String packageName,
- final String name, final String comment,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final List<Type> implementsTypes,
- final List<EnumBuilder> enumBuilders,
- final List<ConstantBuilder> constantBuilders,
- final List<MethodSignatureBuilder> methodBuilders) {
- super();
- this.parent = parent;
- this.packageName = packageName;
- 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);
- }
-
- private List<AnnotationType> toUnmodifiableAnnotations(
- final List<AnnotationTypeBuilder> annotationBuilders) {
- final List<AnnotationType> annotations = new ArrayList<AnnotationType>();
- for (final AnnotationTypeBuilder builder : annotationBuilders) {
- annotations.add(builder.toInstance());
- }
- return Collections.unmodifiableList(annotations);
- }
-
- private List<MethodSignature> toUnmodifiableMethods(
- List<MethodSignatureBuilder> methodBuilders) {
- final List<MethodSignature> methods = new ArrayList<MethodSignature>();
- for (final MethodSignatureBuilder methodBuilder : methodBuilders) {
- methods.add(methodBuilder.toInstance(this));
- }
- return Collections.unmodifiableList(methods);
- }
-
- private List<Enumeration> toUnmodifiableEnums(
- List<EnumBuilder> enumBuilders) {
- final List<Enumeration> enums = new ArrayList<Enumeration>();
- for (final EnumBuilder enumBuilder : enumBuilders) {
- enums.add(enumBuilder.toInstance(this));
- }
- return Collections.unmodifiableList(enums);
- }
-
- private List<Constant> toUnmodifiableConstants(
- List<ConstantBuilder> constantBuilders) {
- final List<Constant> constants = new ArrayList<Constant>();
- for (final ConstantBuilder enumBuilder : constantBuilders) {
- constants.add(enumBuilder.toInstance(this));
- }
- return Collections.unmodifiableList(constants);
- }
-
- @Override
- public String getPackageName() {
- return packageName;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public Type getParentType() {
- return parent;
- }
-
- @Override
- public String getComment() {
- return comment;
- }
-
- @Override
- public List<AnnotationType> getAnnotations() {
- return annotations;
- }
-
- @Override
- public List<Type> getImplements() {
- return implementsTypes;
- }
-
- @Override
- public List<Enumeration> getEnumDefintions() {
- return enumDefinitions;
- }
-
- @Override
- public List<Constant> getConstantDefinitions() {
- return constantDefintions;
- }
-
- @Override
- public List<MethodSignature> getMethodDefinitions() {
- return methodDefinitions;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime
- * result
- + ((constantDefintions == null) ? 0 : constantDefintions
- .hashCode());
- result = prime
- * result
- + ((enumDefinitions == null) ? 0 : enumDefinitions
- .hashCode());
- result = prime
- * result
- + ((methodDefinitions == null) ? 0 : methodDefinitions
- .hashCode());
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((packageName == null) ? 0 : packageName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- GeneratedTypeImpl other = (GeneratedTypeImpl) obj;
- if (constantDefintions == null) {
- if (other.constantDefintions != null) {
- return false;
- }
- } else if (!constantDefintions.equals(other.constantDefintions)) {
- return false;
- }
- if (enumDefinitions == null) {
- if (other.enumDefinitions != null) {
- return false;
- }
- } else if (!enumDefinitions.equals(other.enumDefinitions)) {
- return false;
- }
- if (methodDefinitions == null) {
- if (other.methodDefinitions != null) {
- return false;
- }
- } else if (!methodDefinitions.equals(other.methodDefinitions)) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (packageName == null) {
- if (other.packageName != null) {
- return false;
- }
- } else if (!packageName.equals(other.packageName)) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("GeneratedType [packageName=");
- builder.append(packageName);
- builder.append(", name=");
- builder.append(name);
- if (parent != null) {
- builder.append(", parent=");
- builder.append(parent.getPackageName());
- builder.append(".");
- builder.append(parent.getName());
- } else {
- builder.append(", parent=null");
- }
- builder.append(", comment=");
- builder.append(comment);
- builder.append(", annotations=");
- builder.append(annotations);
- builder.append(", enumDefinitions=");
- builder.append(enumDefinitions);
- builder.append(", constantDefintions=");
- builder.append(constantDefintions);
- builder.append(", methodDefinitions=");
- builder.append(methodDefinitions);
- builder.append("]");
- return builder.toString();
+ private static final class GeneratedTypeImpl extends AbstractGeneratedType {
+
+ public GeneratedTypeImpl(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(parent, packageName, name, comment, annotationBuilders, isAbstract, implementsTypes,
+ enclosedGenTypeBuilders, enclosedGenTOBuilders, enumBuilders, constants, methodBuilders);
}
}
}
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
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;
import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
-final class MethodSignatureBuilderImpl implements MethodSignatureBuilder {
- private final String name;
- private Type returnType;
+final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder implements MethodSignatureBuilder {
+
private final List<MethodSignature.Parameter> parameters;
- private final List<AnnotationTypeBuilder> annotationBuilders;
- private String comment = "";
- private final Type parent;
+ private boolean isAbstract;
- public MethodSignatureBuilderImpl(final Type parent, final String name) {
- super();
- this.name = name;
- this.parent = parent;
- this.parameters = new ArrayList<MethodSignature.Parameter>();
- this.annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
+ public MethodSignatureBuilderImpl(final String name) {
+ super(name);
+ this.parameters = new ArrayList<>();
}
@Override
- public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
- if (packageName != null && name != null) {
- final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
- packageName, name);
- if (annotationBuilders.add(builder)) {
- return builder;
- }
- }
- return null;
- }
-
- @Override
- public void addReturnType(Type returnType) {
- if (returnType != null) {
- this.returnType = returnType;
- }
+ public void setAbstract(boolean isAbstract) {
+ this.isAbstract = isAbstract;
}
@Override
parameters.add(new MethodParameterImpl(name, type));
}
- @Override
- public void addComment(String comment) {
- this.comment = comment;
- }
-
@Override
public MethodSignature toInstance(Type definingType) {
- return new MethodSignatureImpl(definingType, name, annotationBuilders,
- comment, returnType, parameters);
+ final List<AnnotationType> annotations = toAnnotationTypes();
+ return new MethodSignatureImpl(definingType, getName(), annotations,
+ getComment(), getAccessModifier(), getReturnType(), parameters, isFinal(), isAbstract);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result
+ ((parameters == null) ? 0 : parameters.hashCode());
result = prime * result
- + ((returnType == null) ? 0 : returnType.hashCode());
+ + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
return result;
}
return false;
}
MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
- if (name == null) {
- if (other.name != null) {
+ if (getName() == null) {
+ if (other.getName() != null) {
return false;
}
- } else if (!name.equals(other.name)) {
+ } else if (!getName().equals(other.getName())) {
return false;
}
if (parameters == null) {
} else if (!parameters.equals(other.parameters)) {
return false;
}
- if (returnType == null) {
- if (other.returnType != null) {
+ if (getReturnType() == null) {
+ if (other.getReturnType() != null) {
return false;
}
- } else if (!returnType.equals(other.returnType)) {
+ } else if (!getReturnType().equals(other.getReturnType())) {
return false;
}
return true;
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MethodSignatureBuilderImpl [name=");
- builder.append(name);
+ builder.append(getName());
builder.append(", returnType=");
- builder.append(returnType);
+ builder.append(getReturnType());
builder.append(", parameters=");
builder.append(parameters);
builder.append(", annotationBuilders=");
- builder.append(annotationBuilders);
+ builder.append(getAnnotationBuilders());
builder.append(", comment=");
- builder.append(comment);
- if (parent != null) {
- builder.append(", parent=");
- builder.append(parent.getPackageName());
- builder.append(".");
- builder.append(parent.getName());
- } else {
- builder.append(", parent=null");
- }
+ builder.append(getComment());
builder.append("]");
return builder.toString();
}
-
- private static final class MethodSignatureImpl implements MethodSignature {
-
- private final String name;
- private final String comment;
- private final Type definingType;
- private final Type returnType;
- private final List<Parameter> params;
- private List<AnnotationType> annotations;
-
- public MethodSignatureImpl(final Type definingType, final String name,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final String comment, final Type returnType,
- final List<Parameter> params) {
- super();
- this.name = name;
- this.comment = comment;
- this.definingType = definingType;
- this.returnType = returnType;
- this.params = Collections.unmodifiableList(params);
-
- this.annotations = new ArrayList<AnnotationType>();
- for (final AnnotationTypeBuilder builder : annotationBuilders) {
- this.annotations.add(builder.toInstance());
- }
- this.annotations = Collections.unmodifiableList(this.annotations);
- }
-
- @Override
- public List<AnnotationType> getAnnotations() {
- return annotations;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getComment() {
- return comment;
- }
-
- @Override
- public Type getDefiningType() {
- return definingType;
- }
-
- @Override
- public Type getReturnType() {
- return returnType;
- }
-
- @Override
- public List<Parameter> getParameters() {
- return params;
- }
-
- @Override
- public AccessModifier getAccessModifier() {
- return AccessModifier.PUBLIC;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((params == null) ? 0 : params.hashCode());
- result = prime * result
- + ((returnType == null) ? 0 : returnType.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- MethodSignatureImpl other = (MethodSignatureImpl) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- if (params == null) {
- if (other.params != null) {
- return false;
- }
- } else if (!params.equals(other.params)) {
- return false;
- }
- if (returnType == null) {
- if (other.returnType != null) {
- return false;
- }
- } else if (!returnType.equals(other.returnType)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("MethodSignatureImpl [name=");
- builder.append(name);
- builder.append(", comment=");
- builder.append(comment);
- if (definingType != null) {
- builder.append(", definingType=");
- builder.append(definingType.getPackageName());
- builder.append(".");
- builder.append(definingType.getName());
- } else {
- builder.append(", definingType= null");
- }
- builder.append(", returnType=");
- builder.append(returnType);
- builder.append(", params=");
- builder.append(params);
- builder.append(", annotations=");
- builder.append(annotations);
- builder.append("]");
- return builder.toString();
- }
- }
}
\ No newline at end of file
--- /dev/null
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+import java.util.Collections;
+import java.util.List;
+
+class MethodSignatureImpl extends AbstractTypeMember implements MethodSignature {
+
+ private final List<Parameter> params;
+ private final boolean isAbstract;
+
+ public MethodSignatureImpl(final Type definingType, final String name,
+ final List<AnnotationType> annotations,
+ final String comment, final AccessModifier accessModifier,
+ final Type returnType, final List<Parameter> params, boolean isFinal,
+ boolean isAbstract) {
+ super(definingType, name, annotations, comment, accessModifier, returnType, isFinal);
+ this.params = Collections.unmodifiableList(params);
+ this.isAbstract = isAbstract;
+ }
+
+ @Override
+ public boolean isAbstract() {
+ return isAbstract;
+ }
+
+ @Override
+ public List<Parameter> getParameters() {
+ return params;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result
+ + ((params == null) ? 0 : params.hashCode());
+ result = prime * result
+ + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MethodSignatureImpl other = (MethodSignatureImpl) obj;
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ if (params == null) {
+ if (other.params != null) {
+ return false;
+ }
+ } else if (!params.equals(other.params)) {
+ return false;
+ }
+ if (getReturnType() == null) {
+ if (other.getReturnType() != null) {
+ return false;
+ }
+ } else if (!getReturnType().equals(other.getReturnType())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("MethodSignatureImpl [name=");
+ builder.append(getName());
+ builder.append(", comment=");
+ builder.append(getComment());
+ if (getDefiningType() != null) {
+ builder.append(", definingType=");
+ builder.append(getDefiningType().getPackageName());
+ builder.append(".");
+ builder.append(getDefiningType().getName());
+ } else {
+ builder.append(", definingType= null");
+ }
+ builder.append(", returnType=");
+ builder.append(getReturnType());
+ builder.append(", params=");
+ builder.append(params);
+ builder.append(", annotations=");
+ builder.append(getAnnotations());
+ builder.append("]");
+ return builder.toString();
+ }
+}
import org.junit.Test;
import org.opendaylight.controller.binding.generator.util.Types;
-import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
final MethodSignatureBuilder methodBuilder = genTypeBuilder
.addMethod("simpleMethod");
- methodBuilder.addReturnType(Types.typeForClass(Integer.class));
+ methodBuilder.setReturnType(Types.typeForClass(Integer.class));
final AnnotationTypeBuilder annotManAttr = methodBuilder
.addAnnotation("org.springframework.jmx.export.annotation",
"ManagedAttribute");
final GeneratedPropertyBuilder propertyBuilder = genTOBuilder
.addProperty("simpleProperty");
- propertyBuilder.addReturnType(Types.typeForClass(Integer.class));
+ propertyBuilder.setReturnType(Types.typeForClass(Integer.class));
final AnnotationTypeBuilder annotManAttr = propertyBuilder
.addAnnotation("org.springframework.jmx.export.annotation",
"ManagedAttribute");
@Override
public Writer generate(Type type) throws IOException {
final Writer writer = new StringWriter();
- boolean isIdentity = type instanceof GeneratedTransferIdentityObject;
if (type instanceof GeneratedTransferObject) {
GeneratedTransferObject genTO = (GeneratedTransferObject) type;
final String currentPkg = genTO.getPackageName();
final List<GeneratedProperty> fields = genTO.getProperties();
- final List<Enumeration> enums = genTO.getEnumDefintions();
+ final List<Enumeration> enums = genTO.getEnumerations();
writer.write(GeneratorUtil.createPackageDeclaration(currentPkg));
writer.write(NL);
writer.write(NL);
writer.write(GeneratorUtil.createClassDeclaration(genTO, "",
- imports, isIdentity));
+ imports, genTO.isAbstract()));
writer.write(NL);
writer.write(NL);
}
writer.write(NL);
writer.write(GeneratorUtil.createConstructor(genTO, TAB,
- imports, isIdentity) + NL);
+ imports, genTO.isAbstract()) + NL);
writer.write(NL);
for (GeneratedProperty field : fields) {
writer.write(GeneratorUtil.createGetter(field, TAB,
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
final List<Constant> constants = genType.getConstantDefinitions();
final List<MethodSignature> methods = genType
.getMethodDefinitions();
- final List<Enumeration> enums = genType.getEnumDefintions();
+ final List<Enumeration> enums = genType.getEnumerations();
writer.write(GeneratorUtil.createPackageDeclaration(genType
.getPackageName()));
}
return writer;
}
-
}
"simple.pack", "DefCtor");
GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo");
- propBuilder.addReturnType(Types.typeForClass(String.class));
+ propBuilder.setReturnType(Types.typeForClass(String.class));
propBuilder.setReadOnly(false);
propBuilder = toBuilder.addProperty("bar");
- propBuilder.addReturnType(Types.typeForClass(Integer.class));
+ propBuilder.setReturnType(Types.typeForClass(Integer.class));
propBuilder.setReadOnly(false);
final GeneratedTransferObject genTO = toBuilder.toInstance();
"simple.pack", "DefCtor");
GeneratedPropertyBuilder propBuilder = toBuilder.addProperty("foo");
- propBuilder.addReturnType(Types.typeForClass(String.class));
+ propBuilder.setReturnType(Types.typeForClass(String.class));
propBuilder.setReadOnly(false);
toBuilder.addToStringProperty(propBuilder);
propBuilder = toBuilder.addProperty("bar");
- propBuilder.addReturnType(Types.typeForClass(Integer.class));
+ propBuilder.setReturnType(Types.typeForClass(Integer.class));
propBuilder.setReadOnly(false);
toBuilder.addToStringProperty(propBuilder);
final GeneratedTransferObject genTO = toBuilder.toInstance();
*/\r
package org.opendaylight.controller.sal.binding.model.api;\r
\r
+/**\r
+ * Enum definition which provides four access modifiers that are described\r
+ * in Java programming language (Default, Private, Protected, Public).\r
+ */\r
public enum AccessModifier {\r
- PRIVATE, PUBLIC, PROTECTED\r
+ DEFAULT, PRIVATE, PUBLIC, PROTECTED\r
}\r
import java.util.List;
-
+/**
+ * The Annotation Type interface is designed to hold information about
+ * annotation for any type that could be annotated in Java.
+ * <br>
+ * For sake of simplicity the Annotation Type is not designed to model exact
+ * behaviour of annotation mechanism, but just to hold information needed to
+ * model annotation over java Type definition.
+ */
public interface AnnotationType extends Type {
-
+
+ /**
+ * Returns the List of Annotations.
+ * <br>
+ * Each Annotation Type MAY have defined multiple Annotations.
+ *
+ * @return the List of Annotations.
+ */
public List<AnnotationType> getAnnotations();
-
+
+ /**
+ * Returns Parameter Definition assigned for given parameter name.
+ * <br>
+ * If Annotation does not contain parameter with specified param name,
+ * the method MAY return <code>null</code> value.
+ *
+ * @param paramName Parameter Name
+ * @return Parameter Definition assigned for given parameter name.
+ */
public Parameter getParameter(final String paramName);
-
+
+ /**
+ * Returns List of all parameters assigned to Annotation Type.
+ *
+ * @return List of all parameters assigned to Annotation Type.
+ */
public List<Parameter> getParameters();
-
+
+ /**
+ * Returns List of parameter names.
+ *
+ * @return List of parameter names.
+ */
public List<String> getParameterNames();
-
+
+ /**
+ * Returns <code>true</code> if annotation contains parameters.
+ *
+ * @return <code>true</code> if annotation contains parameters.
+ */
public boolean containsParameters();
-
+
+ /**
+ * Annotation Type parameter interface. For simplicity the Parameter
+ * contains values and value types as Strings. Every annotation which
+ * contains parameters could contain either single parameter or array of
+ * parameters. To model this purposes the by contract if the parameter
+ * contains single parameter the {@link #getValues()} method will return
+ * empty List and {@link #getValue()} MUST always return non-<code>null</code>
+ * parameter. If the Parameter holds List of values the singular {@link
+ * #getValue()} parameter MAY return <code>null</code> value.
+ */
interface Parameter {
-
+
+ /**
+ * Returns the Name of the parameter.
+ *
+ * @return the Name of the parameter.
+ */
public String getName();
-
+
+ /**
+ * Returns value in String format if Parameter contains singular value,
+ * otherwise MAY return <code>null</code>.
+ *
+ * @return value in String format if Parameter contains singular value.
+ */
public String getValue();
-
+
+ /**
+ * Returns List of Parameter assigned values in order in which they
+ * were assigned for given parameter name.
+ * <br>
+ * If there are multiple values assigned for given parameter name the
+ * method MUST NOT return empty List.
+ *
+ * @return List of Parameter assigned values in order in which they
+ * were assigned for given parameter name.
+ */
public List<String> getValues();
}
}
import java.io.IOException;\r
import java.io.Writer;\r
\r
+/**\r
+ *\r
+ *\r
+ */\r
public interface CodeGenerator {\r
\r
+ /**\r
+ *\r
+ * @param type\r
+ * @return\r
+ * @throws IOException\r
+ */\r
Writer generate(Type type) throws IOException;\r
\r
}\r
*/
package org.opendaylight.controller.sal.binding.model.api;
+/**
+ * The Concrete Type is marker interface that encapsulates definition of java
+ * concrete type.
+ */
public interface ConcreteType extends Type {
}
*/\r
package org.opendaylight.controller.sal.binding.model.api;\r
\r
+/**\r
+ * Interface Contact is designed to hold and model java constant. In Java\r
+ * there are no constant keywords instead of the constant is defined as\r
+ * static final field with assigned value. For this purpose the Constant\r
+ * interface contains methods {@link #getType()} to provide wrapped return\r
+ * Type of Constant, {@link #getName()} the Name of constant and the {@link\r
+ * #getValue()} for providing of value assigned to Constant. To determine of\r
+ * which type the constant value is it is recommended firstly to retrieve\r
+ * Type from constant. The Type interface holds base information like java\r
+ * package name and java type name (e.g. fully qualified name). From this\r
+ * string user should be able to determine to which type can be {@link\r
+ * #getValue()} type typecasted to unbox and provide value assigned to\r
+ * constant.\r
+ */\r
public interface Constant {\r
\r
+ /**\r
+ * Returns the Type that declares constant.\r
+ *\r
+ * @return the Type that declares constant.\r
+ */\r
public Type getDefiningType();\r
\r
+ /**\r
+ * Returns the return Type (or just Type) of the Constant.\r
+ *\r
+ * @return the return Type (or just Type) of the Constant.\r
+ */\r
public Type getType();\r
\r
+ /**\r
+ * Returns the name of constant.\r
+ * <br>\r
+ * By conventions the name SHOULD be in CAPITALS separated with\r
+ * underscores.\r
+ *\r
+ * @return the name of constant.\r
+ */\r
public String getName();\r
\r
+ /**\r
+ * Returns boxed value that is assigned for context.\r
+ *\r
+ * @return boxed value that is assigned for context.\r
+ */\r
public Object getValue();\r
\r
+ /**\r
+ * Returns Constant definition in formatted string.\r
+ * <br>\r
+ * <br>\r
+ * The expected string SHOULD be in format: <code>public final\r
+ * static [Type] CONSTANT_NAME = [value];</code>\r
+ *\r
+ * @return Constant definition in formatted string.\r
+ */\r
public String toFormattedString();\r
}\r
import java.util.List;
+/**
+ *
+ */
public interface Enumeration extends Type {
-
+
+ /**
+ *
+ * @return
+ */
public List<AnnotationType> getAnnotations();
-
+
+ /**
+ *
+ * @return
+ */
public Type getDefiningType();
+ /**
+ *
+ * @return
+ */
public List<Pair> getValues();
+ /**
+ *
+ * @return
+ */
public String toFormattedString();
+ /**
+ *
+ */
interface Pair {
public String getName();
*/\r
package org.opendaylight.controller.sal.binding.model.api;\r
\r
-public interface GeneratedProperty extends MethodSignature {\r
+/**\r
+ * Generated Property extends interface {@link MethodSignature} interface.\r
+ * <br>\r
+ * The Generated Property interface is designed to store information of\r
+ * fields (or members) declared in Java Transfer Objects (or any java\r
+ * classes) and their access counterparts (getters and setters).\r
+ *\r
+ * @see MethodSignature\r
+ */\r
+public interface GeneratedProperty extends TypeMember {\r
\r
+ /**\r
+ * Returns <code>true</code> if the property si declared as read-only.\r
+ * <br>\r
+ * If the property has flag <code>isReadOnly == true</code> the property\r
+ * SHOULD be generated as getter only.\r
+ *\r
+ * @return <code>true</code> if the property si declared as read-only.\r
+ */\r
public boolean isReadOnly();\r
-\r
- public boolean isFinal();\r
}\r
import java.util.List;
+/**
+ * Generated Transfer Object extends {@link GeneratedType} and is designed to
+ * represent Java Class. The Generated Transfer Object contains declarations
+ * of member fields stored in List of Properties. The Generated Transfer
+ * Object can be extended by exactly ONE Generated Transfer Object as Java
+ * don't allow multiple inheritance. For retrieval of implementing Generated
+ * Types use {@link #getImplements()} method.
+ * <br>
+ * Every transfer object SHOULD contain equals, hashCode and toString 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.
+ */
public GeneratedTransferObject getExtends();
-
+
+ /**
+ * Returns List of Properties that are declared for Generated Transfer
+ * Object.
+ *
+ * @return List of Properties that are declared for Generated Transfer
+ * Object.
+ */
public List<GeneratedProperty> getProperties();
-
+
+ /**
+ * 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.
+ */
public List<GeneratedProperty> getEqualsIdentifiers();
-
+
+ /**
+ * 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.
+ */
public List<GeneratedProperty> getHashCodeIdentifiers();
-
+
+ /**
+ * 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.
+ */
public List<GeneratedProperty> getToStringIdentifiers();
}
* <li><code>interface</code> name (with commentary that <b>SHOULD</b> be
* present to proper define interface and base <i>contracts</i> specified for
* interface)</li>
+ * <li>Each Generated Type can define list of types that Generated Type
+ * can implement to extend it's definition (i.e. interface extends list of
+ * interfaces or java class implements list of interfaces)</li>
+ * <li>Each Generated Type can contain multiple enclosed definitions of
+ * Generated Types (i.e. interface can contain N enclosed interface
+ * definitions or enclosed classes)</li>
* <li><code>enum</code> and <code>constant</code> definitions (i.e. each
* constant definition is by default defined as <code>public static final</code>
* + type (either primitive or object) and constant name</li>
* types) and return values</li>
* </ul>
*
- * By the definition of the interface constant, enum and method definitions MUST
+ * By the definition of the interface constant, enum,
+ * enclosed types and method definitions MUST
* be public, so there is no need to specify the scope of visibility.
- *
- *
*/
public interface GeneratedType extends Type {
+ /**
+ * Returns the parent type if Generated Type is defined as enclosing type,
+ * otherwise returns <code>null</code>
+ *
+ * @return the parent type if Generated Type is defined as enclosing type,
+ * otherwise returns <code>null</code>
+ */
public Type getParentType();
-
+
+ /**
+ * Returns comment string associated with Generated Type.
+ *
+ * @return comment string associated with Generated Type.
+ */
public String getComment();
-
+
+ /**
+ * Returns List of annotation definitions associated with generated type.
+ *
+ * @return List of annotation definitions associated with generated type.
+ */
public List<AnnotationType> getAnnotations();
-
+
+ /**
+ * Returns <code>true</code> if The Generated Type is defined as abstract.
+ *
+ * @return <code>true</code> if The Generated Type is defined as abstract.
+ */
+ public boolean isAbstract();
+
+ /**
+ * Returns List of Types that Generated Type will implement.
+ *
+ * @return List of Types that Generated Type will implement.
+ */
public List<Type> getImplements();
-
+
/**
- * Returns Set of all Enumerator definitions associated with interface.
- *
- * @return Set of all Enumerator definitions associated with interface.
+ * Returns List of enclosing Generated Types.
+ *
+ * @return List of enclosing Generated Types.
*/
- public List<Enumeration> getEnumDefintions();
+ public List<GeneratedType> getEnclosedTypes();
/**
+ * Returns List of all Enumerator definitions associated with Generated
+ * Type.
*
- *
- * @return
+ * @return List of all Enumerator definitions associated with Generated
+ * Type.
+ */
+ public List<Enumeration> getEnumerations();
+
+ /**
+ * Returns List of Constant definitions associated with Generated Type.
+ *
+ * @return List of Constant definitions associated with Generated Type.
*/
public List<Constant> getConstantDefinitions();
/**
+ * Returns List of Method Definitions associated with Generated Type.
*
- *
- * @return
+ * @return List of Method Definitions associated with Generated Type.
*/
public List<MethodSignature> getMethodDefinitions();
-
}
import java.util.List;
-public interface MethodSignature {
-
- public List<AnnotationType> getAnnotations();
-
- public String getName();
-
- public String getComment();
-
- public Type getDefiningType();
+/**
+ * The Method Signature interface contains simplified meta model for java
+ * method definition. Each method MUST be defined by name, return type,
+ * parameters and access modifier.
+ * <br>
+ * Additionally method MAY contain associated annotations and comment. By
+ * contract if method does not contain any comments or annotation definitions
+ * the {@link #getComment()} SHOULD rather return empty string and {@link
+ * #getAnnotations()} SHOULD rather return empty list than <code>null</code>
+ * values.
+ * <br>
+ * The defining Type contains the reference to Generated Type that declares
+ * Method Signature.
+ */
+public interface MethodSignature extends TypeMember {
- public Type getReturnType();
+ /**
+ * Returns <code>true</code> if the method signature is defined as abstract.
+ * <br>
+ * By default in java all method declarations in interface are defined as abstract,
+ * but the user don't need necessary to declare abstract keyword in front of each method.
+ * <br>
+ * The abstract methods are allowed in Class definitions but only when the class is declared as abstract.
+ *
+ * @return <code>true</code> if the method signature is defined as abstract.
+ */
+ public boolean isAbstract();
+ /**
+ * Returns the List of parameters that method declare. If the method does
+ * not contain any parameters, the method will return empty List.
+ *
+ * @return the List of parameters that method declare.
+ */
public List<Parameter> getParameters();
- public AccessModifier getAccessModifier();
-
+ /**
+ * The Parameter interface is designed to hold the information of method
+ * Parameter(s). The parameter is defined by his Name which MUST be
+ * unique as java does not allow multiple parameters with same names for
+ * one method and Type that is associated with parameter.
+ */
interface Parameter {
+
+ /**
+ * Returns the parameter name.
+ *
+ * @return the parameter name.
+ */
public String getName();
+ /**
+ * Returns Type that is bounded to parameter name.
+ *
+ * @return Type that is bounded to parameter name.
+ */
public Type getType();
}
}
\r
/**\r
* Represents an instance of simple parametrized type such as List<String>.\r
+ *\r
+ * The parametrized Type is designed to be used to store information of Java\r
+ * Generic Type. The array of {@link #getActualTypeArguments()} holds\r
+ * information of all generic parameters defined for Parameterized Type.\r
*/\r
public interface ParameterizedType extends Type {\r
\r
+ /**\r
+ * Returns array of Types that are defined for Parameterized Type.\r
+ * <br>\r
+ * (for example if ParameterizedType encapsulates java generic Map that\r
+ * specifies two parameters Map<K,V> and the K is java.lang.Integer and V\r
+ * is defined as GeneratedType the array will contain two Types to store\r
+ * the information of generic parameters.)\r
+ *\r
+ * @return array of Types that are defined for Parameterized Type.\r
+ */\r
Type[] getActualTypeArguments();\r
\r
+ /**\r
+ * Returns the Raw Type definition of Parameterized Type.\r
+ *\r
+ * @return the Raw Type definition of Parameterized Type.\r
+ */\r
Type getRawType();\r
}\r
*/\r
package org.opendaylight.controller.sal.binding.model.api;\r
\r
+/**\r
+ * The Type interface defines the base type for all types defined in java.\r
+ * Each Type defined in java MUST contain name and package name,\r
+ * except of primitive types like int, byte etc. In case of mapping of\r
+ * primitive type the package name MUST be left as empty string.\r
+ *\r
+ */\r
public interface Type {\r
/**\r
* Returns name of the package that interface belongs to.\r
* @return name of the interface.\r
*/\r
public String getName();\r
+\r
+ /**\r
+ * Returns fully qualified name of Type.\r
+ * <br>\r
+ * The fully qualified name of Type MUST be returned in following format:\r
+ * <ul>\r
+ * <li>If does not contains package name: [type name] (e.g. int, byte,\r
+ * byte[],...)</li>\r
+ * <li>If Type contains package name: [package name].[type name]\r
+ * (e.g java.lang.Byte, org.opendaylight.controller.gen.GenType)</li>\r
+ * </ul>\r
+ *\r
+ * @return fully qualified name of Type.\r
+ */\r
+ public String getFullyQualifiedName();\r
}\r
--- /dev/null
+/*
+ * 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.controller.sal.binding.model.api;
+
+import java.util.List;
+
+public interface TypeMember {
+
+ /**
+ * Returns List of annotation definitions associated with generated type.
+ *
+ * @return List of annotation definitions associated with generated type.
+ */
+ public List<AnnotationType> getAnnotations();
+
+ /**
+ * Returns the name of method.
+ *
+ * @return the name of method.
+ */
+ public String getName();
+
+ /**
+ * Returns comment string associated with method.
+ *
+ * @return comment string associated with method.
+ */
+ public String getComment();
+
+ /**
+ * Returns the Type that declares method.
+ *
+ * @return the Type that declares method.
+ */
+ public Type getDefiningType();
+
+ /**
+ * Returns the access modifier of method.
+ *
+ * @return the access modifier of method.
+ */
+ public AccessModifier getAccessModifier();
+
+ /**
+ * Returns the returning Type that methods returns.
+ *
+ * @return the returning Type that methods returns.
+ */
+ public Type getReturnType();
+
+ /**
+ * Returns <code>true</code> if method is declared as final.
+ *
+ * @return <code>true</code> if method is declared as final.
+ */
+ public boolean isFinal();
+}
import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
import org.opendaylight.controller.sal.binding.model.api.Type;
+/**
+ * Annotation Type Builder Interface serves for creation and instantiation of
+ * immutable copy of Annotation Type. The Annotation Type Builder extends
+ * from {@link Type} interface. The Annotation Type contains set of methods
+ * which are capable to provide information about other Annotation Types and
+ * Annotation Parameters.
+ *
+ * @see AnnotationType
+ */
public interface AnnotationTypeBuilder extends Type {
-
+
+ /**
+ * The method creates new AnnotationTypeBuilder containing specified
+ * package name an annotation name.
+ * <br>
+ * Neither the package name or annotation name can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param packageName Package Name of Annotation Type
+ * @param name Name of Annotation Type
+ * @return <code>new</code> instance of Annotation Type Builder.
+ */
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
+
+ /**
+ * Adds the parameter into List of parameters for Annotation Type.
+ * <br>
+ * If there is already stored parameter with the same name as the new
+ * parameter, the value of the old one will be simply overwritten by the
+ * newer parameter.
+ * <br>
+ * Neither the param name or value can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param paramName Parameter Name
+ * @param value Parameter Value
+ * @return <code>true</code> if the parameter has been successfully
+ * assigned for Annotation Type
+ */
public boolean addParameter(final String paramName, String value);
-
+
+ /**
+ * Adds the parameter with specified List of parameter values into List of
+ * parameters for Annotation Type.
+ * <br>
+ * If there is already stored parameter with the same name as the new
+ * parameter, the value of the old one will be simply overwritten by the
+ * newer parameter.
+ * <br>
+ * Neither the param name or value can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param paramName Parameter Name
+ * @param values List of Values bounded to Parameter Name
+ * @return <code>true</code> if the parameter has been successfully
+ * assigned for Annotation Type
+ */
public boolean addParameters(final String paramName, List<String> values);
-
+
+ /**
+ * Returns <code>new</code> <i>immutable</i> instance of Annotation Type
+ * with values assigned in current instance of Annotation Type Builder.
+ * <br>
+ * The return Annotation Type instance is immutable thus no additional
+ * modification to Annotation Type Builder will have an impact to
+ * instantiated Annotation Type.
+ * <br>
+ * For this purpose call this method after
+ * all additions are complete.
+ *
+ * @return <code>new</code> <i>immutable</i> instance of Annotation Type.
+ */
public AnnotationType toInstance();
}
import org.opendaylight.controller.sal.binding.model.api.Type;\r
\r
/**\r
-\r
*\r
*/\r
public interface ConstantBuilder {\r
import org.opendaylight.controller.sal.binding.model.api.Type;
/**
-
+ * Enum Builder is interface that contains methods to build and instantiate
+ * Enumeration definition.
*
+ * @see Enumeration
*/
public interface EnumBuilder extends Type {
-
+
+ /**
+ * The method creates new AnnotationTypeBuilder containing specified
+ * package name an annotation name.
+ * <br>
+ * Neither the package name or annotation name can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param packageName Package Name of Annotation Type
+ * @param name Name of Annotation Type
+ * @return <code>new</code> instance of Annotation Type Builder.
+ */
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
+
+ /**
+ *
+ * @param name
+ * @param value
+ */
public void addValue(final String name, final Integer value);
+ /**
+ *
+ * @param definingType
+ * @return
+ */
public Enumeration toInstance(final Type definingType);
}
*/
package org.opendaylight.controller.sal.binding.model.api.type.builder;
-import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
import org.opendaylight.controller.sal.binding.model.api.Type;
/**
-
+ * Generated Property Builder is interface that contains methods to build and
+ * instantiate Generated Property definition.
*
+ * @see GeneratedProperty
*/
-public interface GeneratedPropertyBuilder {
-
- public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
- public String getName();
-
- public boolean addReturnType(final Type returnType);
-
- public void accessorModifier(final AccessModifier modifier);
-
- public void addComment(final String comment);
-
- public void setFinal(final boolean isFinal);
-
+public interface GeneratedPropertyBuilder extends TypeMemberBuilder {
+
+ /**
+ * Sets isReadOnly flag for property. If property is marked as read only
+ * it is the same as set property in java as final.
+ *
+ * @param isReadOnly Read Only property flag.
+ */
public void setReadOnly(final boolean isReadOnly);
-
+
+ /**
+ * Returns <code>new</code> <i>immutable</i> instance of Generated
+ * Property.
+ * <br>
+ * The <code>definingType</code> param cannot be <code>null</code>. The
+ * every member in Java MUST be declared and defined inside the scope of
+ * <code>class</code> definition. In case that
+ * defining Type will be passed as <code>null</code> reference the method
+ * SHOULD thrown {@link IllegalArgumentException}.
+ *
+ * @param definingType Defining Type of Generated Property
+ * @return <code>new</code> <i>immutable</i> instance of Generated
+ * Property.
+ */
public GeneratedProperty toInstance(final Type definingType);
}
import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
/**
-
+ * Generated Transfer Object Builder is interface that contains methods to
+ * build and instantiate Generated Transfer Object definition.
+ *
+ * @see GeneratedTransferObject
*/
public interface GeneratedTOBuilder extends GeneratedTypeBuilder {
- public boolean addExtendsType(final GeneratedTransferObject genTransObj);
+ /**
+ * Add Generated Transfer Object from which will be extended current
+ * Generated Transfer Object.
+ * <br>
+ * By definition Java does not allow multiple
+ * inheritance, hence if there is already definition of Generated
+ * Transfer Object the extending object will 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
+ */
+ public void setExtendsType(final GeneratedTransferObject genTransObj);
+ /**
+ * Add new Generated Property definition for Generated Transfer Object
+ * Builder and returns Generated Property Builder for specifying Property.
+ * <br>
+ * Name of Property cannot be <code>null</code>,
+ * if it is <code>null</code> the method SHOULD throw {@link IllegalArgumentException}
+ *
+ * @param name Name of Property
+ * @return <code>new</code> instance of Generated Property Builder.
+ */
public GeneratedPropertyBuilder addProperty(final String name);
+ /**
+ * 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 <code>true</code> if addition of Generated Property into list
+ * of <code>equals</code> properties is successful.
+ */
public boolean addEqualsIdentity(final GeneratedPropertyBuilder property);
+ /**
+ * 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 <code>true</code> if addition of Generated Property into list
+ * of <code>hashCode</code> properties is successful.
+ */
public boolean addHashIdentity(final GeneratedPropertyBuilder property);
+ /**
+ * 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 <code>true</code> if addition of Generated Property into list
+ * of <code>toString</code> properties is successful.
+ */
public boolean addToStringProperty(final GeneratedPropertyBuilder property);
@Override
public GeneratedTransferObject toInstance();
-
- public GeneratedTransferObject toIdentityInstance();
-
}
*/
package org.opendaylight.controller.sal.binding.model.api.type.builder;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
import org.opendaylight.controller.sal.binding.model.api.Type;
/**
-
+ * Generated Type Builder interface is helper interface for building and
+ * defining the GeneratedType.
*
+ * @see GeneratedType
*/
public interface GeneratedTypeBuilder extends Type {
- public Type getParentType();
+ /**
+ * Adds new Enclosing Type into definition of Generated Type and returns
+ * <code>new</code> Instance of Generated Type Builder.
+ * <br>
+ * There is no need of specifying of Package Name because enclosing Type
+ * is already defined inside Generated Type with specific package name.
+ * <br>
+ * The name of enclosing Type cannot be same as Name of parent type and
+ * if there is already defined enclosing type with the same name,
+ * the new enclosing type will simply overwrite the older definition.
+ * <br>
+ * If the name of enclosing type is <code>null</code> the method SHOULD
+ * throw {@link IllegalArgumentException}
+ *
+ * @param name Name of Enclosing Type
+ * @return <code>new</code> Instance of Generated Type Builder.
+ */
+ public GeneratedTypeBuilder addEnclosingType(final String name);
+
+ /**
+ * Adds new Enclosing Transfer Object into definition of Generated Type
+ * and returns <code>new</code> Instance of Generated TO Builder.
+ * <br>
+ * There is no need of specifying of Package Name because enclosing Type
+ * is already defined inside Generated Type with specific package name.
+ * <br>
+ * The name of enclosing Type cannot be same as Name of parent type and
+ * if there is already defined enclosing type with the same name,
+ * the new enclosing type will simply overwrite the older definition.
+ * <br>
+ * If the name of enclosing type is <code>null</code> the method SHOULD
+ * throw {@link IllegalArgumentException}
+ *
+ * @param name Name of Enclosing Type
+ * @return <code>new</code> Instance of Generated Type Builder.
+ */
+ public GeneratedTOBuilder addEnclosingTransferObject(final String name);
+ /**
+ * Adds String definition of comment into Method Signature definition.
+ * <br>
+ * The comment String MUST NOT contain anny comment specific chars (i.e.
+ * "/**" or "//") just plain String text description.
+ *
+ * @param comment Comment String.
+ */
public void addComment(final String comment);
-
+
+ /**
+ * The method creates new AnnotationTypeBuilder containing specified
+ * package name an annotation name.
+ * <br>
+ * Neither the package name or annotation name can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param packageName Package Name of Annotation Type
+ * @param name Name of Annotation Type
+ * @return <code>new</code> instance of Annotation Type Builder.
+ */
public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
+
+ /**
+ * Sets the <code>abstract</code> flag to define Generated Type as <i>abstract</i> type.
+ *
+ * @param isAbstract abstract flag
+ */
+ public void setAbstract(boolean isAbstract);
+
+ /**
+ * Add Type to implements.
+ *
+ * @param genType Type to implement
+ * @return <code>true</code> if the addition of type is successful.
+ */
public boolean addImplementsType(final Type genType);
-
- public ConstantBuilder addConstant(final Type type, final String name,
+
+ /**
+ * Adds Constant definition and returns <code>new</code> Constant instance.
+ * <br>
+ * By definition Constant MUST be defined by return Type,
+ * Name and assigned value. The name SHOULD be defined with cpaital
+ * letters. Neither of method parameters can be <code>null</code> and the
+ * method SHOULD throw {@link IllegalArgumentException} if the contract
+ * is broken.
+ *
+ * @param type Constant Type
+ * @param name Name of Constant
+ * @param value Assigned Value
+ * @return <code>new</code> Constant instance.
+ */
+ public Constant addConstant(final Type type, final String name,
final Object value);
+ /**
+ * Adds new Enumeration definition for Generated Type Builder and returns
+ * Enum Builder for specifying all Enum parameters.
+ * <br>
+ * If there is already Enumeration stored with the same name,
+ * the old enum will be simply overwritten byt new enum definition.
+ * <br>
+ * Name of Enumeration cannot be <code>null</code>,
+ * if it is <code>null</code> the method SHOULD throw {@link IllegalArgumentException}
+ *
+ * @param name Enumeration Name
+ * @return <code>new</code> instance of Enumeration Builder.
+ */
public EnumBuilder addEnumeration(final String name);
+ /**
+ * Add new Method Signature definition for Generated Type Builder and
+ * returns Method Signature Builder for specifying all Method parameters.
+ * <br>
+ * Name of Method cannot be <code>null</code>,
+ * if it is <code>null</code> the method SHOULD throw {@link IllegalArgumentException}
+ * <br>
+ * By <i>Default</i> the MethodSignatureBuilder SHOULD be pre-set as
+ * {@link MethodSignatureBuilder#setAbstract(true)}, {@link MethodSignatureBuilder#setFinal(false)} and
+ * {@link MethodSignatureBuilder#setAccessModifier(PUBLIC)}
+ *
+ * @param name Name of Method
+ * @return <code>new</code> instance of Method Signature Builder.
+ */
public MethodSignatureBuilder addMethod(final String name);
+ /**
+ * Returns the <code>new</code> <i>immutable</i> instance of Generated
+ * Type.
+ *
+ * @return the <code>new</code> <i>immutable</i> instance of Generated
+ * Type.
+ */
public GeneratedType toInstance();
}
import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
import org.opendaylight.controller.sal.binding.model.api.Type;
-public interface MethodSignatureBuilder {
-
- public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
-
- public void addReturnType(final Type returnType);
+/**
+ * Method Signature Builder serves solely for building Method Signature and
+ * returning the <code>new</code> instance of Method Signature.
+ * <br>
+ * By definition of {@link MethodSignature} the Method in java MUST contain
+ * Name, Return Type and Access Modifier. By default the Access Modifier can
+ * be set to public. The Method Signature builder does not contain method for
+ * addName due to enforce reason that MethodSignatureBuilder SHOULD be
+ * instantiated only once with defined method name.
+ * <br>
+ * The methods as {@link #addAnnotation(String, String)} and {@link #setComment(String)}
+ * can be used as optional because not all methods MUST contain annotation or
+ * comment definitions.
+ *
+ *
+ * @see MethodSignature
+ */
+public interface MethodSignatureBuilder extends TypeMemberBuilder {
- public void addParameter(final Type type, final String name);
+ /**
+ * Sets the flag for declaration of method as abstract or non abstract. If the flag <code>isAbstract == true</code>
+ * The instantiated Method Signature MUST have return value for {@link org.opendaylight.controller.sal.binding
+ * .model.api.MethodSignature#isAbstract()} also equals to <code>true</code>.
+ *
+ * @param isAbstract is abstract flag
+ */
+ public void setAbstract(boolean isAbstract);
- public void addComment(final String comment);
+ /**
+ * Adds Parameter into the List of method parameters. Neither the Name or
+ * Type of parameter can be <code>null</code>.
+ *
+ * <br>
+ * In case that any of parameters are defined as <code>null</code> the
+ * method SHOULD throw an {@link IllegalArgumentException}
+ *
+ * @param type Parameter Type
+ * @param name Parameter Name
+ */
+ public void addParameter(final Type type, final String name);
+ /**
+ * Returns <code>new</code> <i>immutable</i> instance of Method Signature.
+ * <br>
+ * The <code>definingType</code> param cannot be <code>null</code>. The
+ * every method in Java MUST be declared and defined inside the scope of
+ * <code>class</code> or <code>interface</code> definition. In case that
+ * defining Type will be passed as <code>null</code> reference the method
+ * SHOULD thrown {@link IllegalArgumentException}.
+ *
+ * @param definingType Defining Type of Method Signature
+ * @return <code>new</code> <i>immutable</i> instance of Method Signature.
+ */
public MethodSignature toInstance(final Type definingType);
}
--- /dev/null
+package org.opendaylight.controller.sal.binding.model.api.type.builder;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+
+/**
+ *
+ */
+public interface TypeMemberBuilder {
+
+ /**
+ * The method creates new AnnotationTypeBuilder containing specified
+ * package name an annotation name.
+ * <br>
+ * Neither the package name or annotation name can contain
+ * <code>null</code> references. In case that
+ * any of parameters contains <code>null</code> the method SHOULD thrown
+ * {@link IllegalArgumentException}
+ *
+ * @param packageName Package Name of Annotation Type
+ * @param name Name of Annotation Type
+ * @return <code>new</code> instance of Annotation Type Builder.
+ */
+ public AnnotationTypeBuilder addAnnotation(final String packageName, final String name);
+
+ /**
+ * Returns the name of property.
+ *
+ * @return the name of property.
+ */
+ public String getName();
+
+ /**
+ * Adds return Type into Builder definition for Generated Property.
+ * <br>
+ * The return Type MUST NOT be <code>null</code>,
+ * otherwise the method SHOULD throw {@link IllegalArgumentException}
+ *
+ * @param returnType Return Type of property.
+ */
+ public void setReturnType(final Type returnType);
+
+ /**
+ * Sets the access modifier of property.
+ *
+ * @param modifier Access Modifier value.
+ */
+ public void setAccessModifier(final AccessModifier modifier);
+
+ /**
+ * Adds String definition of comment into Method Signature definition.
+ * <br>
+ * The comment String MUST NOT contain anny comment specific chars (i.e.
+ * "/**" or "//") just plain String text description.
+ *
+ * @param comment Comment String.
+ */
+ public void setComment(final String comment);
+
+ /**
+ * Sets the flag final for method signature. If this is set the method will be prohibited from overriding.
+ * <br>
+ * This setting is irrelevant for methods designated to be defined in interface definitions because interface
+ * can't have final method.
+ *
+ * @param isFinal Is Final
+ */
+ public void setFinal(final boolean isFinal);
+}