public static final Type UINT16_TYPE = Types.typeForClass(Integer.class);
public static final Type UINT32_TYPE = Types.typeForClass(Long.class);
public static final Type UINT64_TYPE = Types.typeForClass(BigInteger.class);
+ public static final Type BINARY_TYPE = Types.primitiveType("byte[]");
static {
typeMap.put("boolean", BOOLEAN_TYPE);
typeMap.put("uint16", UINT16_TYPE);
typeMap.put("uint32", UINT32_TYPE);
typeMap.put("uint64", UINT64_TYPE);
+ typeMap.put("binary", BINARY_TYPE);
}
public static final TypeProvider BASE_YANG_TYPES_PROVIDER = new TypeProvider() {
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!)");
}
-
if (typeDefinition.getQName().getLocalName() == null) {
throw new IllegalArgumentException("Type Definitions Local Name " +
"cannot be NULL!");
.javaTypeForSchemaDefinitionType(typeDefinition);
}
}
+ //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);
+// }
return returnType;
}
assertNotNull("genTypes is null", genTypes);
assertFalse("genTypes is empty", genTypes.isEmpty());
+
+ //TODO: implement test
}
}
--- /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.generator.impl;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+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;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+public class BinaryTypeTest {
+ private final static List<File> yangModels = new ArrayList<>();
+ private final static String yangModelsFolder = AugmentedTypeTest.class
+ .getResource("/binary-type-test-models").getPath();
+
+ @BeforeClass
+ public static void loadTestResources() {
+ final File augFolder = new File(yangModelsFolder);
+ for (final File fileEntry : augFolder.listFiles()) {
+ if (fileEntry.isFile()) {
+ yangModels.add(fileEntry);
+ }
+ }
+ }
+
+ @Test
+ public void binaryTypeTest() {
+ final YangModelParser parser = new YangParserImpl();
+ final Set<Module> modules = parser.parseYangModels(yangModels);
+ final SchemaContext context = parser.resolveSchemaContext(modules);
+
+ assertNotNull("context is null", context);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
+ final List<Type> genTypes = bindingGen.generateTypes(context);
+
+ assertNotNull("genTypes is null", genTypes);
+ assertFalse("genTypes is empty", genTypes.isEmpty());
+
+ //TODO: implement test
+ }
+}
assertNotNull("genTypes is null", genTypes);
assertFalse("genTypes is empty", genTypes.isEmpty());
+
+ //TODO: implement test
}
}
--- /dev/null
+module binary-type-test {
+ yang-version 1;
+ namespace "urn:binary:types:model";
+ prefix "btt";
+
+ import binary-types {
+ prefix "bin";
+ revision-date 2013-06-13;
+ }
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ description
+ "Simple test to test imported binary types and resolving of binary
+ type in leaf statement.";
+
+ revision "2013-06-13" {
+ reference "NO REF";
+ }
+
+ typedef binary-type {
+ type binary {
+ length 128;
+ }
+ }
+
+ container container-foo {
+ leaf binary-leaf {
+ type binary {
+ length 128;
+ }
+ }
+
+ list binary-list {
+ key "binary-key";
+
+ leaf binary-key {
+ type btt:binary-type;
+ }
+
+ leaf imported-simple-binary {
+ type bin:simple-binary;
+ }
+ }
+
+ leaf imported-restrict-binary {
+ type bin:restricted-binary;
+ }
+
+ leaf-list binary-list {
+ type binary {
+ length 256;
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+ module binary-types {
+
+ namespace "urn:binary:types";
+ prefix "bin";
+
+ organization "OPEN DAYLIGHT";
+
+ contact "http://www.opendaylight.org/";
+
+ description "Stand alone binary types declaration file for testing
+ purposes only.";
+
+ revision 2013-06-13 {
+ description
+ "Initial revision.";
+ reference
+ "NO REFERENCE";
+ }
+
+ /*** collection of protocol field related types ***/
+
+ typedef simple-binary {
+ type binary;
+ }
+
+ typedef restricted-binary {
+ type binary {
+ length 24;
+ }
+ }
+
+ typedef composite-binary {
+ type union {
+ type bin:simple-binary;
+ type bin:restricted-binary;
+ }
+ }
+ }
@Deprecated\r
Type javaTypeForYangType(String type);\r
\r
+ /**\r
+ * Resolve of yang Type Definition to it's java counter part.\r
+ * If the Type Definition contains one of yang primitive types the method\r
+ * will return java.lang. counterpart. (For example if yang type is int32\r
+ * the java counterpart is java.lang.Integer). In case that Type\r
+ * Definition contains extended type defined via yang typedef statement\r
+ * the method SHOULD return Generated Type or Generated Transfer Object\r
+ * if that Type is correctly referenced to resolved imported yang module.\r
+ * The method will return <cdoe>null</cdoe> value in situations that\r
+ * TypeDefinition can't be resolved (either due missing yang import or\r
+ * incorrectly specified type).\r
+ *\r
+ *\r
+ * @param type Type Definition to resolve from\r
+ * @return Resolved Type\r
+ */\r
Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type);\r
}\r
\r
@Override\r
public String toString() {\r
-\r
+ if (packageName.isEmpty()) {\r
+ return "Type (" + name + ")";\r
+ }\r
return "Type (" + packageName + "." + name + ")";\r
}\r
\r
private static final Type SET_TYPE = typeForClass(Set.class);\r
private static final Type LIST_TYPE = typeForClass(List.class);\r
private static final Type MAP_TYPE = typeForClass(Map.class);\r
- \r
public static final Type DATA_OBJECT = typeForClass(DataObject.class);\r
- \r
- private Types() {\r
- }\r
\r
public static ConcreteType voidType() {\r
return new ConcreteTypeImpl(Void.class.getPackage().getName(),\r
Void.class.getSimpleName());\r
}\r
\r
+ public static final Type primitiveType(final String primitiveType) {\r
+ return new ConcreteTypeImpl("", primitiveType);\r
+ }\r
+\r
+\r
/**\r
* Returns an instance of {@link ConcreteType} describing the class\r
* \r
if (packageName.startsWith("java.lang")) {
builder.append(type.getName());
} else {
- builder.append(packageName + "." + type.getName());
+ if (!packageName.isEmpty()) {
+ builder.append(packageName + "." + type.getName());
+ } else {
+ builder.append(type.getName());
+ }
+
}
if (type instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) type;
String genTypePkg) {
String typeName = type.getName();
String typePkg = type.getPackageName();
- if (typePkg.startsWith("java.lang") || typePkg.equals(genTypePkg)) {
+ if (typePkg.startsWith("java.lang") || typePkg.equals(genTypePkg) ||
+ typePkg.isEmpty()) {
return;
}
LinkedHashMap<String, Integer> packages = importedTypes.get(typeName);