import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.opendaylight.yangtools.yang.model.util.UnionType;
import static com.google.common.base.Preconditions.*;
import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.*;
import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
public class BindingGeneratorImpl implements BindingGenerator {
- /**
+ /**
* Outter key represents the package name. Outter value represents map of
* all builders in the same package. Inner key represents the schema node
* name (in JAVA class/interface name format). Inner value represents
* instance of builder for schema node specified in key part.
*/
- private Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders;
+ private Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders;
- /**
+ /**
* Provide methods for converting YANG types to JAVA types.
*/
- private var TypeProvider typeProvider;
+ private var TypeProvider typeProvider;
- /**
+ /**
* Holds reference to schema context to resolve data of augmented elemnt
* when creating augmentation builder
*/
- private var SchemaContext schemaContext;
+ private var SchemaContext schemaContext;
- /**
+ /**
* Each grouping which is converted from schema node to generated type is
* added to this map with its Schema path as key to make it easier to get
* reference to it. In schema nodes in <code>uses</code> attribute there is
* Schema node the object of type <code>Type</code> is required. So in this
* case is used this map.
*/
- private val allGroupings = new HashMap<SchemaPath, GeneratedType>();
+ private val allGroupings = new HashMap<SchemaPath, GeneratedType>();
- private val yangToJavaMapping = new HashMap<SchemaPath, Type>();
+ private val yangToJavaMapping = new HashMap<SchemaPath, Type>();
- /**
+ /**
* Constant with the concrete name of namespace.
*/
- private val static String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext";
+ private val static String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext";
- /**
+ /**
* Constant with the concrete name of identifier.
*/
- private val static String AUGMENT_IDENTIFIER_NAME = "augment-identifier";
+ private val static String AUGMENT_IDENTIFIER_NAME = "augment-identifier";
- /**
+ /**
* Resolves generated types from <code>context</code> schema nodes of all
* modules.
*
* @throws IllegalStateException
* if <code>context</code> contain no modules
*/
- override generateTypes(SchemaContext context) {
- checkArgument(context !== null, "Schema Context reference cannot be NULL.");
- checkState(context.modules !== null, "Schema Context does not contain defined modules.");
- val List<Type> generatedTypes = new ArrayList();
- schemaContext = context;
- typeProvider = new TypeProviderImpl(context);
- val Set<Module> modules = context.modules;
- return generateTypes(context, modules);
- }
-
- /**
+ override generateTypes(SchemaContext context) {
+ checkArgument(context !== null, "Schema Context reference cannot be NULL.");
+ checkState(context.modules !== null, "Schema Context does not contain defined modules.");
+ val List<Type> generatedTypes = new ArrayList();
+ schemaContext = context;
+ typeProvider = new TypeProviderImpl(context);
+ val Set<Module> modules = context.modules;
+ return generateTypes(context, modules);
+ }
+
+ /**
* Resolves generated types from <code>context</code> schema nodes only for
* modules specified in <code>modules</code>
*
* @throws IllegalStateException
* if <code>context</code> contain no modules
*/
- override generateTypes(SchemaContext context, Set<Module> modules) {
- checkArgument(context !== null, "Schema Context reference cannot be NULL.");
- checkState(context.modules !== null, "Schema Context does not contain defined modules.");
- checkArgument(modules !== null, "Set of Modules cannot be NULL.");
-
- val List<Type> filteredGenTypes = new ArrayList();
-
- schemaContext = context;
- typeProvider = new TypeProviderImpl(context);
- val contextModules = ModuleDependencySort.sort(context.modules);
- genTypeBuilders = new HashMap();
-
- for (contextModule : contextModules) {
- val List<Type> generatedTypes = new ArrayList();
- generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule));
- generatedTypes.addAll(allGroupingsToGenTypes(contextModule));
- if (false == contextModule.childNodes.isEmpty()) {
- generatedTypes.add(moduleToDataType(contextModule));
- }
- generatedTypes.addAll(allContainersToGenTypes(contextModule));
- generatedTypes.addAll(allListsToGenTypes(contextModule));
- generatedTypes.addAll(allChoicesToGenTypes(contextModule));
- generatedTypes.addAll(allRPCMethodsToGenType(contextModule));
- generatedTypes.addAll(allNotificationsToGenType(contextModule));
- generatedTypes.addAll(allIdentitiesToGenTypes(contextModule, context));
-
- if (modules.contains(contextModule)) {
- filteredGenTypes.addAll(generatedTypes);
- }
- }
- for (contextModule : contextModules) {
- val generatedTypes = (allAugmentsToGenTypes(contextModule));
- if (modules.contains(contextModule)) {
- filteredGenTypes.addAll(generatedTypes);
- }
-
- }
- return filteredGenTypes;
- }
-
- /**
+ override generateTypes(SchemaContext context, Set<Module> modules) {
+ checkArgument(context !== null, "Schema Context reference cannot be NULL.");
+ checkState(context.modules !== null, "Schema Context does not contain defined modules.");
+ checkArgument(modules !== null, "Set of Modules cannot be NULL.");
+
+ val List<Type> filteredGenTypes = new ArrayList();
+
+ schemaContext = context;
+ typeProvider = new TypeProviderImpl(context);
+ val contextModules = ModuleDependencySort.sort(context.modules);
+ genTypeBuilders = new HashMap();
+
+ for (contextModule : contextModules) {
+ val List<Type> generatedTypes = new ArrayList();
+ generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule));
+ generatedTypes.addAll(allGroupingsToGenTypes(contextModule));
+ if (false == contextModule.childNodes.isEmpty()) {
+ generatedTypes.add(moduleToDataType(contextModule));
+ }
+ generatedTypes.addAll(allContainersToGenTypes(contextModule));
+ generatedTypes.addAll(allListsToGenTypes(contextModule));
+ generatedTypes.addAll(allChoicesToGenTypes(contextModule));
+ generatedTypes.addAll(allRPCMethodsToGenType(contextModule));
+ generatedTypes.addAll(allNotificationsToGenType(contextModule));
+ generatedTypes.addAll(allIdentitiesToGenTypes(contextModule, context));
+
+ if (modules.contains(contextModule)) {
+ filteredGenTypes.addAll(generatedTypes);
+ }
+ }
+ for (contextModule : contextModules) {
+ val generatedTypes = (allAugmentsToGenTypes(contextModule));
+ if (modules.contains(contextModule)) {
+ filteredGenTypes.addAll(generatedTypes);
+ }
+
+ }
+ return filteredGenTypes;
+ }
+
+ /**
* Converts all extended type definitions of module to the list of
* <code>Type</code> objects.
*
* </ul>
*
*/
- private def List<Type> allTypeDefinitionsToGenTypes(Module module) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
- checkArgument(module.name !== null, "Module name cannot be NULL.");
- val Set<TypeDefinition<?>> typeDefinitions = module.typeDefinitions;
- checkState(typeDefinitions !== null, '''Type Definitions for module «module.name» cannot be NULL.''');
-
- val List<Type> generatedTypes = new ArrayList();
- for (TypeDefinition<?> typedef : typeDefinitions) {
- if (typedef !== null) {
- val type = (typeProvider as TypeProviderImpl).generatedTypeForExtendedDefinitionType(typedef, typedef);
- if ((type !== null) && !generatedTypes.contains(type)) {
- generatedTypes.add(type);
- }
- }
- }
- return generatedTypes;
- }
-
- /**
+ private def List<Type> allTypeDefinitionsToGenTypes(Module module) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+ checkArgument(module.name !== null, "Module name cannot be NULL.");
+ val Set<TypeDefinition<?>> typeDefinitions = module.typeDefinitions;
+ checkState(typeDefinitions !== null, '''Type Definitions for module «module.name» cannot be NULL.''');
+
+ val List<Type> generatedTypes = new ArrayList();
+ for (TypeDefinition<?> typedef : typeDefinitions) {
+ if (typedef !== null) {
+ val type = (typeProvider as TypeProviderImpl).generatedTypeForExtendedDefinitionType(typedef, typedef);
+ if ((type !== null) && !generatedTypes.contains(type)) {
+ generatedTypes.add(type);
+ }
+ }
+ }
+ return generatedTypes;
+ }
+
+ /**
* Converts all <b>containers</b> of the module to the list of
* <code>Type</code> objects.
*
* </ul>
*
*/
- private def List<Type> allContainersToGenTypes(Module module) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
-
- checkArgument(module.name !== null, "Module name cannot be NULL.");
-
- if (module.childNodes === null) {
- throw new IllegalArgumentException(
- "Reference to Set of Child Nodes in module " + module.name + " cannot be NULL.");
- }
-
- val List<Type> generatedTypes = new ArrayList();
- val it = new DataNodeIterator(module);
- val List<ContainerSchemaNode> schemaContainers = it.allContainers();
- val basePackageName = moduleNamespaceToPackageName(module);
- for (container : schemaContainers) {
- if (!container.isAddedByUses()) {
- generatedTypes.add(containerToGenType(basePackageName, container));
- }
- }
- return generatedTypes;
- }
-
- /**
+ private def List<Type> allContainersToGenTypes(Module module) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+
+ checkArgument(module.name !== null, "Module name cannot be NULL.");
+
+ if (module.childNodes === null) {
+ throw new IllegalArgumentException(
+ "Reference to Set of Child Nodes in module " + module.name + " cannot be NULL.");
+ }
+
+ val List<Type> generatedTypes = new ArrayList();
+ val it = new DataNodeIterator(module);
+ val List<ContainerSchemaNode> schemaContainers = it.allContainers();
+ val basePackageName = moduleNamespaceToPackageName(module);
+ for (container : schemaContainers) {
+ if (!container.isAddedByUses()) {
+ generatedTypes.add(containerToGenType(basePackageName, container));
+ }
+ }
+ return generatedTypes;
+ }
+
+ /**
* Converts all <b>lists</b> of the module to the list of <code>Type</code>
* objects.
*
* </ul>
*
*/
- private def List<Type> allListsToGenTypes(Module module) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
- checkArgument(module.name !== null, "Module name cannot be NULL.");
-
- if (module.childNodes === null) {
- throw new IllegalArgumentException(
- "Reference to Set of Child Nodes in module " + module.name + " cannot be NULL.");
- }
-
- val List<Type> generatedTypes = new ArrayList();
- val it = new DataNodeIterator(module);
- val List<ListSchemaNode> schemaLists = it.allLists();
- val basePackageName = moduleNamespaceToPackageName(module);
- if (schemaLists !== null) {
- for (list : schemaLists) {
- if (!list.isAddedByUses()) {
- generatedTypes.addAll(listToGenType(basePackageName, list));
- }
- }
- }
- return generatedTypes;
- }
-
- /**
+ private def List<Type> allListsToGenTypes(Module module) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+ checkArgument(module.name !== null, "Module name cannot be NULL.");
+
+ if (module.childNodes === null) {
+ throw new IllegalArgumentException(
+ "Reference to Set of Child Nodes in module " + module.name + " cannot be NULL.");
+ }
+
+ val List<Type> generatedTypes = new ArrayList();
+ val it = new DataNodeIterator(module);
+ val List<ListSchemaNode> schemaLists = it.allLists();
+ val basePackageName = moduleNamespaceToPackageName(module);
+ if (schemaLists !== null) {
+ for (list : schemaLists) {
+ if (!list.isAddedByUses()) {
+ generatedTypes.addAll(listToGenType(basePackageName, list));
+ }
+ }
+ }
+ return generatedTypes;
+ }
+
+ /**
* Converts all <b>choices</b> of the module to the list of
* <code>Type</code> objects.
*
* </ul>
*
*/
- private def List<GeneratedType> allChoicesToGenTypes(Module module) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
- checkArgument(module.name !== null, "Module name cannot be NULL.");
-
- val it = new DataNodeIterator(module);
- val choiceNodes = it.allChoices();
- val basePackageName = moduleNamespaceToPackageName(module);
-
- val List<GeneratedType> generatedTypes = new ArrayList();
- for (choice : choiceNodes) {
- if ((choice !== null) && !choice.isAddedByUses()) {
- generatedTypes.addAll(choiceToGeneratedType(basePackageName, choice));
- }
- }
- return generatedTypes;
- }
-
- /**
+ private def List<GeneratedType> allChoicesToGenTypes(Module module) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+ checkArgument(module.name !== null, "Module name cannot be NULL.");
+
+ val it = new DataNodeIterator(module);
+ val choiceNodes = it.allChoices();
+ val basePackageName = moduleNamespaceToPackageName(module);
+
+ val List<GeneratedType> generatedTypes = new ArrayList();
+ for (choice : choiceNodes) {
+ if ((choice !== null) && !choice.isAddedByUses()) {
+ generatedTypes.addAll(choiceToGeneratedType(basePackageName, choice));
+ }
+ }
+ return generatedTypes;
+ }
+
+ /**
* Converts all <b>augmentation</b> of the module to the list
* <code>Type</code> objects.
*
* </ul>
*
*/
- private def List<Type> allAugmentsToGenTypes(Module module) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
- checkArgument(module.name !== null, "Module name cannot be NULL.");
- if (module.childNodes === null) {
- throw new IllegalArgumentException(
- "Reference to Set of Augmentation Definitions in module " + module.name + " cannot be NULL.");
- }
-
- val List<Type> generatedTypes = new ArrayList();
- val basePackageName = moduleNamespaceToPackageName(module);
- val List<AugmentationSchema> augmentations = resolveAugmentations(module);
- for (augment : augmentations) {
- generatedTypes.addAll(augmentationToGenTypes(basePackageName, augment));
- }
- return generatedTypes;
- }
-
- /**
+ private def List<Type> allAugmentsToGenTypes(Module module) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+ checkArgument(module.name !== null, "Module name cannot be NULL.");
+ if (module.childNodes === null) {
+ throw new IllegalArgumentException(
+ "Reference to Set of Augmentation Definitions in module " + module.name + " cannot be NULL.");
+ }
+
+ val List<Type> generatedTypes = new ArrayList();
+ val basePackageName = moduleNamespaceToPackageName(module);
+ val List<AugmentationSchema> augmentations = resolveAugmentations(module);
+ for (augment : augmentations) {
+ generatedTypes.addAll(augmentationToGenTypes(basePackageName, augment));
+ }
+ return generatedTypes;
+ }
+
+ /**
* Returns list of <code>AugmentationSchema</code> objects. The objects are
* sorted according to the length of their target path from the shortest to
* the longest.
* </ul>
*
*/
- private def List<AugmentationSchema> resolveAugmentations(Module module) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
- checkState(module.augmentations !== null, "Augmentations Set cannot be NULL.");
-
- val Set<AugmentationSchema> augmentations = module.augmentations;
- val List<AugmentationSchema> sortedAugmentations = new ArrayList(augmentations);
- Collections.sort(sortedAugmentations,
- [ augSchema1, augSchema2 |
- if (augSchema1.targetPath.path.size() > augSchema2.targetPath.path.size()) {
- return 1;
- } else if (augSchema1.targetPath.path.size() < augSchema2.targetPath.path.size()) {
- return -1;
- }
- return 0;
- ]);
- return sortedAugmentations;
- }
-
- /**
+ private def List<AugmentationSchema> resolveAugmentations(Module module) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+ checkState(module.augmentations !== null, "Augmentations Set cannot be NULL.");
+
+ val Set<AugmentationSchema> augmentations = module.augmentations;
+ val List<AugmentationSchema> sortedAugmentations = new ArrayList(augmentations);
+ Collections.sort(sortedAugmentations,
+ [ augSchema1, augSchema2 |
+ if (augSchema1.targetPath.path.size() > augSchema2.targetPath.path.size()) {
+ return 1;
+ } else if (augSchema1.targetPath.path.size() < augSchema2.targetPath.path.size()) {
+ return -1;
+ }
+ return 0;
+ ]);
+ return sortedAugmentations;
+ }
+
+ /**
* Converts whole <b>module</b> to <code>GeneratedType</code> object.
* Firstly is created the module builder object from which is vally
* obtained reference to <code>GeneratedType</code> object.
* if the module equals null
*
*/
- private def GeneratedType moduleToDataType(Module module) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
-
- val moduleDataTypeBuilder = moduleTypeBuilder(module, "Data");
- addImplementedInterfaceFromUses(module, moduleDataTypeBuilder);
- moduleDataTypeBuilder.addImplementsType(DATA_ROOT);
-
- val basePackageName = moduleNamespaceToPackageName(module);
- if (moduleDataTypeBuilder !== null) {
- val Set<DataSchemaNode> dataNodes = module.childNodes;
- resolveDataSchemaNodes(basePackageName, moduleDataTypeBuilder, dataNodes);
- }
- return moduleDataTypeBuilder.toInstance();
- }
-
- /**
+ private def GeneratedType moduleToDataType(Module module) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+
+ val moduleDataTypeBuilder = moduleTypeBuilder(module, "Data");
+ addImplementedInterfaceFromUses(module, moduleDataTypeBuilder);
+ moduleDataTypeBuilder.addImplementsType(DATA_ROOT);
+
+ val basePackageName = moduleNamespaceToPackageName(module);
+ if (moduleDataTypeBuilder !== null) {
+ val Set<DataSchemaNode> dataNodes = module.childNodes;
+ resolveDataSchemaNodes(basePackageName, moduleDataTypeBuilder, dataNodes);
+ }
+ return moduleDataTypeBuilder.toInstance();
+ }
+
+ /**
* Converts all <b>rpcs</b> inputs and outputs substatements of the module
* to the list of <code>Type</code> objects. In addition are to containers
* and lists which belong to input or output also part of returning list.
* </ul>
*
*/
- private def List<Type> allRPCMethodsToGenType(Module module) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
-
- checkArgument(module.name !== null, "Module name cannot be NULL.");
-
- if (module.childNodes === null) {
- throw new IllegalArgumentException(
- "Reference to Set of RPC Method Definitions in module " + module.name + " cannot be NULL.");
- }
-
- val basePackageName = moduleNamespaceToPackageName(module);
- val Set<RpcDefinition> rpcDefinitions = module.rpcs;
-
- if (rpcDefinitions.isEmpty()) {
- return Collections.emptyList();
- }
-
- val List<Type> genRPCTypes = new ArrayList();
- val interfaceBuilder = moduleTypeBuilder(module, "Service");
- interfaceBuilder.addImplementsType(Types.typeForClass(RpcService));
- for (rpc : rpcDefinitions) {
- if (rpc !== null) {
-
- val rpcName = parseToClassName(rpc.QName.localName);
- val rpcMethodName = parseToValidParamName(rpcName);
- val method = interfaceBuilder.addMethod(rpcMethodName);
-
- val rpcInOut = new ArrayList();
-
- val input = rpc.input;
- val output = rpc.output;
-
- if (input !== null) {
- rpcInOut.add(new DataNodeIterator(input));
- val inType = addRawInterfaceDefinition(basePackageName, input, rpcName);
- addImplementedInterfaceFromUses(input, inType);
- inType.addImplementsType(DATA_OBJECT);
- inType.addImplementsType(augmentable(inType));
- resolveDataSchemaNodes(basePackageName, inType, input.childNodes);
- val inTypeInstance = inType.toInstance();
- genRPCTypes.add(inTypeInstance);
- method.addParameter(inTypeInstance, "input");
- }
-
- var Type outTypeInstance = VOID;
- if (output !== null) {
- rpcInOut.add(new DataNodeIterator(output));
- val outType = addRawInterfaceDefinition(basePackageName, output, rpcName);
- addImplementedInterfaceFromUses(output, outType);
- outType.addImplementsType(DATA_OBJECT);
- outType.addImplementsType(augmentable(outType));
-
- resolveDataSchemaNodes(basePackageName, outType, output.childNodes);
- outTypeInstance = outType.toInstance();
- genRPCTypes.add(outTypeInstance);
-
- }
-
- val rpcRes = Types.parameterizedTypeFor(Types.typeForClass(RpcResult), outTypeInstance);
- method.setReturnType(Types.parameterizedTypeFor(FUTURE, rpcRes));
- for (iter : rpcInOut) {
- val List<ContainerSchemaNode> nContainers = iter.allContainers();
- if ((nContainers !== null) && !nContainers.isEmpty()) {
- for (container : nContainers) {
- if (!container.isAddedByUses()) {
- genRPCTypes.add(containerToGenType(basePackageName, container));
- }
- }
- }
- val List<ListSchemaNode> nLists = iter.allLists();
- if ((nLists !== null) && !nLists.isEmpty()) {
- for (list : nLists) {
- if (!list.isAddedByUses()) {
- genRPCTypes.addAll(listToGenType(basePackageName, list));
- }
- }
- }
- }
- }
- }
- genRPCTypes.add(interfaceBuilder.toInstance());
- return genRPCTypes;
- }
-
- /**
+ private def List<Type> allRPCMethodsToGenType(Module module) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+
+ checkArgument(module.name !== null, "Module name cannot be NULL.");
+
+ if (module.childNodes === null) {
+ throw new IllegalArgumentException(
+ "Reference to Set of RPC Method Definitions in module " + module.name + " cannot be NULL.");
+ }
+
+ val basePackageName = moduleNamespaceToPackageName(module);
+ val Set<RpcDefinition> rpcDefinitions = module.rpcs;
+
+ if (rpcDefinitions.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ val List<Type> genRPCTypes = new ArrayList();
+ val interfaceBuilder = moduleTypeBuilder(module, "Service");
+ interfaceBuilder.addImplementsType(Types.typeForClass(RpcService));
+ for (rpc : rpcDefinitions) {
+ if (rpc !== null) {
+
+ val rpcName = parseToClassName(rpc.QName.localName);
+ val rpcMethodName = parseToValidParamName(rpcName);
+ val method = interfaceBuilder.addMethod(rpcMethodName);
+
+ val rpcInOut = new ArrayList();
+
+ val input = rpc.input;
+ val output = rpc.output;
+
+ if (input !== null) {
+ rpcInOut.add(new DataNodeIterator(input));
+ val inType = addRawInterfaceDefinition(basePackageName, input, rpcName);
+ addImplementedInterfaceFromUses(input, inType);
+ inType.addImplementsType(DATA_OBJECT);
+ inType.addImplementsType(augmentable(inType));
+ resolveDataSchemaNodes(basePackageName, inType, input.childNodes);
+ val inTypeInstance = inType.toInstance();
+ genRPCTypes.add(inTypeInstance);
+ method.addParameter(inTypeInstance, "input");
+ }
+
+ var Type outTypeInstance = VOID;
+ if (output !== null) {
+ rpcInOut.add(new DataNodeIterator(output));
+ val outType = addRawInterfaceDefinition(basePackageName, output, rpcName);
+ addImplementedInterfaceFromUses(output, outType);
+ outType.addImplementsType(DATA_OBJECT);
+ outType.addImplementsType(augmentable(outType));
+
+ resolveDataSchemaNodes(basePackageName, outType, output.childNodes);
+ outTypeInstance = outType.toInstance();
+ genRPCTypes.add(outTypeInstance);
+
+ }
+
+ val rpcRes = Types.parameterizedTypeFor(Types.typeForClass(RpcResult), outTypeInstance);
+ method.setReturnType(Types.parameterizedTypeFor(FUTURE, rpcRes));
+ for (iter : rpcInOut) {
+ val List<ContainerSchemaNode> nContainers = iter.allContainers();
+ if ((nContainers !== null) && !nContainers.isEmpty()) {
+ for (container : nContainers) {
+ if (!container.isAddedByUses()) {
+ genRPCTypes.add(containerToGenType(basePackageName, container));
+ }
+ }
+ }
+ val List<ListSchemaNode> nLists = iter.allLists();
+ if ((nLists !== null) && !nLists.isEmpty()) {
+ for (list : nLists) {
+ if (!list.isAddedByUses()) {
+ genRPCTypes.addAll(listToGenType(basePackageName, list));
+ }
+ }
+ }
+ }
+ }
+ }
+ genRPCTypes.add(interfaceBuilder.toInstance());
+ return genRPCTypes;
+ }
+
+ /**
* Converts all <b>notifications</b> of the module to the list of
* <code>Type</code> objects. In addition are to this list added containers
* and lists which are part of this notification.
* </ul>
*
*/
- private def List<Type> allNotificationsToGenType(Module module) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
-
- checkArgument(module.name !== null, "Module name cannot be NULL.");
-
- if (module.childNodes === null) {
- throw new IllegalArgumentException(
- "Reference to Set of Notification Definitions in module " + module.name + " cannot be NULL.");
- }
- val notifications = module.notifications;
- if(notifications.isEmpty()) return Collections.emptyList();
-
- val listenerInterface = moduleTypeBuilder(module, "Listener");
- listenerInterface.addImplementsType(BindingTypes.NOTIFICATION_LISTENER);
-
- val basePackageName = moduleNamespaceToPackageName(module);
- val List<Type> generatedTypes = new ArrayList();
-
- for (notification : notifications) {
- if (notification !== null) {
- val iter = new DataNodeIterator(notification);
-
- // Containers
- for (node : iter.allContainers()) {
- if (!node.isAddedByUses()) {
- generatedTypes.add(containerToGenType(basePackageName, node));
- }
- }
-
- // Lists
- for (node : iter.allLists()) {
- if (!node.isAddedByUses()) {
- generatedTypes.addAll(listToGenType(basePackageName, node));
- }
- }
- val notificationInterface = addDefaultInterfaceDefinition(basePackageName, notification);
- notificationInterface.addImplementsType(NOTIFICATION);
-
- // Notification object
- resolveDataSchemaNodes(basePackageName, notificationInterface, notification.childNodes);
-
- listenerInterface.addMethod("on" + notificationInterface.name) //
- .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification").
- setReturnType(Types.VOID);
-
- generatedTypes.add(notificationInterface.toInstance());
- }
- }
- generatedTypes.add(listenerInterface.toInstance());
- return generatedTypes;
- }
-
- /**
+ private def List<Type> allNotificationsToGenType(Module module) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+
+ checkArgument(module.name !== null, "Module name cannot be NULL.");
+
+ if (module.childNodes === null) {
+ throw new IllegalArgumentException(
+ "Reference to Set of Notification Definitions in module " + module.name + " cannot be NULL.");
+ }
+ val notifications = module.notifications;
+ if(notifications.isEmpty()) return Collections.emptyList();
+
+ val listenerInterface = moduleTypeBuilder(module, "Listener");
+ listenerInterface.addImplementsType(BindingTypes.NOTIFICATION_LISTENER);
+
+ val basePackageName = moduleNamespaceToPackageName(module);
+ val List<Type> generatedTypes = new ArrayList();
+
+ for (notification : notifications) {
+ if (notification !== null) {
+ val iter = new DataNodeIterator(notification);
+
+ // Containers
+ for (node : iter.allContainers()) {
+ if (!node.isAddedByUses()) {
+ generatedTypes.add(containerToGenType(basePackageName, node));
+ }
+ }
+
+ // Lists
+ for (node : iter.allLists()) {
+ if (!node.isAddedByUses()) {
+ generatedTypes.addAll(listToGenType(basePackageName, node));
+ }
+ }
+ val notificationInterface = addDefaultInterfaceDefinition(basePackageName, notification);
+ notificationInterface.addImplementsType(NOTIFICATION);
+
+ // Notification object
+ resolveDataSchemaNodes(basePackageName, notificationInterface, notification.childNodes);
+
+ listenerInterface.addMethod("on" + notificationInterface.name) //
+ .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification").
+ setReturnType(Types.VOID);
+
+ generatedTypes.add(notificationInterface.toInstance());
+ }
+ }
+ generatedTypes.add(listenerInterface.toInstance());
+ return generatedTypes;
+ }
+
+ /**
* Converts all <b>identities</b> of the module to the list of
* <code>Type</code> objects.
*
* (object of type <code>IdentitySchemaNode</code>
*
*/
- private def List<Type> allIdentitiesToGenTypes(Module module, SchemaContext context) {
- val List<Type> genTypes = new ArrayList();
+ private def List<Type> allIdentitiesToGenTypes(Module module, SchemaContext context) {
+ val List<Type> genTypes = new ArrayList();
- val Set<IdentitySchemaNode> schemaIdentities = module.identities;
+ val Set<IdentitySchemaNode> schemaIdentities = module.identities;
- val basePackageName = moduleNamespaceToPackageName(module);
+ val basePackageName = moduleNamespaceToPackageName(module);
- if (schemaIdentities !== null && !schemaIdentities.isEmpty()) {
- for (identity : schemaIdentities) {
- genTypes.add(identityToGenType(basePackageName, identity, context));
- }
- }
- return genTypes;
- }
+ if (schemaIdentities !== null && !schemaIdentities.isEmpty()) {
+ for (identity : schemaIdentities) {
+ genTypes.add(identityToGenType(basePackageName, identity, context));
+ }
+ }
+ return genTypes;
+ }
- /**
+ /**
* Converts the <b>identity</b> object to GeneratedType. Firstly it is
* created transport object builder. If identity contains base identity then
* reference to base identity is added to superior identity as its extend.
* <code>IdentitySchemaNode</code>
*
*/
- private def GeneratedType identityToGenType(String basePackageName, IdentitySchemaNode identity,
- SchemaContext context) {
- if (identity === null) {
- return null;
- }
-
- val packageName = packageNameForGeneratedType(basePackageName, identity.path);
- val genTypeName = parseToClassName(identity.QName.localName);
- val newType = new GeneratedTOBuilderImpl(packageName, genTypeName);
-
- val baseIdentity = identity.baseIdentity;
- if (baseIdentity !== null) {
- val baseIdentityParentModule = SchemaContextUtil.findParentModule(context, baseIdentity);
-
- val returnTypePkgName = moduleNamespaceToPackageName(baseIdentityParentModule);
- val returnTypeName = parseToClassName(baseIdentity.QName.localName);
-
- val gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance();
- newType.setExtendsType(gto);
- } else {
- newType.setExtendsType(Types.baseIdentityTO);
- }
- newType.setAbstract(true);
- return newType.toInstance();
- }
-
- /**
+ private def GeneratedType identityToGenType(String basePackageName, IdentitySchemaNode identity,
+ SchemaContext context) {
+ if (identity === null) {
+ return null;
+ }
+
+ val packageName = packageNameForGeneratedType(basePackageName, identity.path);
+ val genTypeName = parseToClassName(identity.QName.localName);
+ val newType = new GeneratedTOBuilderImpl(packageName, genTypeName);
+
+ val baseIdentity = identity.baseIdentity;
+ if (baseIdentity !== null) {
+ val baseIdentityParentModule = SchemaContextUtil.findParentModule(context, baseIdentity);
+
+ val returnTypePkgName = moduleNamespaceToPackageName(baseIdentityParentModule);
+ val returnTypeName = parseToClassName(baseIdentity.QName.localName);
+
+ val gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance();
+ newType.setExtendsType(gto);
+ } else {
+ newType.setExtendsType(Types.baseIdentityTO);
+ }
+ newType.setAbstract(true);
+ return newType.toInstance();
+ }
+
+ /**
* Converts all <b>groupings</b> of the module to the list of
* <code>Type</code> objects. Firstly are groupings sorted according mutual
* dependencies. At least dependend (indepedent) groupings are in the list
* (object of type <code>GroupingDefinition</code>)
*
*/
- private def List<Type> allGroupingsToGenTypes(Module module) {
- checkArgument(module !== null, "Module parameter can not be null");
- val List<Type> genTypes = new ArrayList();
- val basePackageName = moduleNamespaceToPackageName(module);
- val Set<GroupingDefinition> groupings = module.groupings;
- val List<GroupingDefinition> groupingsSortedByDependencies = new GroupingDefinitionDependencySort().sort(
- groupings);
-
- for (grouping : groupingsSortedByDependencies) {
- val genType = groupingToGenType(basePackageName, grouping);
- genTypes.add(genType);
- val schemaPath = grouping.path;
- allGroupings.put(schemaPath, genType);
- }
- return genTypes;
- }
-
- /**
+ private def List<Type> allGroupingsToGenTypes(Module module) {
+ checkArgument(module !== null, "Module parameter can not be null");
+ val List<Type> genTypes = new ArrayList();
+ val basePackageName = moduleNamespaceToPackageName(module);
+ val Set<GroupingDefinition> groupings = module.groupings;
+ val List<GroupingDefinition> groupingsSortedByDependencies = new GroupingDefinitionDependencySort().sort(
+ groupings);
+
+ for (grouping : groupingsSortedByDependencies) {
+ val genType = groupingToGenType(basePackageName, grouping);
+ genTypes.add(genType);
+ val schemaPath = grouping.path;
+ allGroupings.put(schemaPath, genType);
+ }
+ return genTypes;
+ }
+
+ /**
* Converts individual grouping to GeneratedType. Firstly generated type
* builder is created and every child node of grouping is resolved to the
* method.
* @return GeneratedType which is generated from grouping (object of type
* <code>GroupingDefinition</code>)
*/
- private def GeneratedType groupingToGenType(String basePackageName, GroupingDefinition grouping) {
- if (grouping === null) {
- return null;
- }
+ private def GeneratedType groupingToGenType(String basePackageName, GroupingDefinition grouping) {
+ if (grouping === null) {
+ return null;
+ }
- val packageName = packageNameForGeneratedType(basePackageName, grouping.path);
- val Set<DataSchemaNode> schemaNodes = grouping.childNodes;
- val typeBuilder = addDefaultInterfaceDefinition(packageName, grouping);
+ val packageName = packageNameForGeneratedType(basePackageName, grouping.path);
+ val Set<DataSchemaNode> schemaNodes = grouping.childNodes;
+ val typeBuilder = addDefaultInterfaceDefinition(packageName, grouping);
- resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes);
- return typeBuilder.toInstance();
- }
+ resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes);
+ return typeBuilder.toInstance();
+ }
- /**
+ /**
* Tries to find EnumTypeDefinition in <code>typeDefinition</code>. If base
* type of <code>typeDefinition</code> is of the type ExtendedType then this
* method is recursivelly called with this base type.
* @return EnumTypeDefinition if it is found inside
* <code>typeDefinition</code> or <code>null</code> in other case
*/
- private def EnumTypeDefinition enumTypeDefFromExtendedType(TypeDefinition<?> typeDefinition) {
- if (typeDefinition !== null) {
- if (typeDefinition.baseType instanceof EnumTypeDefinition) {
- return typeDefinition.baseType as EnumTypeDefinition;
- } else if (typeDefinition.baseType instanceof ExtendedType) {
- return enumTypeDefFromExtendedType(typeDefinition.baseType);
- }
- }
- return null;
- }
-
- /**
+ private def EnumTypeDefinition enumTypeDefFromExtendedType(TypeDefinition<?> typeDefinition) {
+ if (typeDefinition !== null) {
+ if (typeDefinition.baseType instanceof EnumTypeDefinition) {
+ return typeDefinition.baseType as EnumTypeDefinition;
+ } else if (typeDefinition.baseType instanceof ExtendedType) {
+ return enumTypeDefFromExtendedType(typeDefinition.baseType);
+ }
+ }
+ return null;
+ }
+
+ /**
* Adds enumeration builder created from <code>enumTypeDef</code> to
* <code>typeBuilder</code>.
*
* @return enumeration builder which contais data from
* <code>enumTypeDef</code>
*/
- private def EnumBuilder resolveInnerEnumFromTypeDefinition(EnumTypeDefinition enumTypeDef, String enumName,
- GeneratedTypeBuilder typeBuilder) {
- if ((enumTypeDef !== null) && (typeBuilder !== null) && (enumTypeDef.QName !== null) &&
- (enumTypeDef.QName.localName !== null)) {
+ private def EnumBuilder resolveInnerEnumFromTypeDefinition(EnumTypeDefinition enumTypeDef, String enumName,
+ GeneratedTypeBuilder typeBuilder) {
+ if ((enumTypeDef !== null) && (typeBuilder !== null) && (enumTypeDef.QName !== null) &&
+ (enumTypeDef.QName.localName !== null)) {
- val enumerationName = parseToClassName(enumName);
- val enumBuilder = typeBuilder.addEnumeration(enumerationName);
- enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
+ val enumerationName = parseToClassName(enumName);
+ val enumBuilder = typeBuilder.addEnumeration(enumerationName);
+ enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
- return enumBuilder;
- }
- return null;
- }
+ return enumBuilder;
+ }
+ return null;
+ }
- /**
+ /**
* Generates type builder for <code>module</code>.
*
* @param module
* @throws IllegalArgumentException
* if <code>module</code> equals null
*/
- private def GeneratedTypeBuilder moduleTypeBuilder(Module module, String postfix) {
- checkArgument(module !== null, "Module reference cannot be NULL.");
- val packageName = moduleNamespaceToPackageName(module);
- val moduleName = parseToClassName(module.name) + postfix;
+ private def GeneratedTypeBuilder moduleTypeBuilder(Module module, String postfix) {
+ checkArgument(module !== null, "Module reference cannot be NULL.");
+ val packageName = moduleNamespaceToPackageName(module);
+ val moduleName = parseToClassName(module.name) + postfix;
- return new GeneratedTypeBuilderImpl(packageName, moduleName);
+ return new GeneratedTypeBuilderImpl(packageName, moduleName);
- }
+ }
- /**
+ /**
* Converts <code>augSchema</code> to list of <code>Type</code> which
* contains generated type for augmentation. In addition there are also
* generated types for all containers, list and choices which are child of
* <li>if target path of <code>augSchema</code> equals null</li>
* </ul>
*/
- private def List<Type> augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema) {
- checkArgument(augmentPackageName !== null, "Package Name cannot be NULL.");
- checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL.");
- checkState(augSchema.targetPath !== null,
- "Augmentation Schema does not contain Target Path (Target Path is NULL).");
- val List<Type> genTypes = new ArrayList();
-
- // EVERY augmented interface will extends Augmentation<T> interface
- // and DataObject interface!!!
- val targetPath = augSchema.targetPath;
- val targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
- if (targetSchemaNode !== null) {
- var targetType = yangToJavaMapping.get(targetSchemaNode.path);
- if (targetType == null) {
-
- // FIXME: augmentation should be added as last, all types should already be generated
- // and have assigned Java Types,
- val targetModule = findParentModule(schemaContext, targetSchemaNode);
- val targetBasePackage = moduleNamespaceToPackageName(targetModule);
- val typePackage = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath());
- val targetSchemaNodeName = targetSchemaNode.getQName().getLocalName();
- val typeName = parseToClassName(targetSchemaNodeName);
- targetType = new ReferencedTypeImpl(typePackage, typeName);
- }
- val augChildNodes = augSchema.childNodes;
- if (!(targetSchemaNode instanceof ChoiceNode)) {
- val augTypeBuilder = addRawAugmentGenTypeDefinition(augmentPackageName, targetType, augSchema);
- val augType = augTypeBuilder.toInstance();
- genTypes.add(augType);
- } else {
- val choiceTarget = targetSchemaNode as ChoiceNode;
- val choiceCaseNodes = choiceTarget.cases;
- genTypes.addAll(
- generateTypesFromAugmentedChoiceCases(augmentPackageName, targetType, choiceCaseNodes));
- }
- genTypes.addAll(augmentationBodyToGenTypes(augmentPackageName, augChildNodes));
- }
- return genTypes;
- }
-
- /**
+ private def List<Type> augmentationToGenTypes(String augmentPackageName, AugmentationSchema augSchema) {
+ checkArgument(augmentPackageName !== null, "Package Name cannot be NULL.");
+ checkArgument(augSchema !== null, "Augmentation Schema cannot be NULL.");
+ checkState(augSchema.targetPath !== null,
+ "Augmentation Schema does not contain Target Path (Target Path is NULL).");
+ val List<Type> genTypes = new ArrayList();
+
+ // EVERY augmented interface will extends Augmentation<T> interface
+ // and DataObject interface!!!
+ val targetPath = augSchema.targetPath;
+ val targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
+ if (targetSchemaNode !== null) {
+ var targetType = yangToJavaMapping.get(targetSchemaNode.path);
+ if (targetType == null) {
+
+ // FIXME: augmentation should be added as last, all types should already be generated
+ // and have assigned Java Types,
+ val targetModule = findParentModule(schemaContext, targetSchemaNode);
+ val targetBasePackage = moduleNamespaceToPackageName(targetModule);
+ val typePackage = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath());
+ val targetSchemaNodeName = targetSchemaNode.getQName().getLocalName();
+ val typeName = parseToClassName(targetSchemaNodeName);
+ targetType = new ReferencedTypeImpl(typePackage, typeName);
+ }
+ val augChildNodes = augSchema.childNodes;
+ if (!(targetSchemaNode instanceof ChoiceNode)) {
+ val augTypeBuilder = addRawAugmentGenTypeDefinition(augmentPackageName, targetType, augSchema);
+ val augType = augTypeBuilder.toInstance();
+ genTypes.add(augType);
+ } else {
+ val choiceTarget = targetSchemaNode as ChoiceNode;
+ val choiceCaseNodes = choiceTarget.cases;
+ genTypes.addAll(
+ generateTypesFromAugmentedChoiceCases(augmentPackageName, targetType, choiceCaseNodes));
+ }
+ genTypes.addAll(augmentationBodyToGenTypes(augmentPackageName, augChildNodes));
+ }
+ return genTypes;
+ }
+
+ /**
* Returns a generated type builder for an augmentation.
*
* The name of the type builder is equal to the name of augmented node with
* and uses of augment
* @return generated type builder for augment
*/
- private def GeneratedTypeBuilder addRawAugmentGenTypeDefinition(String augmentPackageName, Type targetTypeRef,
- AugmentationSchema augSchema) {
- var Map<String, GeneratedTypeBuilder> augmentBuilders = genTypeBuilders.get(augmentPackageName);
- if (augmentBuilders === null) {
- augmentBuilders = new HashMap();
- genTypeBuilders.put(augmentPackageName, augmentBuilders);
- }
- val augIdentifier = getAugmentIdentifier(augSchema.unknownSchemaNodes);
-
- val augTypeName = if (augIdentifier !== null) {
- parseToClassName(augIdentifier)
- } else {
- augGenTypeName(augmentBuilders, targetTypeRef.name);
- }
- val Set<DataSchemaNode> augChildNodes = augSchema.childNodes;
-
- val augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augTypeName);
-
- augTypeBuilder.addImplementsType(DATA_OBJECT);
- augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef));
- addImplementedInterfaceFromUses(augSchema, augTypeBuilder);
-
- augSchemaNodeToMethods(augmentPackageName, augTypeBuilder, augChildNodes);
- augmentBuilders.put(augTypeName, augTypeBuilder);
- return augTypeBuilder;
- }
-
- /**
+ private def GeneratedTypeBuilder addRawAugmentGenTypeDefinition(String augmentPackageName, Type targetTypeRef,
+ AugmentationSchema augSchema) {
+ var Map<String, GeneratedTypeBuilder> augmentBuilders = genTypeBuilders.get(augmentPackageName);
+ if (augmentBuilders === null) {
+ augmentBuilders = new HashMap();
+ genTypeBuilders.put(augmentPackageName, augmentBuilders);
+ }
+ val augIdentifier = getAugmentIdentifier(augSchema.unknownSchemaNodes);
+
+ val augTypeName = if (augIdentifier !== null) {
+ parseToClassName(augIdentifier)
+ } else {
+ augGenTypeName(augmentBuilders, targetTypeRef.name);
+ }
+ val Set<DataSchemaNode> augChildNodes = augSchema.childNodes;
+
+ val augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augTypeName);
+
+ augTypeBuilder.addImplementsType(DATA_OBJECT);
+ augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef));
+ addImplementedInterfaceFromUses(augSchema, augTypeBuilder);
+
+ augSchemaNodeToMethods(augmentPackageName, augTypeBuilder, augChildNodes);
+ augmentBuilders.put(augTypeName, augTypeBuilder);
+ return augTypeBuilder;
+ }
+
+ /**
*
* @param unknownSchemaNodes
* @return
*/
- private def String getAugmentIdentifier(List<UnknownSchemaNode> unknownSchemaNodes) {
- for (unknownSchemaNode : unknownSchemaNodes) {
- val nodeType = unknownSchemaNode.nodeType;
- if (AUGMENT_IDENTIFIER_NAME.equals(nodeType.localName) &&
- YANG_EXT_NAMESPACE.equals(nodeType.namespace.toString())) {
- return unknownSchemaNode.nodeParameter;
- }
- }
- return null;
- }
-
- /**
+ private def String getAugmentIdentifier(List<UnknownSchemaNode> unknownSchemaNodes) {
+ for (unknownSchemaNode : unknownSchemaNodes) {
+ val nodeType = unknownSchemaNode.nodeType;
+ if (AUGMENT_IDENTIFIER_NAME.equals(nodeType.localName) &&
+ YANG_EXT_NAMESPACE.equals(nodeType.namespace.toString())) {
+ return unknownSchemaNode.nodeParameter;
+ }
+ }
+ return null;
+ }
+
+ /**
* Convert a container, list and choice subnodes (and recursivelly their
* subnodes) of augment to generated types
*
* @return list of <code>Type</code> which represents container, list and
* choice subnodes of augment
*/
- private def List<Type> augmentationBodyToGenTypes(String augBasePackageName, Set<DataSchemaNode> augChildNodes) {
- val List<Type> genTypes = new ArrayList();
- val List<DataNodeIterator> augSchemaIts = new ArrayList();
- for (childNode : augChildNodes) {
- if (childNode instanceof DataNodeContainer) {
- augSchemaIts.add(new DataNodeIterator(childNode as DataNodeContainer));
-
- if (childNode instanceof ContainerSchemaNode) {
- genTypes.add(containerToGenType(augBasePackageName, childNode as ContainerSchemaNode));
- } else if (childNode instanceof ListSchemaNode) {
- genTypes.addAll(listToGenType(augBasePackageName, childNode as ListSchemaNode));
- }
- } else if (childNode instanceof ChoiceNode) {
- val choice = childNode as ChoiceNode;
- for (caseNode : choice.cases) {
- augSchemaIts.add(new DataNodeIterator(caseNode));
- }
- genTypes.addAll(choiceToGeneratedType(augBasePackageName, childNode as ChoiceNode));
- }
- }
-
- for (it : augSchemaIts) {
- val List<ContainerSchemaNode> augContainers = it.allContainers();
- val List<ListSchemaNode> augLists = it.allLists();
- val List<ChoiceNode> augChoices = it.allChoices();
-
- if (augContainers !== null) {
- for (container : augContainers) {
- genTypes.add(containerToGenType(augBasePackageName, container));
- }
- }
- if (augLists !== null) {
- for (list : augLists) {
- genTypes.addAll(listToGenType(augBasePackageName, list));
- }
- }
- if (augChoices !== null) {
- for (choice : augChoices) {
- genTypes.addAll(choiceToGeneratedType(augBasePackageName, choice));
- }
- }
- }
- return genTypes;
- }
-
- /**
+ private def List<Type> augmentationBodyToGenTypes(String augBasePackageName, Set<DataSchemaNode> augChildNodes) {
+ val List<Type> genTypes = new ArrayList();
+ val List<DataNodeIterator> augSchemaIts = new ArrayList();
+ for (childNode : augChildNodes) {
+ if (childNode instanceof DataNodeContainer) {
+ augSchemaIts.add(new DataNodeIterator(childNode as DataNodeContainer));
+
+ if (childNode instanceof ContainerSchemaNode) {
+ genTypes.add(containerToGenType(augBasePackageName, childNode as ContainerSchemaNode));
+ } else if (childNode instanceof ListSchemaNode) {
+ genTypes.addAll(listToGenType(augBasePackageName, childNode as ListSchemaNode));
+ }
+ } else if (childNode instanceof ChoiceNode) {
+ val choice = childNode as ChoiceNode;
+ for (caseNode : choice.cases) {
+ augSchemaIts.add(new DataNodeIterator(caseNode));
+ }
+ genTypes.addAll(choiceToGeneratedType(augBasePackageName, childNode as ChoiceNode));
+ }
+ }
+
+ for (it : augSchemaIts) {
+ val List<ContainerSchemaNode> augContainers = it.allContainers();
+ val List<ListSchemaNode> augLists = it.allLists();
+ val List<ChoiceNode> augChoices = it.allChoices();
+
+ if (augContainers !== null) {
+ for (container : augContainers) {
+ genTypes.add(containerToGenType(augBasePackageName, container));
+ }
+ }
+ if (augLists !== null) {
+ for (list : augLists) {
+ genTypes.addAll(listToGenType(augBasePackageName, list));
+ }
+ }
+ if (augChoices !== null) {
+ for (choice : augChoices) {
+ genTypes.addAll(choiceToGeneratedType(augBasePackageName, choice));
+ }
+ }
+ }
+ return genTypes;
+ }
+
+ /**
* Returns first unique name for the augment generated type builder. The
* generated type builder name for augment consists from name of augmented
* node and serial number of its augmentation.
* string with name of augmented node
* @return string with unique name for augmentation builder
*/
- private def String augGenTypeName(Map<String, GeneratedTypeBuilder> builders, String genTypeName) {
- var index = 1;
- while ((builders !== null) && builders.containsKey(genTypeName + index)) {
- index = index + 1;
- }
- return genTypeName + index;
- }
-
- /**
+ private def String augGenTypeName(Map<String, GeneratedTypeBuilder> builders, String genTypeName) {
+ var index = 1;
+ while ((builders !== null) && builders.containsKey(genTypeName + index)) {
+ index = index + 1;
+ }
+ return genTypeName + index;
+ }
+
+ /**
* Converts <code>containerNode</code> to generated type. Firstly the
* generated type builder is created. The subnodes of
* <code>containerNode</code> are added as methods and the instance of
* schema paths
* @return generated type for <code>containerNode</code>
*/
- private def GeneratedType containerToGenType(String basePackageName, ContainerSchemaNode containerNode) {
- if (containerNode === null) {
- return null;
- }
+ private def GeneratedType containerToGenType(String basePackageName, ContainerSchemaNode containerNode) {
+ if (containerNode === null) {
+ return null;
+ }
- val packageName = packageNameForGeneratedType(basePackageName, containerNode.path);
- val schemaNodes = containerNode.childNodes;
- val typeBuilder = addDefaultInterfaceDefinition(packageName, containerNode);
+ val packageName = packageNameForGeneratedType(basePackageName, containerNode.path);
+ val schemaNodes = containerNode.childNodes;
+ val typeBuilder = addDefaultInterfaceDefinition(packageName, containerNode);
- resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes);
- return typeBuilder.toInstance();
- }
+ resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes);
+ return typeBuilder.toInstance();
+ }
- /**
+ /**
* Adds the methods to <code>typeBuilder</code> which represent subnodes of
* node for which <code>typeBuilder</code> was created.
*
* parameter. The getter methods (representing child nodes) could be
* added to it.
*/
- private def GeneratedTypeBuilder resolveDataSchemaNodes(String basePackageName, GeneratedTypeBuilder typeBuilder,
- Set<DataSchemaNode> schemaNodes) {
- if ((schemaNodes !== null) && (typeBuilder !== null)) {
- for (schemaNode : schemaNodes) {
- if (!schemaNode.isAugmenting() && !schemaNode.isAddedByUses()) {
- addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder);
- }
-
- }
- }
- return typeBuilder;
- }
-
- /**
+ private def GeneratedTypeBuilder resolveDataSchemaNodes(String basePackageName, GeneratedTypeBuilder typeBuilder,
+ Set<DataSchemaNode> schemaNodes) {
+ if ((schemaNodes !== null) && (typeBuilder !== null)) {
+ for (schemaNode : schemaNodes) {
+ if (!schemaNode.isAugmenting() && !schemaNode.isAddedByUses()) {
+ addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder);
+ }
+
+ }
+ }
+ return typeBuilder;
+ }
+
+ /**
* Adds the methods to <code>typeBuilder</code> what represents subnodes of
* node for which <code>typeBuilder</code> was created.
*
* parameter <code>typeBuilder</code>. The getter method could be
* added to it.
*/
- private def GeneratedTypeBuilder augSchemaNodeToMethods(String basePackageName, GeneratedTypeBuilder typeBuilder,
- Set<DataSchemaNode> schemaNodes) {
- if ((schemaNodes !== null) && (typeBuilder !== null)) {
- for (schemaNode : schemaNodes) {
- if (schemaNode.isAugmenting()) {
- addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder);
- }
- }
- }
- return typeBuilder;
- }
-
- /**
+ private def GeneratedTypeBuilder augSchemaNodeToMethods(String basePackageName, GeneratedTypeBuilder typeBuilder,
+ Set<DataSchemaNode> schemaNodes) {
+ if ((schemaNodes !== null) && (typeBuilder !== null)) {
+ for (schemaNode : schemaNodes) {
+ if (schemaNode.isAugmenting()) {
+ addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder);
+ }
+ }
+ }
+ return typeBuilder;
+ }
+
+ /**
* Adds to <code>typeBuilder</code> a method which is derived from
* <code>schemaNode</code>.
*
* generated type builder to which is <code>schemaNode</code>
* added as a method.
*/
- private def void addSchemaNodeToBuilderAsMethod(String basePackageName, DataSchemaNode node,
- GeneratedTypeBuilder typeBuilder) {
- if (node !== null && typeBuilder !== null) {
- switch (node) {
- case node instanceof LeafSchemaNode:
- resolveLeafSchemaNodeAsMethod(typeBuilder, node as LeafSchemaNode)
- case node instanceof LeafListSchemaNode:
- resolveLeafListSchemaNode(typeBuilder, node as LeafListSchemaNode)
- case node instanceof ContainerSchemaNode:
- resolveContainerSchemaNode(basePackageName, typeBuilder, node as ContainerSchemaNode)
- case node instanceof ListSchemaNode:
- resolveListSchemaNode(basePackageName, typeBuilder, node as ListSchemaNode)
- case node instanceof ChoiceNode:
- resolveChoiceSchemaNode(basePackageName, typeBuilder, node as ChoiceNode)
- }
- }
- }
-
- /**
+ private def void addSchemaNodeToBuilderAsMethod(String basePackageName, DataSchemaNode node,
+ GeneratedTypeBuilder typeBuilder) {
+ if (node !== null && typeBuilder !== null) {
+ switch (node) {
+ case node instanceof LeafSchemaNode:
+ resolveLeafSchemaNodeAsMethod(typeBuilder, node as LeafSchemaNode)
+ case node instanceof LeafListSchemaNode:
+ resolveLeafListSchemaNode(typeBuilder, node as LeafListSchemaNode)
+ case node instanceof ContainerSchemaNode:
+ resolveContainerSchemaNode(basePackageName, typeBuilder, node as ContainerSchemaNode)
+ case node instanceof ListSchemaNode:
+ resolveListSchemaNode(basePackageName, typeBuilder, node as ListSchemaNode)
+ case node instanceof ChoiceNode:
+ resolveChoiceSchemaNode(basePackageName, typeBuilder, node as ChoiceNode)
+ }
+ }
+ }
+
+ /**
* Creates a getter method for a choice node.
*
* Firstly generated type builder for choice is created or found in
* </ul>
*
*/
- private def void resolveChoiceSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder,
- ChoiceNode choiceNode) {
- checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
- checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
- checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL.");
-
- val choiceName = choiceNode.QName.localName;
- if (choiceName !== null && !choiceNode.isAddedByUses()) {
- val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path);
- val choiceType = addDefaultInterfaceDefinition(packageName, choiceNode);
- constructGetter(typeBuilder, choiceName, choiceNode.description, choiceType);
- }
- }
-
- /**
+ private def void resolveChoiceSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder,
+ ChoiceNode choiceNode) {
+ checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
+ checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
+ checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL.");
+
+ val choiceName = choiceNode.QName.localName;
+ if (choiceName !== null && !choiceNode.isAddedByUses()) {
+ val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path);
+ val choiceType = addDefaultInterfaceDefinition(packageName, choiceNode);
+ constructGetter(typeBuilder, choiceName, choiceNode.description, choiceType);
+ }
+ }
+
+ /**
* Converts <code>choiceNode</code> to the list of generated types for
* choice and its cases.
*
* </ul>
*
*/
- private def List<GeneratedType> choiceToGeneratedType(String basePackageName, ChoiceNode choiceNode) {
- checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
- checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL.");
-
- val List<GeneratedType> generatedTypes = new ArrayList();
- val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path);
- val choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode);
-
- //choiceTypeBuilder.addImplementsType(DATA_OBJECT);
- val choiceType = choiceTypeBuilder.toInstance();
-
- generatedTypes.add(choiceType);
- val Set<ChoiceCaseNode> caseNodes = choiceNode.cases;
- if ((caseNodes !== null) && !caseNodes.isEmpty()) {
- generatedTypes.addAll(generateTypesFromChoiceCases(basePackageName, choiceType, caseNodes));
- }
- return generatedTypes;
- }
-
- /**
+ private def List<GeneratedType> choiceToGeneratedType(String basePackageName, ChoiceNode choiceNode) {
+ checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
+ checkArgument(choiceNode !== null, "Choice Schema Node cannot be NULL.");
+
+ val List<GeneratedType> generatedTypes = new ArrayList();
+ val packageName = packageNameForGeneratedType(basePackageName, choiceNode.path);
+ val choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode);
+
+ //choiceTypeBuilder.addImplementsType(DATA_OBJECT);
+ val choiceType = choiceTypeBuilder.toInstance();
+
+ generatedTypes.add(choiceType);
+ val Set<ChoiceCaseNode> caseNodes = choiceNode.cases;
+ if ((caseNodes !== null) && !caseNodes.isEmpty()) {
+ generatedTypes.addAll(generateTypesFromChoiceCases(basePackageName, choiceType, caseNodes));
+ }
+ return generatedTypes;
+ }
+
+ /**
* Converts <code>caseNodes</code> set to list of corresponding generated
* types.
*
* </ul>
* *
*/
- private def List<GeneratedType> generateTypesFromChoiceCases(String basePackageName, Type refChoiceType,
- Set<ChoiceCaseNode> caseNodes) {
- checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
- checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL.");
- checkArgument(caseNodes !== null, "Set of Choice Case Nodes cannot be NULL.");
-
- val List<GeneratedType> generatedTypes = new ArrayList();
- for (caseNode : caseNodes) {
- if (caseNode !== null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) {
- val packageName = packageNameForGeneratedType(basePackageName, caseNode.path);
- val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
- caseTypeBuilder.addImplementsType(refChoiceType);
-
- val Set<DataSchemaNode> childNodes = caseNode.childNodes;
- if (childNodes !== null) {
- resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes);
- }
- generatedTypes.add(caseTypeBuilder.toInstance());
- }
- }
-
- return generatedTypes;
- }
-
- /**
+ private def List<GeneratedType> generateTypesFromChoiceCases(String basePackageName, Type refChoiceType,
+ Set<ChoiceCaseNode> caseNodes) {
+ checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
+ checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL.");
+ checkArgument(caseNodes !== null, "Set of Choice Case Nodes cannot be NULL.");
+
+ val List<GeneratedType> generatedTypes = new ArrayList();
+ for (caseNode : caseNodes) {
+ if (caseNode !== null && !caseNode.isAddedByUses() && !caseNode.isAugmenting()) {
+ val packageName = packageNameForGeneratedType(basePackageName, caseNode.path);
+ val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
+ caseTypeBuilder.addImplementsType(refChoiceType);
+
+ val Set<DataSchemaNode> childNodes = caseNode.childNodes;
+ if (childNodes !== null) {
+ resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes);
+ }
+ generatedTypes.add(caseTypeBuilder.toInstance());
+ }
+ }
+
+ return generatedTypes;
+ }
+
+ /**
* Generates list of generated types for all the cases of a choice which are
* added to the choice through the augment.
*
* <li>if <code>caseNodes</code> equals null</li>
* </ul>
*/
- private def List<GeneratedType> generateTypesFromAugmentedChoiceCases(String basePackageName, Type refChoiceType,
- Set<ChoiceCaseNode> caseNodes) {
- checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
- checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL.");
- checkArgument(caseNodes !== null, "Set of Choice Case Nodes cannot be NULL.");
-
- val List<GeneratedType> generatedTypes = new ArrayList();
- for (caseNode : caseNodes) {
- if (caseNode !== null && caseNode.isAugmenting()) {
- val packageName = packageNameForGeneratedType(basePackageName, caseNode.path);
- val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
- caseTypeBuilder.addImplementsType(refChoiceType);
-
- val Set<DataSchemaNode> childNodes = caseNode.childNodes;
- if (childNodes !== null) {
- resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes);
- }
- generatedTypes.add(caseTypeBuilder.toInstance());
- }
- }
-
- return generatedTypes;
- }
-
- /**
+ private def List<GeneratedType> generateTypesFromAugmentedChoiceCases(String basePackageName, Type refChoiceType,
+ Set<ChoiceCaseNode> caseNodes) {
+ checkArgument(basePackageName !== null, "Base Package Name cannot be NULL.");
+ checkArgument(refChoiceType !== null, "Referenced Choice Type cannot be NULL.");
+ checkArgument(caseNodes !== null, "Set of Choice Case Nodes cannot be NULL.");
+
+ val List<GeneratedType> generatedTypes = new ArrayList();
+ for (caseNode : caseNodes) {
+ if (caseNode !== null && caseNode.isAugmenting()) {
+ val packageName = packageNameForGeneratedType(basePackageName, caseNode.path);
+ val caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
+ caseTypeBuilder.addImplementsType(refChoiceType);
+
+ val Set<DataSchemaNode> childNodes = caseNode.childNodes;
+ if (childNodes !== null) {
+ resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes);
+ }
+ generatedTypes.add(caseTypeBuilder.toInstance());
+ }
+ }
+
+ return generatedTypes;
+ }
+
+ /**
* Converts <code>leaf</code> to the getter method which is added to
* <code>typeBuilder</code>.
*
* <li>true - in other cases</li>
* </ul>
*/
- private def boolean resolveLeafSchemaNodeAsMethod(GeneratedTypeBuilder typeBuilder, LeafSchemaNode leaf) {
- if ((leaf !== null) && (typeBuilder !== null)) {
- val leafName = leaf.QName.localName;
- var String leafDesc = leaf.description;
- if (leafDesc === null) {
- leafDesc = "";
- }
-
- val parentModule = findParentModule(schemaContext, leaf);
- if (leafName !== null && !leaf.isAddedByUses()) {
- val TypeDefinition<?> typeDef = leaf.type;
-
- var Type returnType = null;
- if (typeDef instanceof EnumTypeDefinition) {
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
- val enumTypeDef = enumTypeDefFromExtendedType(typeDef);
- val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leafName, typeBuilder);
-
- if (enumBuilder !== null) {
- returnType = new ReferencedTypeImpl(enumBuilder.packageName, enumBuilder.name);
- }
- (typeProvider as TypeProviderImpl).putReferencedType(leaf.path, returnType);
- } else if (typeDef instanceof UnionType) {
- val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule);
- if (genTOBuilder !== null) {
- returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
- }
- } else if (typeDef instanceof BitsTypeDefinition) {
- val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule);
- if (genTOBuilder !== null) {
- returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
- }
- } else {
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
- }
- if (returnType !== null) {
- constructGetter(typeBuilder, leafName, leafDesc, returnType);
- return true;
- }
- }
- }
- return false;
- }
-
- /**
+ private def boolean resolveLeafSchemaNodeAsMethod(GeneratedTypeBuilder typeBuilder, LeafSchemaNode leaf) {
+ if ((leaf !== null) && (typeBuilder !== null)) {
+ val leafName = leaf.QName.localName;
+ var String leafDesc = leaf.description;
+ if (leafDesc === null) {
+ leafDesc = "";
+ }
+
+ val parentModule = findParentModule(schemaContext, leaf);
+ if (leafName !== null && !leaf.isAddedByUses()) {
+ val TypeDefinition<?> typeDef = leaf.type;
+
+ var Type returnType = null;
+ if (typeDef instanceof EnumTypeDefinition) {
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
+ val enumTypeDef = enumTypeDefFromExtendedType(typeDef);
+ val enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leafName, typeBuilder);
+
+ if (enumBuilder !== null) {
+ returnType = new ReferencedTypeImpl(enumBuilder.packageName, enumBuilder.name);
+ }
+ (typeProvider as TypeProviderImpl).putReferencedType(leaf.path, returnType);
+ } else if (typeDef instanceof UnionType) {
+ val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule);
+ if (genTOBuilder !== null) {
+ returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
+ }
+ } else if (typeDef instanceof BitsTypeDefinition) {
+ val genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule);
+ if (genTOBuilder !== null) {
+ returnType = new ReferencedTypeImpl(genTOBuilder.packageName, genTOBuilder.name);
+ }
+ } else {
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
+ }
+ if (returnType !== null) {
+ constructGetter(typeBuilder, leafName, leafDesc, returnType);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
* Converts <code>leaf</code> schema node to property of generated TO
* builder.
*
* <li>true - other cases</li>
* </ul>
*/
- private def boolean resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf,
- boolean isReadOnly) {
- if ((leaf !== null) && (toBuilder !== null)) {
- val leafName = leaf.QName.localName;
- var String leafDesc = leaf.description;
- if (leafDesc === null) {
- leafDesc = "";
- }
-
- if (leafName !== null && !leaf.isAddedByUses()) {
- val TypeDefinition<?> typeDef = leaf.type;
-
- // TODO: properly resolve enum types
- val returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
-
- if (returnType !== null) {
- val propBuilder = toBuilder.addProperty(parseToClassName(leafName));
-
- propBuilder.setReadOnly(isReadOnly);
- propBuilder.setReturnType(returnType);
- propBuilder.setComment(leafDesc);
-
- toBuilder.addEqualsIdentity(propBuilder);
- toBuilder.addHashIdentity(propBuilder);
- toBuilder.addToStringProperty(propBuilder);
-
- return true;
- }
- }
- }
- return false;
- }
-
- /**
+ private def boolean resolveLeafSchemaNodeAsProperty(GeneratedTOBuilder toBuilder, LeafSchemaNode leaf,
+ boolean isReadOnly) {
+ if ((leaf !== null) && (toBuilder !== null)) {
+ val leafName = leaf.QName.localName;
+ var String leafDesc = leaf.description;
+ if (leafDesc === null) {
+ leafDesc = "";
+ }
+
+ if (leafName !== null && !leaf.isAddedByUses()) {
+ val TypeDefinition<?> typeDef = leaf.type;
+
+ // TODO: properly resolve enum types
+ val returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
+
+ if (returnType !== null) {
+ val propBuilder = toBuilder.addProperty(parseToClassName(leafName));
+
+ propBuilder.setReadOnly(isReadOnly);
+ propBuilder.setReturnType(returnType);
+ propBuilder.setComment(leafDesc);
+
+ toBuilder.addEqualsIdentity(propBuilder);
+ toBuilder.addHashIdentity(propBuilder);
+ toBuilder.addToStringProperty(propBuilder);
+
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
* Converts <code>node</code> leaf list schema node to getter method of
* <code>typeBuilder</code>.
*
* <li>false - other cases</li>
* </ul>
*/
- private def boolean resolveLeafListSchemaNode(GeneratedTypeBuilder typeBuilder, LeafListSchemaNode node) {
- if ((node !== null) && (typeBuilder !== null)) {
- val nodeName = node.QName.localName;
- var String nodeDesc = node.description;
- if (nodeDesc === null) {
- nodeDesc = "";
- }
-
- if (nodeName !== null && !node.isAddedByUses()) {
- val TypeDefinition<?> type = node.type;
- val listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type, node));
-
- constructGetter(typeBuilder, nodeName, nodeDesc, listType);
- return true;
- }
- }
- return false;
- }
-
- /**
+ private def boolean resolveLeafListSchemaNode(GeneratedTypeBuilder typeBuilder, LeafListSchemaNode node) {
+ if ((node !== null) && (typeBuilder !== null)) {
+ val nodeName = node.QName.localName;
+ var String nodeDesc = node.description;
+ if (nodeDesc === null) {
+ nodeDesc = "";
+ }
+
+ if (nodeName !== null && !node.isAddedByUses()) {
+ val TypeDefinition<?> type = node.type;
+ val listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type, node));
+
+ constructGetter(typeBuilder, nodeName, nodeDesc, listType);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Creates a getter method for a container node.
*
* Firstly generated type builder for container is created or found in
* <li>true - other cases</li>
* </ul>
*/
- private def boolean resolveContainerSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder,
- ContainerSchemaNode containerNode) {
- if ((containerNode !== null) && (typeBuilder !== null)) {
- val nodeName = containerNode.QName.localName;
+ private def boolean resolveContainerSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder,
+ ContainerSchemaNode containerNode) {
+ if ((containerNode !== null) && (typeBuilder !== null)) {
+ val nodeName = containerNode.QName.localName;
- if (nodeName !== null && !containerNode.isAddedByUses()) {
- val packageName = packageNameForGeneratedType(basePackageName, containerNode.path);
+ if (nodeName !== null && !containerNode.isAddedByUses()) {
+ val packageName = packageNameForGeneratedType(basePackageName, containerNode.path);
- val rawGenType = addDefaultInterfaceDefinition(packageName, containerNode);
- constructGetter(typeBuilder, nodeName, containerNode.description, rawGenType);
+ val rawGenType = addDefaultInterfaceDefinition(packageName, containerNode);
+ constructGetter(typeBuilder, nodeName, containerNode.description, rawGenType);
- return true;
- }
- }
- return false;
- }
+ return true;
+ }
+ }
+ return false;
+ }
- /**
+ /**
* Creates a getter method for a list node.
*
* Firstly generated type builder for list is created or found in
* <li>true - other cases</li>
* </ul>
*/
- private def boolean resolveListSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder,
- ListSchemaNode listNode) {
- if ((listNode !== null) && (typeBuilder !== null)) {
- val listName = listNode.QName.localName;
-
- if (listName !== null && !listNode.isAddedByUses()) {
- val packageName = packageNameForGeneratedType(basePackageName, listNode.path);
- val rawGenType = addDefaultInterfaceDefinition(packageName, listNode);
- constructGetter(typeBuilder, listName, listNode.description, Types.listTypeFor(rawGenType));
- return true;
- }
- }
- return false;
- }
-
- /**
+ private def boolean resolveListSchemaNode(String basePackageName, GeneratedTypeBuilder typeBuilder,
+ ListSchemaNode listNode) {
+ if ((listNode !== null) && (typeBuilder !== null)) {
+ val listName = listNode.QName.localName;
+
+ if (listName !== null && !listNode.isAddedByUses()) {
+ val packageName = packageNameForGeneratedType(basePackageName, listNode.path);
+ val rawGenType = addDefaultInterfaceDefinition(packageName, listNode);
+ constructGetter(typeBuilder, listName, listNode.description, Types.listTypeFor(rawGenType));
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Instantiates generated type builder with <code>packageName</code> and
* <code>schemaNode</code>.
*
* schema node for which is created generated type builder
* @return generated type builder <code>schemaNode</code>
*/
- private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode) {
- val builder = addRawInterfaceDefinition(packageName, schemaNode, "");
- builder.addImplementsType(DATA_OBJECT);
- if (!(schemaNode instanceof GroupingDefinition)) {
- builder.addImplementsType(augmentable(builder));
- }
+ private def GeneratedTypeBuilder addDefaultInterfaceDefinition(String packageName, SchemaNode schemaNode) {
+ val builder = addRawInterfaceDefinition(packageName, schemaNode, "");
+ builder.addImplementsType(DATA_OBJECT);
+ if (!(schemaNode instanceof GroupingDefinition)) {
+ builder.addImplementsType(augmentable(builder));
+ }
- if (schemaNode instanceof DataNodeContainer) {
- addImplementedInterfaceFromUses(schemaNode as DataNodeContainer, builder);
- }
+ if (schemaNode instanceof DataNodeContainer) {
+ addImplementedInterfaceFromUses(schemaNode as DataNodeContainer, builder);
+ }
- return builder;
- }
+ return builder;
+ }
- /**
+ /**
* Wraps the calling of the same overloaded method.
*
* @param packageName
* schema node which provide data about the schema node name
* @return generated type builder for <code>schemaNode</code>
*/
- private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode) {
- return addRawInterfaceDefinition(packageName, schemaNode, "");
- }
+ private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode) {
+ return addRawInterfaceDefinition(packageName, schemaNode, "");
+ }
- /**
+ /**
* Returns reference to generated type builder for specified
* <code>schemaNode</code> with <code>packageName</code>.
*
* </ul>
*
*/
- private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode,
- String prefix) {
- checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL.");
- checkArgument(packageName !== null, "Package Name for Generated Type cannot be NULL.");
- checkArgument(schemaNode.QName !== null, "QName for Data Schema Node cannot be NULL.");
- val schemaNodeName = schemaNode.QName.localName;
- checkArgument(schemaNodeName !== null, "Local Name of QName for Data Schema Node cannot be NULL.");
-
- var String genTypeName;
- if (prefix === null) {
- genTypeName = parseToClassName(schemaNodeName);
- } else {
- genTypeName = prefix + parseToClassName(schemaNodeName);
- }
-
- //FIXME: Validation of name conflict
- val newType = new GeneratedTypeBuilderImpl(packageName, genTypeName);
- yangToJavaMapping.put(schemaNode.path, newType);
- if (!genTypeBuilders.containsKey(packageName)) {
- val Map<String, GeneratedTypeBuilder> builders = new HashMap();
- builders.put(genTypeName, newType);
- genTypeBuilders.put(packageName, builders);
- } else {
- val Map<String, GeneratedTypeBuilder> builders = genTypeBuilders.get(packageName);
- if (!builders.containsKey(genTypeName)) {
- builders.put(genTypeName, newType);
- }
- }
- return newType;
- }
-
- /**
+ private def GeneratedTypeBuilder addRawInterfaceDefinition(String packageName, SchemaNode schemaNode,
+ String prefix) {
+ checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL.");
+ checkArgument(packageName !== null, "Package Name for Generated Type cannot be NULL.");
+ checkArgument(schemaNode.QName !== null, "QName for Data Schema Node cannot be NULL.");
+ val schemaNodeName = schemaNode.QName.localName;
+ checkArgument(schemaNodeName !== null, "Local Name of QName for Data Schema Node cannot be NULL.");
+
+ var String genTypeName;
+ if (prefix === null) {
+ genTypeName = parseToClassName(schemaNodeName);
+ } else {
+ genTypeName = prefix + parseToClassName(schemaNodeName);
+ }
+
+ //FIXME: Validation of name conflict
+ val newType = new GeneratedTypeBuilderImpl(packageName, genTypeName);
+ yangToJavaMapping.put(schemaNode.path, newType);
+ if (!genTypeBuilders.containsKey(packageName)) {
+ val Map<String, GeneratedTypeBuilder> builders = new HashMap();
+ builders.put(genTypeName, newType);
+ genTypeBuilders.put(packageName, builders);
+ } else {
+ val Map<String, GeneratedTypeBuilder> builders = genTypeBuilders.get(packageName);
+ if (!builders.containsKey(genTypeName)) {
+ builders.put(genTypeName, newType);
+ }
+ }
+ return newType;
+ }
+
+ /**
* Creates the name of the getter method from <code>methodName</code>.
*
* @param methodName
* @return string with the name of the getter method for
* <code>methodName</code> in JAVA method format
*/
- private def String getterMethodName(String methodName, Type returnType) {
- val method = new StringBuilder();
- if (BOOLEAN.equals(returnType)) {
- method.append("is");
- } else {
- method.append("get");
- }
- method.append(parseToClassName(methodName));
- return method.toString();
- }
-
- /**
+ private def String getterMethodName(String methodName, Type returnType) {
+ val method = new StringBuilder();
+ if (BOOLEAN.equals(returnType)) {
+ method.append("is");
+ } else {
+ method.append("get");
+ }
+ method.append(parseToClassName(methodName));
+ return method.toString();
+ }
+
+ /**
* Created a method signature builder as part of
* <code>interfaceBuilder</code>.
*
* @return method signature builder which represents the getter method of
* <code>interfaceBuilder</code>
*/
- private def MethodSignatureBuilder constructGetter(GeneratedTypeBuilder interfaceBuilder, String schemaNodeName,
- String comment, Type returnType) {
+ private def MethodSignatureBuilder constructGetter(GeneratedTypeBuilder interfaceBuilder, String schemaNodeName,
+ String comment, Type returnType) {
- val getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName, returnType));
+ val getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName, returnType));
- getMethod.setComment(comment);
- getMethod.setReturnType(returnType);
+ getMethod.setComment(comment);
+ getMethod.setReturnType(returnType);
- return getMethod;
- }
+ return getMethod;
+ }
- private def listToGenType(String basePackageName, ListSchemaNode list) {
- checkArgument(basePackageName !== null, "Package Name for Generated Type cannot be NULL.");
- checkArgument(list !== null, "List Schema Node cannot be NULL.");
+ private def listToGenType(String basePackageName, ListSchemaNode list) {
+ checkArgument(basePackageName !== null, "Package Name for Generated Type cannot be NULL.");
+ checkArgument(list !== null, "List Schema Node cannot be NULL.");
- val packageName = packageNameForGeneratedType(basePackageName, list.path);
+ val packageName = packageNameForGeneratedType(basePackageName, list.path);
- // val typeBuilder =
- // resolveListTypeBuilder(packageName, list);
- val typeBuilder = addDefaultInterfaceDefinition(packageName, list);
+ // val typeBuilder =
+ // resolveListTypeBuilder(packageName, list);
+ val typeBuilder = addDefaultInterfaceDefinition(packageName, list);
- val List<String> listKeys = listKeys(list);
- val genTOBuilder = resolveListKeyTOBuilder(packageName, list);
+ val List<String> listKeys = listKeys(list);
+ val genTOBuilder = resolveListKeyTOBuilder(packageName, list);
- if (genTOBuilder !== null) {
- val identifierMarker = IDENTIFIER.parameterizedTypeFor(typeBuilder);
- val identifiableMarker = IDENTIFIABLE.parameterizedTypeFor(genTOBuilder);
- genTOBuilder.addImplementsType(identifierMarker);
- typeBuilder.addImplementsType(identifiableMarker);
- }
- val schemaNodes = list.childNodes;
+ if (genTOBuilder !== null) {
+ val identifierMarker = IDENTIFIER.parameterizedTypeFor(typeBuilder);
+ val identifiableMarker = IDENTIFIABLE.parameterizedTypeFor(genTOBuilder);
+ genTOBuilder.addImplementsType(identifierMarker);
+ typeBuilder.addImplementsType(identifiableMarker);
+ }
+ val schemaNodes = list.childNodes;
- for (schemaNode : schemaNodes) {
- if (!schemaNode.isAugmenting()) {
- addSchemaNodeToListBuilders(basePackageName, schemaNode, typeBuilder, genTOBuilder, listKeys);
- }
- }
- return typeBuildersToGenTypes(typeBuilder, genTOBuilder);
- }
+ for (schemaNode : schemaNodes) {
+ if (!schemaNode.isAugmenting()) {
+ addSchemaNodeToListBuilders(basePackageName, schemaNode, typeBuilder, genTOBuilder, listKeys);
+ }
+ }
+ return typeBuildersToGenTypes(typeBuilder, genTOBuilder);
+ }
- /**
+ /**
* Adds <code>schemaNode</code> to <code>typeBuilder</code> as getter method
* or to <code>genTOBuilder</code> as property.
*
* <li>if <code>typeBuilder</code> equals null</li>
* </ul>
*/
- private def void addSchemaNodeToListBuilders(String basePackageName, DataSchemaNode schemaNode,
- GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder, List<String> listKeys) {
- checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL.");
-
- checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
-
- if (schemaNode instanceof LeafSchemaNode) {
- val leaf = schemaNode as LeafSchemaNode;
- val leafName = leaf.QName.localName;
- if (!listKeys.contains(leafName)) {
- resolveLeafSchemaNodeAsMethod(typeBuilder, leaf);
- } else {
- resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true);
- }
- } else if (schemaNode instanceof LeafListSchemaNode) {
- resolveLeafListSchemaNode(typeBuilder, schemaNode as LeafListSchemaNode);
- } else if (schemaNode instanceof ContainerSchemaNode) {
- resolveContainerSchemaNode(basePackageName, typeBuilder, schemaNode as ContainerSchemaNode);
- } else if (schemaNode instanceof ListSchemaNode) {
- resolveListSchemaNode(basePackageName, typeBuilder, schemaNode as ListSchemaNode);
- }
- }
-
- private def typeBuildersToGenTypes(GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) {
- val List<Type> genTypes = new ArrayList();
- checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
-
- if (genTOBuilder !== null) {
- val genTO = genTOBuilder.toInstance();
- constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO);
- genTypes.add(genTO);
- }
- genTypes.add(typeBuilder.toInstance());
- return genTypes;
- }
-
- /**
+ private def void addSchemaNodeToListBuilders(String basePackageName, DataSchemaNode schemaNode,
+ GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder, List<String> listKeys) {
+ checkArgument(schemaNode !== null, "Data Schema Node cannot be NULL.");
+
+ checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
+
+ if (schemaNode instanceof LeafSchemaNode) {
+ val leaf = schemaNode as LeafSchemaNode;
+ val leafName = leaf.QName.localName;
+ if (!listKeys.contains(leafName)) {
+ resolveLeafSchemaNodeAsMethod(typeBuilder, leaf);
+ } else {
+ resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true);
+ }
+ } else if (schemaNode instanceof LeafListSchemaNode) {
+ resolveLeafListSchemaNode(typeBuilder, schemaNode as LeafListSchemaNode);
+ } else if (schemaNode instanceof ContainerSchemaNode) {
+ resolveContainerSchemaNode(basePackageName, typeBuilder, schemaNode as ContainerSchemaNode);
+ } else if (schemaNode instanceof ListSchemaNode) {
+ resolveListSchemaNode(basePackageName, typeBuilder, schemaNode as ListSchemaNode);
+ }
+ }
+
+ private def typeBuildersToGenTypes(GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) {
+ val List<Type> genTypes = new ArrayList();
+ checkArgument(typeBuilder !== null, "Generated Type Builder cannot be NULL.");
+
+ if (genTOBuilder !== null) {
+ val genTO = genTOBuilder.toInstance();
+ constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO);
+ genTypes.add(genTO);
+ }
+ genTypes.add(typeBuilder.toInstance());
+ return genTypes;
+ }
+
+ /**
* Selects the names of the list keys from <code>list</code> and returns
* them as the list of the strings
*
* <code>list</code> contains no keys then the empty list is
* returned.
*/
- private def listKeys(ListSchemaNode list) {
- val List<String> listKeys = new ArrayList();
-
- if (list.keyDefinition !== null) {
- val keyDefinitions = list.keyDefinition;
- for (keyDefinition : keyDefinitions) {
- listKeys.add(keyDefinition.localName);
- }
- }
- return listKeys;
- }
-
- /**
+ private def listKeys(ListSchemaNode list) {
+ val List<String> listKeys = new ArrayList();
+
+ if (list.keyDefinition !== null) {
+ val keyDefinitions = list.keyDefinition;
+ for (keyDefinition : keyDefinitions) {
+ listKeys.add(keyDefinition.localName);
+ }
+ }
+ return listKeys;
+ }
+
+ /**
* Generates for the <code>list</code> which contains any list keys special
* generated TO builder.
*
* <code>list</code> or null if <code>list</code> is null or list of
* key definitions is null or empty.
*/
- private def GeneratedTOBuilder resolveListKeyTOBuilder(String packageName, ListSchemaNode list) {
- var GeneratedTOBuilder genTOBuilder = null;
- if ((list.keyDefinition !== null) && (!list.keyDefinition.isEmpty())) {
- if (list !== null) {
- val listName = list.QName.localName + "Key";
- val String genTOName = parseToClassName(listName);
- genTOBuilder = new GeneratedTOBuilderImpl(packageName, genTOName);
- }
- }
- return genTOBuilder;
-
- }
-
- /**
+ private def GeneratedTOBuilder resolveListKeyTOBuilder(String packageName, ListSchemaNode list) {
+ var GeneratedTOBuilder genTOBuilder = null;
+ if ((list.keyDefinition !== null) && (!list.keyDefinition.isEmpty())) {
+ if (list !== null) {
+ val listName = list.QName.localName + "Key";
+ val String genTOName = parseToClassName(listName);
+ genTOBuilder = new GeneratedTOBuilderImpl(packageName, genTOName);
+ }
+ }
+ return genTOBuilder;
+
+ }
+
+ /**
* Builds generated TO builders for <code>typeDef</code> of type
* {@link org.opendaylight.yangtools.yang.model.util.UnionType UnionType} or
* {@link org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
* string with name for generated TO builder
* @return generated TO builder for <code>typeDef</code>
*/
- private def GeneratedTOBuilder addTOToTypeBuilder(TypeDefinition<?> typeDef, GeneratedTypeBuilder typeBuilder,
- String leafName, LeafSchemaNode leaf, Module parentModule) {
- val classNameFromLeaf = parseToClassName(leafName);
- val List<GeneratedTOBuilder> genTOBuilders = new ArrayList();
- val packageName = typeBuilder.fullyQualifiedName;
- if (typeDef instanceof UnionTypeDefinition) {
- genTOBuilders.addAll(
- (typeProvider as TypeProviderImpl).
- provideGeneratedTOBuildersForUnionTypeDef(packageName, typeDef, classNameFromLeaf, leaf));
- } else if (typeDef instanceof BitsTypeDefinition) {
- genTOBuilders.add(
- ((typeProvider as TypeProviderImpl) ).
- provideGeneratedTOBuilderForBitsTypeDefinition(packageName, typeDef, classNameFromLeaf));
- }
- if (genTOBuilders !== null && !genTOBuilders.isEmpty()) {
- for (genTOBuilder : genTOBuilders) {
- typeBuilder.addEnclosingTransferObject(genTOBuilder);
- }
- return genTOBuilders.get(0);
- }
- return null;
-
- }
-
- /**
+ private def GeneratedTOBuilder addTOToTypeBuilder(TypeDefinition<?> typeDef, GeneratedTypeBuilder typeBuilder,
+ String leafName, LeafSchemaNode leaf, Module parentModule) {
+ val classNameFromLeaf = parseToClassName(leafName);
+ val List<GeneratedTOBuilder> genTOBuilders = new ArrayList();
+ val packageName = typeBuilder.fullyQualifiedName;
+ if (typeDef instanceof UnionTypeDefinition) {
+ genTOBuilders.addAll(
+ (typeProvider as TypeProviderImpl).
+ provideGeneratedTOBuildersForUnionTypeDef(packageName, typeDef, classNameFromLeaf, leaf));
+ } else if (typeDef instanceof BitsTypeDefinition) {
+ genTOBuilders.add(
+ ((typeProvider as TypeProviderImpl) ).
+ provideGeneratedTOBuilderForBitsTypeDefinition(packageName, typeDef, classNameFromLeaf));
+ }
+ if (genTOBuilders !== null && !genTOBuilders.isEmpty()) {
+ for (genTOBuilder : genTOBuilders) {
+ typeBuilder.addEnclosingTransferObject(genTOBuilder);
+ }
+ return genTOBuilders.get(0);
+ }
+ return null;
+
+ }
+
+ /**
* Adds the implemented types to type builder.
*
* The method passes through the list of <i>uses</i> in
* <code>dataNodeContainer</code>
* @return generated type builder with all implemented types
*/
- private def addImplementedInterfaceFromUses(DataNodeContainer dataNodeContainer, GeneratedTypeBuilder builder) {
- for (usesNode : dataNodeContainer.uses) {
- if (usesNode.groupingPath !== null) {
- val genType = allGroupings.get(usesNode.groupingPath);
- if (genType === null) {
- throw new IllegalStateException(
- "Grouping " + usesNode.groupingPath + "is not resolved for " + builder.name);
- }
- builder.addImplementsType(genType);
- }
- }
- return builder;
- }
+ private def addImplementedInterfaceFromUses(DataNodeContainer dataNodeContainer, GeneratedTypeBuilder builder) {
+ for (usesNode : dataNodeContainer.uses) {
+ if (usesNode.groupingPath !== null) {
+ val genType = allGroupings.get(usesNode.groupingPath);
+ if (genType === null) {
+ throw new IllegalStateException(
+ "Grouping " + usesNode.groupingPath + "is not resolved for " + builder.name);
+ }
+ builder.addImplementsType(genType);
+ }
+ }
+ return builder;
+ }
}
*/
private Type provideTypeForIdentityref(IdentityrefTypeDefinition idref) {
QName baseIdQName = idref.getIdentity();
- Module module = schemaContext.findModuleByNamespaceAndRevision(baseIdQName.getNamespace(),baseIdQName.getRevision());
+ Module module = schemaContext.findModuleByNamespaceAndRevision(baseIdQName.getNamespace(),
+ baseIdQName.getRevision());
IdentitySchemaNode identity = null;
for (IdentitySchemaNode id : module.getIdentities()) {
if (id.getQName().equals(baseIdQName)) {
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.data.impl;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;\r
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;\r
-import org.opendaylight.yangtools.yang.data.api.Node;\r
-import org.opendaylight.yangtools.yang.data.api.NodeModification;\r
-\r
-/**\r
- * @author michal.rehak\r
- * @param <T>\r
- * type of node value\r
- *\r
- */\r
-public abstract class AbstractNodeTO<T> implements Node<T>, NodeModification {\r
-\r
- private QName qName;\r
- private CompositeNode parent;\r
- private T value;\r
- private ModifyAction modifyAction;\r
-\r
- /**\r
- * @param qname\r
- * @param parent\r
- * @param value\r
- */\r
- public AbstractNodeTO(QName qname, CompositeNode parent, T value) {\r
- this.qName = qname;\r
- this.parent = parent;\r
- this.value = value;\r
- }\r
-\r
- /**\r
- * @param qname\r
- * @param parent\r
- * @param value\r
- * @param modifyAction\r
- */\r
- public AbstractNodeTO(QName qname, CompositeNode parent, T value, ModifyAction modifyAction) {\r
- this.qName = qname;\r
- this.parent = parent;\r
- this.value = value;\r
- this.modifyAction = modifyAction;\r
- }\r
-\r
- @Override\r
- public QName getNodeType() {\r
- return qName;\r
- }\r
-\r
- /**\r
- * @return the qName\r
- */\r
- public QName getQName() {\r
- return qName;\r
- }\r
-\r
- @Override\r
- public CompositeNode getParent() {\r
- return parent;\r
- }\r
-\r
- /**\r
- * @param parent the parent to set\r
- */\r
- public void setParent(CompositeNode parent) {\r
- this.parent = parent;\r
- }\r
-\r
- /**\r
- * @param value the value to set\r
- */\r
- protected void setValue(T value) {\r
- this.value = value;\r
- }\r
-\r
- @Override\r
- public T getValue() {\r
- return value;\r
- }\r
-\r
- /**\r
- * @return modification action\r
- * @see org.opendaylight.yangtools.yang.data.impl.NodeModificationSupport#getModificationAction()\r
- */\r
- @Override\r
- public ModifyAction getModificationAction() {\r
- return modifyAction;\r
- }\r
-\r
- /**\r
- * @param modifyAction\r
- * the modifyAction to set\r
- */\r
- protected void setModificationAction(ModifyAction modifyAction) {\r
- this.modifyAction = modifyAction;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- StringBuffer out = new StringBuffer();\r
- out.append(String.format("Node[%s], qName[%s], modify[%s]",\r
- getClass().getSimpleName(), getQName().getLocalName(),\r
- getModificationAction() == null ? "n/a" : getModificationAction()));\r
- return out.toString();\r
- }\r
-\r
- /* */\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result\r
- + ((modifyAction == null) ? 0 : modifyAction.hashCode());\r
-// result = prime * result + ((parent == null) ? 0 : parent.hashCode());\r
- result = prime * result + ((qName == null) ? 0 : qName.hashCode());\r
- result = prime * result + ((value == null) ? 0 : value.hashCode());\r
- return result % 2;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- @SuppressWarnings("unchecked")\r
- AbstractNodeTO<T> other = (AbstractNodeTO<T>) obj;\r
- if (modifyAction != other.modifyAction)\r
- return false;\r
- if (parent == null) {\r
- if (other.parent != null)\r
- return false;\r
- } else if (other.parent == null) {\r
- return false;\r
- }\r
- if (qName == null) {\r
- if (other.qName != null)\r
- return false;\r
- } else if (!qName.equals(other.qName))\r
- return false;\r
- if (value == null) {\r
- if (other.value != null)\r
- return false;\r
- } else if (!value.equals(other.value))\r
- return false;\r
- return true;\r
- }\r
- /* */\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.NodeModification;
+
+/**
+ * @author michal.rehak
+ * @param <T>
+ * type of node value
+ *
+ */
+public abstract class AbstractNodeTO<T> implements Node<T>, NodeModification {
+
+ private QName qName;
+ private CompositeNode parent;
+ private T value;
+ private ModifyAction modifyAction;
+
+ /**
+ * @param qname
+ * @param parent
+ * @param value
+ */
+ public AbstractNodeTO(QName qname, CompositeNode parent, T value) {
+ this.qName = qname;
+ this.parent = parent;
+ this.value = value;
+ }
+
+ /**
+ * @param qname
+ * @param parent
+ * @param value
+ * @param modifyAction
+ */
+ public AbstractNodeTO(QName qname, CompositeNode parent, T value, ModifyAction modifyAction) {
+ this.qName = qname;
+ this.parent = parent;
+ this.value = value;
+ this.modifyAction = modifyAction;
+ }
+
+ @Override
+ public QName getNodeType() {
+ return qName;
+ }
+
+ /**
+ * @return the qName
+ */
+ public QName getQName() {
+ return qName;
+ }
+
+ @Override
+ public CompositeNode getParent() {
+ return parent;
+ }
+
+ /**
+ * @param parent
+ * the parent to set
+ */
+ public void setParent(CompositeNode parent) {
+ this.parent = parent;
+ }
+
+ /**
+ * @param value
+ * the value to set
+ */
+ protected void setValue(T value) {
+ this.value = value;
+ }
+
+ @Override
+ public T getValue() {
+ return value;
+ }
+
+ /**
+ * @return modification action
+ * @see org.opendaylight.yangtools.yang.data.impl.NodeModificationSupport#getModificationAction()
+ */
+ @Override
+ public ModifyAction getModificationAction() {
+ return modifyAction;
+ }
+
+ /**
+ * @param modifyAction
+ * the modifyAction to set
+ */
+ protected void setModificationAction(ModifyAction modifyAction) {
+ this.modifyAction = modifyAction;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer out = new StringBuffer();
+ out.append(String.format("Node[%s], qName[%s], modify[%s]", getClass().getSimpleName(), getQName()
+ .getLocalName(), getModificationAction() == null ? "n/a" : getModificationAction()));
+ return out.toString();
+ }
+
+ /* */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((modifyAction == null) ? 0 : modifyAction.hashCode());
+ result = prime * result + ((qName == null) ? 0 : qName.hashCode());
+ result = prime * result + ((value == null) ? 0 : value.hashCode());
+ return result % 2;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ @SuppressWarnings("unchecked")
+ AbstractNodeTO<T> other = (AbstractNodeTO<T>) obj;
+ if (modifyAction != other.modifyAction) {
+ return false;
+ }
+ if (parent == null) {
+ if (other.parent != null) {
+ return false;
+ }
+ } else if (other.parent == null) {
+ return false;
+ }
+ if (qName == null) {
+ if (other.qName != null) {
+ return false;
+ }
+ } else if (!qName.equals(other.qName)) {
+ return false;
+ }
+ if (value == null) {
+ if (other.value != null) {
+ return false;
+ }
+ } else if (!value.equals(other.value)) {
+ return false;
+ }
+ return true;
+ }
+ /* */
+
+}
List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
for (Node<?> node : toFilter) {
- if (node instanceof SimpleNode<?>)
+ if (node instanceof SimpleNode<?>) {
list.add((SimpleNode<?>) node);
+ }
}
return list;
}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.data.impl;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;\r
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;\r
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;\r
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;\r
-\r
-/**\r
- * @author michal.rehak\r
- * @param <T> type of simple node value\r
- *\r
- */\r
-public class MutableSimpleNodeTOImpl<T> extends SimpleNodeTOImpl<T>\r
- implements MutableSimpleNode<T> {\r
-\r
- private SimpleNode<T> original;\r
-\r
- /**\r
- * @param qname\r
- * @param parent\r
- * @param value\r
- * @param modifyAction\r
- */\r
- public MutableSimpleNodeTOImpl(QName qname, CompositeNode parent, T value,\r
- ModifyAction modifyAction) {\r
- super(qname, parent, value, modifyAction);\r
- }\r
-\r
- @Override\r
- public void setValue(T value) {\r
- super.setValue(value);\r
- }\r
-\r
- @Override\r
- public void setModifyAction(ModifyAction action) {\r
- super.setModificationAction(action);\r
- }\r
-\r
- @Override\r
- public MutableSimpleNode<T> asMutable() {\r
- return this;\r
- }\r
-\r
- @Override\r
- public SimpleNode<T> getOriginal() {\r
- return original;\r
- }\r
-\r
- /**\r
- * @param original the original to set\r
- */\r
- public void setOriginal(SimpleNode<T> original) {\r
- this.original = original;\r
- }\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+
+/**
+ * @author michal.rehak
+ * @param <T>
+ * type of simple node value
+ *
+ */
+public class MutableSimpleNodeTOImpl<T> extends SimpleNodeTOImpl<T> implements MutableSimpleNode<T> {
+
+ private SimpleNode<T> original;
+
+ /**
+ * @param qname
+ * @param parent
+ * @param value
+ * @param modifyAction
+ */
+ public MutableSimpleNodeTOImpl(QName qname, CompositeNode parent, T value, ModifyAction modifyAction) {
+ super(qname, parent, value, modifyAction);
+ }
+
+ @Override
+ public void setValue(T value) {
+ super.setValue(value);
+ }
+
+ @Override
+ public void setModifyAction(ModifyAction action) {
+ super.setModificationAction(action);
+ }
+
+ @Override
+ public MutableSimpleNode<T> asMutable() {
+ return this;
+ }
+
+ @Override
+ public SimpleNode<T> getOriginal() {
+ return original;
+ }
+
+ /**
+ * @param original
+ * the original to set
+ */
+ public void setOriginal(SimpleNode<T> original) {
+ this.original = original;
+ }
+}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.data.impl;\r
-\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;\r
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;\r
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;\r
-import org.opendaylight.yangtools.yang.data.api.MutableNode;\r
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;\r
-import org.opendaylight.yangtools.yang.data.api.Node;\r
-import org.opendaylight.yangtools.yang.data.api.NodeModificationBuilder;\r
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;\r
-\r
-/**\r
- * @author michal.rehak\r
- *\r
- */\r
-public class NodeModificationBuilderImpl implements NodeModificationBuilder {\r
-\r
- private SchemaContext context;\r
-\r
- private Set<MutableNode<?>> changeLog;\r
- private LazyNodeToNodeMap originalToMutable;\r
-\r
- /**\r
- * @param originalTreeRootNode\r
- * @param context\r
- */\r
- public NodeModificationBuilderImpl(CompositeNode originalTreeRootNode, SchemaContext context) {\r
- this.context = context;\r
- originalToMutable = new LazyNodeToNodeMap();\r
- changeLog = new HashSet<>();\r
- }\r
-\r
- /**\r
- * @param modNode\r
- * @param action\r
- */\r
- private void addModificationToLog(MutableNode<?> modNode, ModifyAction action) {\r
- modNode.setModifyAction(action);\r
- changeLog.add(modNode);\r
- }\r
-\r
- @Override\r
- public void addNode(MutableSimpleNode<?> newNode) {\r
- NodeUtils.fixParentRelation(newNode);\r
- addModificationToLog(newNode, ModifyAction.CREATE);\r
- }\r
-\r
- @Override\r
- public void addNode(MutableCompositeNode newNode) {\r
- NodeUtils.fixParentRelation(newNode);\r
- addModificationToLog(newNode, ModifyAction.CREATE);\r
- }\r
-\r
- @Override\r
- public void replaceNode(MutableSimpleNode<?> replacementNode) {\r
- addModificationToLog(replacementNode, ModifyAction.REPLACE);\r
- }\r
-\r
- @Override\r
- public void replaceNode(MutableCompositeNode replacementNode) {\r
- addModificationToLog(replacementNode, ModifyAction.REPLACE);\r
- }\r
-\r
- @Override\r
- public void deleteNode(MutableCompositeNode deadNode) {\r
- addModificationToLog(deadNode, ModifyAction.DELETE);\r
- }\r
-\r
- @Override\r
- public void deleteNode(MutableSimpleNode<?> deadNode) {\r
- addModificationToLog(deadNode, ModifyAction.DELETE);\r
- }\r
-\r
- @Override\r
- public void removeNode(MutableSimpleNode<?> deadNode) {\r
- addModificationToLog(deadNode, ModifyAction.REMOVE);\r
- }\r
-\r
- @Override\r
- public void removeNode(MutableCompositeNode deadNode) {\r
- addModificationToLog(deadNode, ModifyAction.REMOVE);\r
- }\r
-\r
- @Override\r
- public void mergeNode(MutableCompositeNode alteredNode) {\r
- addModificationToLog(alteredNode, ModifyAction.MERGE);\r
- }\r
-\r
- /**\r
- * @return minimalistic tree containing diffs only\r
- */\r
- @Override\r
- public CompositeNode buildDiffTree() {\r
- Set<Node<?>> wanted = new HashSet<>();\r
-\r
- // walk changeLog, collect all required nodes\r
- for (MutableNode<?> mutant : changeLog) {\r
- wanted.addAll(collectSelfAndAllParents(mutant));\r
- }\r
-\r
- // walk wanted and add relevant keys\r
- Map<String, ListSchemaNode> mapOfLists = NodeUtils.buildMapOfListNodes(context);\r
- for (Node<?> outlaw : wanted) {\r
- if (outlaw instanceof CompositeNode) {\r
- String path = NodeUtils.buildPath(outlaw);\r
- if (mapOfLists.containsKey(path)) {\r
- ListSchemaNode listSchema = mapOfLists.get(path);\r
- if (listSchema.getQName().equals(outlaw.getNodeType())) {\r
- // try to add key subnode to wanted list\r
- List<QName> supportedKeys = listSchema.getKeyDefinition();\r
- CompositeNode outlawOriginal = ((MutableCompositeNode) outlaw).getOriginal();\r
- for (Node<?> outlawOriginalChild : outlawOriginal.getChildren()) {\r
- if (supportedKeys.contains(outlawOriginalChild.getNodeType())) {\r
- originalToMutable.getMutableEquivalent(outlawOriginalChild);\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- return originalToMutable.getMutableRoot();\r
- }\r
-\r
- /**\r
- * @param focusedDescendant\r
- * @return set of parents and focusedAncestor itself\r
- */\r
- private static Set<Node<?>> collectSelfAndAllParents(Node<?> focusedDescendant) {\r
- Set<Node<?>> family = new HashSet<>();\r
- Node<?> tmpNode = focusedDescendant;\r
- while (tmpNode != null) {\r
- family.add(tmpNode);\r
- tmpNode = tmpNode.getParent();\r
- }\r
- return family;\r
- }\r
-\r
- /**\r
- * @param originalNode\r
- * @return mutable version of given node\r
- */\r
- @Override\r
- public Node<?> getMutableEquivalent(Node<?> originalNode) {\r
- return originalToMutable.getMutableEquivalent(originalNode);\r
- }\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.NodeModificationBuilder;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+/**
+ * @author michal.rehak
+ *
+ */
+public class NodeModificationBuilderImpl implements NodeModificationBuilder {
+
+ private SchemaContext context;
+
+ private Set<MutableNode<?>> changeLog;
+ private LazyNodeToNodeMap originalToMutable;
+
+ /**
+ * @param context
+ */
+ public NodeModificationBuilderImpl(SchemaContext context) {
+ this.context = context;
+ originalToMutable = new LazyNodeToNodeMap();
+ changeLog = new HashSet<>();
+ }
+
+ /**
+ * @param modNode
+ * @param action
+ */
+ private void addModificationToLog(MutableNode<?> modNode, ModifyAction action) {
+ modNode.setModifyAction(action);
+ changeLog.add(modNode);
+ }
+
+ @Override
+ public void addNode(MutableSimpleNode<?> newNode) {
+ NodeUtils.fixParentRelation(newNode);
+ addModificationToLog(newNode, ModifyAction.CREATE);
+ }
+
+ @Override
+ public void addNode(MutableCompositeNode newNode) {
+ NodeUtils.fixParentRelation(newNode);
+ addModificationToLog(newNode, ModifyAction.CREATE);
+ }
+
+ @Override
+ public void replaceNode(MutableSimpleNode<?> replacementNode) {
+ addModificationToLog(replacementNode, ModifyAction.REPLACE);
+ }
+
+ @Override
+ public void replaceNode(MutableCompositeNode replacementNode) {
+ addModificationToLog(replacementNode, ModifyAction.REPLACE);
+ }
+
+ @Override
+ public void deleteNode(MutableCompositeNode deadNode) {
+ addModificationToLog(deadNode, ModifyAction.DELETE);
+ }
+
+ @Override
+ public void deleteNode(MutableSimpleNode<?> deadNode) {
+ addModificationToLog(deadNode, ModifyAction.DELETE);
+ }
+
+ @Override
+ public void removeNode(MutableSimpleNode<?> deadNode) {
+ addModificationToLog(deadNode, ModifyAction.REMOVE);
+ }
+
+ @Override
+ public void removeNode(MutableCompositeNode deadNode) {
+ addModificationToLog(deadNode, ModifyAction.REMOVE);
+ }
+
+ @Override
+ public void mergeNode(MutableCompositeNode alteredNode) {
+ addModificationToLog(alteredNode, ModifyAction.MERGE);
+ }
+
+ /**
+ * @return minimalistic tree containing diffs only
+ */
+ @Override
+ public CompositeNode buildDiffTree() {
+ Set<Node<?>> wanted = new HashSet<>();
+
+ // walk changeLog, collect all required nodes
+ for (MutableNode<?> mutant : changeLog) {
+ wanted.addAll(collectSelfAndAllParents(mutant));
+ }
+
+ // walk wanted and add relevant keys
+ Map<String, ListSchemaNode> mapOfLists = NodeUtils.buildMapOfListNodes(context);
+ for (Node<?> outlaw : wanted) {
+ if (outlaw instanceof CompositeNode) {
+ String path = NodeUtils.buildPath(outlaw);
+ if (mapOfLists.containsKey(path)) {
+ ListSchemaNode listSchema = mapOfLists.get(path);
+ if (listSchema.getQName().equals(outlaw.getNodeType())) {
+ // try to add key subnode to wanted list
+ List<QName> supportedKeys = listSchema.getKeyDefinition();
+ CompositeNode outlawOriginal = ((MutableCompositeNode) outlaw).getOriginal();
+ for (Node<?> outlawOriginalChild : outlawOriginal.getChildren()) {
+ if (supportedKeys.contains(outlawOriginalChild.getNodeType())) {
+ originalToMutable.getMutableEquivalent(outlawOriginalChild);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return originalToMutable.getMutableRoot();
+ }
+
+ /**
+ * @param focusedDescendant
+ * @return set of parents and focusedAncestor itself
+ */
+ private static Set<Node<?>> collectSelfAndAllParents(Node<?> focusedDescendant) {
+ Set<Node<?>> family = new HashSet<>();
+ Node<?> tmpNode = focusedDescendant;
+ while (tmpNode != null) {
+ family.add(tmpNode);
+ tmpNode = tmpNode.getParent();
+ }
+ return family;
+ }
+
+ /**
+ * @param originalNode
+ * @return mutable version of given node
+ */
+ @Override
+ public Node<?> getMutableEquivalent(Node<?> originalNode) {
+ return originalToMutable.getMutableEquivalent(originalNode);
+ }
+
+}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.data.impl;\r
-\r
-import java.util.AbstractMap.SimpleEntry;\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Stack;\r
-import java.util.Vector;\r
-\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.DocumentBuilderFactory;\r
-import javax.xml.parsers.ParserConfigurationException;\r
-import javax.xml.xpath.XPath;\r
-import javax.xml.xpath.XPathConstants;\r
-import javax.xml.xpath.XPathExpression;\r
-import javax.xml.xpath.XPathExpressionException;\r
-import javax.xml.xpath.XPathFactory;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;\r
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;\r
-import org.opendaylight.yangtools.yang.data.api.Node;\r
-import org.opendaylight.yangtools.yang.data.api.NodeModification;\r
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;\r
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;\r
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.w3c.dom.Element;\r
-\r
-import com.google.common.base.Joiner;\r
-import com.google.common.collect.Lists;\r
-\r
-\r
-/**\r
- * @author michal.rehak\r
- *\r
- */\r
-public abstract class NodeUtils {\r
-\r
- private static final Logger LOG = LoggerFactory.getLogger(NodeUtils.class);\r
-\r
- /**\r
- *\r
- */\r
- private static final String USER_KEY_NODE = "node";\r
-\r
- /**\r
- * @param node\r
- * @return node path up till root node\r
- */\r
- public static String buildPath(Node<?> node) {\r
- Vector<String> breadCrumbs = new Vector<>();\r
- Node<?> tmpNode = node;\r
- while (tmpNode != null) {\r
- breadCrumbs.insertElementAt(tmpNode.getNodeType().getLocalName(), 0);\r
- tmpNode = tmpNode.getParent();\r
- }\r
-\r
- return Joiner.on(".").join(breadCrumbs);\r
- }\r
-\r
-\r
- /**\r
- * @param treeRootNode\r
- * @return dom tree, containing same node structure, yang nodes are associated\r
- * to dom nodes as user data\r
- */\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl;
+
+import java.util.AbstractMap.SimpleEntry;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.NodeModification;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Element;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Lists;
+
+/**
+ * @author michal.rehak
+ *
+ */
+public abstract class NodeUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NodeUtils.class);
+
+ /**
+ *
+ */
+ private static final String USER_KEY_NODE = "node";
+
+ /**
+ * @param node
+ * @return node path up till root node
+ */
+ public static String buildPath(Node<?> node) {
+ List<String> breadCrumbs = new ArrayList<>();
+ Node<?> tmpNode = node;
+ while (tmpNode != null) {
+ breadCrumbs.add(0, tmpNode.getNodeType().getLocalName());
+ tmpNode = tmpNode.getParent();
+ }
+
+ return Joiner.on(".").join(breadCrumbs);
+ }
+
+ /**
+ * @param treeRootNode
+ * @return dom tree, containing same node structure, yang nodes are
+ * associated to dom nodes as user data
+ */
public static org.w3c.dom.Document buildShadowDomTree(CompositeNode treeRootNode) {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
- org.w3c.dom.Document doc = null;\r
- try {\r
- DocumentBuilder bob = dbf.newDocumentBuilder();\r
- doc = bob.newDocument();\r
- } catch (ParserConfigurationException e) {\r
- LOG.error("documentBuilder problem", e);\r
- return null;\r
- }\r
-\r
-\r
- Stack<SimpleEntry<org.w3c.dom.Node, Node<?>>> jobQueue = new Stack<>();\r
- jobQueue.push(new SimpleEntry<org.w3c.dom.Node, Node<?>>(doc, treeRootNode));\r
-\r
- while (!jobQueue.isEmpty()) {\r
- SimpleEntry<org.w3c.dom.Node, Node<?>> job = jobQueue.pop();\r
- org.w3c.dom.Node jointPlace = job.getKey();\r
- Node<?> item = job.getValue();\r
- QName nodeType = item.getNodeType();\r
- Element itemEl = doc.createElementNS(nodeType.getNamespace().toString(),\r
- item.getNodeType().getLocalName());\r
- itemEl.setUserData(USER_KEY_NODE, item, null);\r
- if (item instanceof SimpleNode<?>) {\r
- Object value = ((SimpleNode<?>) item).getValue();\r
- itemEl.setTextContent(String.valueOf(value));\r
- //itemEl.setAttribute("type", value.getClass().getSimpleName());\r
- }\r
- if (item instanceof NodeModification) {\r
- ModifyAction modificationAction = ((NodeModification) item).getModificationAction();\r
- if (modificationAction != null) {\r
- itemEl.setAttribute("modifyAction", modificationAction.toString());\r
- }\r
- }\r
-\r
- jointPlace.appendChild(itemEl);\r
-\r
- if (item instanceof CompositeNode) {\r
- for (Node<?> child : ((CompositeNode) item).getChildren()) {\r
- jobQueue.push(new SimpleEntry<org.w3c.dom.Node, Node<?>>(itemEl, child));\r
- }\r
- }\r
- }\r
-\r
- return doc;\r
- }\r
-\r
- /**\r
- * @param doc\r
- * @param xpathEx\r
- * @return user data value on found node\r
- * @throws XPathExpressionException\r
- */\r
- @SuppressWarnings("unchecked")\r
- public static <T> T findNodeByXpath(org.w3c.dom.Document doc, String xpathEx)\r
- throws XPathExpressionException {\r
- T userNode = null;\r
- XPathFactory xPathfactory = XPathFactory.newInstance();\r
- XPath xpath = xPathfactory.newXPath();\r
- XPathExpression expr = xpath.compile(xpathEx);\r
-\r
- org.w3c.dom.Node result = (org.w3c.dom.Node) expr.evaluate(doc, XPathConstants.NODE);\r
- if (result != null) {\r
- userNode = (T) result.getUserData(USER_KEY_NODE);\r
- }\r
-\r
- return userNode;\r
- }\r
-\r
-\r
- /**\r
- * build NodeMap, where key = qName; value = node\r
- *\r
- * @param value\r
- * @return map of children, where key = qName and value is list of children groupped by qName\r
- */\r
- public static Map<QName, List<Node<?>>> buildNodeMap(List<Node<?>> value) {\r
- Map<QName, List<Node<?>>> nodeMapTmp = new HashMap<>();\r
- if (value == null || value.isEmpty()) {\r
- throw new IllegalStateException(\r
- "nodeList should not be null or empty");\r
- }\r
- for (Node<?> node : value) {\r
- List<Node<?>> qList = nodeMapTmp.get(node.getNodeType());\r
- if (qList == null) {\r
- qList = new ArrayList<>();\r
- nodeMapTmp.put(node.getNodeType(), qList);\r
- }\r
- qList.add(node);\r
- }\r
- return nodeMapTmp;\r
- }\r
-\r
-\r
- /**\r
- * @param context\r
- * @return map of lists, where key = path; value = {@link DataSchemaNode}\r
- */\r
- public static Map<String, ListSchemaNode> buildMapOfListNodes(\r
- SchemaContext context) {\r
- Map<String, ListSchemaNode> mapOfLists = new HashMap<>();\r
-\r
- Stack<DataSchemaNode> jobQueue = new Stack<>();\r
- jobQueue.addAll(context.getDataDefinitions());\r
-\r
- while (!jobQueue.isEmpty()) {\r
- DataSchemaNode dataSchema = jobQueue.pop();\r
- if (dataSchema instanceof ListSchemaNode) {\r
- mapOfLists.put(schemaPathToPath(dataSchema.getPath().getPath()), (ListSchemaNode) dataSchema);\r
- }\r
-\r
- if (dataSchema instanceof DataNodeContainer) {\r
- jobQueue.addAll(((DataNodeContainer) dataSchema).getChildNodes());\r
- }\r
- }\r
-\r
- return mapOfLists;\r
- }\r
-\r
- /**\r
- * @param path\r
- * @return\r
- */\r
- private static String schemaPathToPath(List<QName> qNamesPath) {\r
- List<String> pathSeed = new ArrayList<>();\r
- for (QName qNameItem : qNamesPath) {\r
- pathSeed.add(qNameItem.getLocalName());\r
- }\r
- return Joiner.on(".").join(pathSeed);\r
- }\r
-\r
- /**\r
- * add given node to it's parent's list of children\r
- * @param newNode\r
- */\r
- public static void fixParentRelation(Node<?> newNode) {\r
- if (newNode.getParent() != null) {\r
- List<Node<?>> siblings = newNode.getParent().getChildren();\r
- if (!siblings.contains(newNode)) {\r
- siblings.add(newNode);\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * crawl all children of given node and assign it as their parent\r
- * @param parentNode\r
- */\r
- public static void fixChildrenRelation(CompositeNode parentNode) {\r
- if (parentNode.getChildren() != null) {\r
- for (Node<?> child : parentNode.getChildren()) {\r
- if (child instanceof AbstractNodeTO<?>) {\r
- ((AbstractNodeTO<?>) child).setParent(parentNode);\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- /**\r
- * @param keys\r
- * @param dataMap\r
- * @return list of values of map, found by given keys\r
- */\r
- public static <T, K> List<K> collectMapValues(List<T> keys,\r
- Map<T, K> dataMap) {\r
- List<K> valueSubList = new ArrayList<>();\r
- for (T key : keys) {\r
- valueSubList.add(dataMap.get(key));\r
- }\r
-\r
- return valueSubList;\r
- }\r
-\r
- /**\r
- * @param nodes\r
- * @return list of children in list of appropriate type\r
- */\r
- public static List<Node<?>> buildChildrenList(Node<?>...nodes) {\r
- return Lists.newArrayList(nodes);\r
- }\r
-\r
-}\r
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ org.w3c.dom.Document doc = null;
+ try {
+ DocumentBuilder bob = dbf.newDocumentBuilder();
+ doc = bob.newDocument();
+ } catch (ParserConfigurationException e) {
+ LOG.error("documentBuilder problem", e);
+ return null;
+ }
+
+ Stack<SimpleEntry<org.w3c.dom.Node, Node<?>>> jobQueue = new Stack<>();
+ jobQueue.push(new SimpleEntry<org.w3c.dom.Node, Node<?>>(doc, treeRootNode));
+
+ while (!jobQueue.isEmpty()) {
+ SimpleEntry<org.w3c.dom.Node, Node<?>> job = jobQueue.pop();
+ org.w3c.dom.Node jointPlace = job.getKey();
+ Node<?> item = job.getValue();
+ QName nodeType = item.getNodeType();
+ Element itemEl = doc.createElementNS(nodeType.getNamespace().toString(), item.getNodeType().getLocalName());
+ itemEl.setUserData(USER_KEY_NODE, item, null);
+ if (item instanceof SimpleNode<?>) {
+ Object value = ((SimpleNode<?>) item).getValue();
+ itemEl.setTextContent(String.valueOf(value));
+ }
+ if (item instanceof NodeModification) {
+ ModifyAction modificationAction = ((NodeModification) item).getModificationAction();
+ if (modificationAction != null) {
+ itemEl.setAttribute("modifyAction", modificationAction.toString());
+ }
+ }
+
+ jointPlace.appendChild(itemEl);
+
+ if (item instanceof CompositeNode) {
+ for (Node<?> child : ((CompositeNode) item).getChildren()) {
+ jobQueue.push(new SimpleEntry<org.w3c.dom.Node, Node<?>>(itemEl, child));
+ }
+ }
+ }
+
+ return doc;
+ }
+
+ /**
+ * @param doc
+ * @param xpathEx
+ * @return user data value on found node
+ * @throws XPathExpressionException
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> T findNodeByXpath(org.w3c.dom.Document doc, String xpathEx) throws XPathExpressionException {
+ T userNode = null;
+ XPathFactory xPathfactory = XPathFactory.newInstance();
+ XPath xpath = xPathfactory.newXPath();
+ XPathExpression expr = xpath.compile(xpathEx);
+
+ org.w3c.dom.Node result = (org.w3c.dom.Node) expr.evaluate(doc, XPathConstants.NODE);
+ if (result != null) {
+ userNode = (T) result.getUserData(USER_KEY_NODE);
+ }
+
+ return userNode;
+ }
+
+ /**
+ * build NodeMap, where key = qName; value = node
+ *
+ * @param value
+ * @return map of children, where key = qName and value is list of children
+ * groupped by qName
+ */
+ public static Map<QName, List<Node<?>>> buildNodeMap(List<Node<?>> value) {
+ Map<QName, List<Node<?>>> nodeMapTmp = new HashMap<>();
+ if (value == null || value.isEmpty()) {
+ throw new IllegalStateException("nodeList should not be null or empty");
+ }
+ for (Node<?> node : value) {
+ List<Node<?>> qList = nodeMapTmp.get(node.getNodeType());
+ if (qList == null) {
+ qList = new ArrayList<>();
+ nodeMapTmp.put(node.getNodeType(), qList);
+ }
+ qList.add(node);
+ }
+ return nodeMapTmp;
+ }
+
+ /**
+ * @param context
+ * @return map of lists, where key = path; value = {@link DataSchemaNode}
+ */
+ public static Map<String, ListSchemaNode> buildMapOfListNodes(SchemaContext context) {
+ Map<String, ListSchemaNode> mapOfLists = new HashMap<>();
+
+ Stack<DataSchemaNode> jobQueue = new Stack<>();
+ jobQueue.addAll(context.getDataDefinitions());
+
+ while (!jobQueue.isEmpty()) {
+ DataSchemaNode dataSchema = jobQueue.pop();
+ if (dataSchema instanceof ListSchemaNode) {
+ mapOfLists.put(schemaPathToPath(dataSchema.getPath().getPath()), (ListSchemaNode) dataSchema);
+ }
+
+ if (dataSchema instanceof DataNodeContainer) {
+ jobQueue.addAll(((DataNodeContainer) dataSchema).getChildNodes());
+ }
+ }
+
+ return mapOfLists;
+ }
+
+ /**
+ * @param path
+ * @return
+ */
+ private static String schemaPathToPath(List<QName> qNamesPath) {
+ List<String> pathSeed = new ArrayList<>();
+ for (QName qNameItem : qNamesPath) {
+ pathSeed.add(qNameItem.getLocalName());
+ }
+ return Joiner.on(".").join(pathSeed);
+ }
+
+ /**
+ * add given node to it's parent's list of children
+ *
+ * @param newNode
+ */
+ public static void fixParentRelation(Node<?> newNode) {
+ if (newNode.getParent() != null) {
+ List<Node<?>> siblings = newNode.getParent().getChildren();
+ if (!siblings.contains(newNode)) {
+ siblings.add(newNode);
+ }
+ }
+ }
+
+ /**
+ * crawl all children of given node and assign it as their parent
+ *
+ * @param parentNode
+ */
+ public static void fixChildrenRelation(CompositeNode parentNode) {
+ if (parentNode.getChildren() != null) {
+ for (Node<?> child : parentNode.getChildren()) {
+ if (child instanceof AbstractNodeTO<?>) {
+ ((AbstractNodeTO<?>) child).setParent(parentNode);
+ }
+ }
+ }
+ }
+
+ /**
+ * @param keys
+ * @param dataMap
+ * @return list of values of map, found by given keys
+ */
+ public static <T, K> List<K> collectMapValues(List<T> keys, Map<T, K> dataMap) {
+ List<K> valueSubList = new ArrayList<>();
+ for (T key : keys) {
+ valueSubList.add(dataMap.get(key));
+ }
+
+ return valueSubList;
+ }
+
+ /**
+ * @param nodes
+ * @return list of children in list of appropriate type
+ */
+ public static List<Node<?>> buildChildrenList(Node<?>... nodes) {
+ return Lists.newArrayList(nodes);
+ }
+
+}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.data.impl;\r
-\r
-import java.net.URI;\r
-import java.util.Date;\r
-\r
-import junit.framework.Assert;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;\r
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;\r
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;\r
-import org.opendaylight.yangtools.yang.data.api.Node;\r
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.w3c.dom.Document;\r
-\r
-/**\r
- * @author michal.rehak\r
- *\r
- */\r
-public class NodeModificationBuilderImplTest {\r
-\r
- private static final Logger LOG = LoggerFactory\r
- .getLogger(NodeModificationBuilderImplTest.class);\r
-\r
- private SchemaContext schemaCtx;\r
- private QName qName;\r
- private CompositeNode network;\r
- private NodeModificationBuilderImpl nodeModificationBuilder;\r
-\r
- private String ns;\r
-\r
- /**\r
- * @throws Exception\r
- */\r
- private void dumpResult() throws Exception {\r
- CompositeNode diffTree = nodeModificationBuilder.buildDiffTree();\r
- CompositeNode diffTreeImmutable = NodeFactory.copyDeepAsImmutable(diffTree, null);\r
-\r
- Document diffShadow = NodeUtils.buildShadowDomTree(diffTreeImmutable);\r
- NodeHelper.dumpDoc(diffShadow, System.out);\r
- }\r
-\r
- /**\r
- * prepare schemaContext\r
- * @throws Exception\r
- */\r
- @Before\r
- public void setUp() throws Exception {\r
- schemaCtx = NodeHelper.loadSchemaContext();\r
-\r
- ns = "urn:opendaylight:controller:network";\r
- qName = new QName(\r
- new URI(ns),\r
- new Date(1369000800000L), "topos");\r
- network = NodeHelper.buildTestConfigTree(qName);\r
-\r
- nodeModificationBuilder = new NodeModificationBuilderImpl(network, schemaCtx);\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)}\r
- * .\r
- */\r
- @Test\r
- public void testGetMutableEquivalent() {\r
- MutableCompositeNode rootMutable = (MutableCompositeNode)\r
- nodeModificationBuilder.getMutableEquivalent(network);\r
-\r
- CompositeNode topologies = network.getCompositesByName("topologies").iterator().next();\r
- Node<?> mutableEquivalent = nodeModificationBuilder.getMutableEquivalent(topologies);\r
- CompositeNode topologiesMutable = rootMutable.getCompositesByName("topologies").iterator().next();\r
-\r
- Assert.assertSame(topologiesMutable, mutableEquivalent);\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}\r
- * .\r
- * @throws Exception\r
- */\r
- @Test\r
- public void testBuildDiffTreeAddSimple() throws Exception {\r
- LOG.debug("testBuildDiffTreeAddSimple");\r
- Document networkShadow = NodeUtils.buildShadowDomTree(network);\r
- CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow,\r
- NodeHelper.AddNamespaceToPattern(\r
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns));\r
-\r
- MutableCompositeNode mutableParent = (MutableCompositeNode)\r
- nodeModificationBuilder.getMutableEquivalent(needle);\r
-\r
- MutableSimpleNode<String> newMutable = NodeFactory.createMutableSimpleNode(\r
- new QName(needle.getNodeType(), "anySubNode"), mutableParent, "42", null, null);\r
-\r
- nodeModificationBuilder.addNode(newMutable);\r
- dumpResult();\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}\r
- * .\r
- * @throws Exception\r
- */\r
- @Test\r
- public void testBuildDiffTreeAddComposite() throws Exception {\r
- LOG.debug("testBuildDiffTreeAddComposite");\r
- Document networkShadow = NodeUtils.buildShadowDomTree(network);\r
- CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow,\r
- NodeHelper.AddNamespaceToPattern(\r
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns));\r
-\r
- MutableCompositeNode mutableParent = (MutableCompositeNode)\r
- nodeModificationBuilder.getMutableEquivalent(needle);\r
-\r
- MutableSimpleNode<String> newMutable = NodeFactory.createMutableSimpleNode(\r
- new QName(needle.getNodeType(), "anySubNode"), null, "42", null, null);\r
-\r
- MutableCompositeNode newMutableCom = NodeFactory.createMutableCompositeNode(\r
- new QName(needle.getNodeType(), "anySubNode"), mutableParent,\r
- NodeUtils.buildChildrenList(newMutable), null, null);\r
- NodeUtils.fixChildrenRelation(newMutableCom);\r
- newMutableCom.init();\r
-\r
- nodeModificationBuilder.addNode(newMutableCom);\r
- dumpResult();\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}\r
- * .\r
- * @throws Exception\r
- */\r
- @Test\r
- public void testBuildDiffTreeDeleteComposite() throws Exception {\r
- LOG.debug("testBuildDiffTreeDeleteComposite");\r
- Document networkShadow = NodeUtils.buildShadowDomTree(network);\r
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow,\r
- NodeHelper.AddNamespaceToPattern(\r
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));\r
-\r
- @SuppressWarnings("unchecked")\r
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>)\r
- nodeModificationBuilder.getMutableEquivalent(needle);\r
-\r
- nodeModificationBuilder.deleteNode(mutableNeedle.getParent().asMutable());\r
- dumpResult();\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}\r
- * .\r
- * @throws Exception\r
- */\r
- @Test\r
- public void testBuildDiffTreeDeleteSimple() throws Exception {\r
- LOG.debug("testBuildDiffTreeDeleteSimple");\r
- Document networkShadow = NodeUtils.buildShadowDomTree(network);\r
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow,\r
- NodeHelper.AddNamespaceToPattern(\r
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));\r
-\r
- @SuppressWarnings("unchecked")\r
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>)\r
- nodeModificationBuilder.getMutableEquivalent(needle);\r
-\r
- nodeModificationBuilder.deleteNode(mutableNeedle);\r
- dumpResult();\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}\r
- * .\r
- * @throws Exception\r
- */\r
- @Test\r
- public void testBuildDiffTreeMerge() throws Exception {\r
- LOG.debug("testBuildDiffTreeMerge");\r
- Document networkShadow = NodeUtils.buildShadowDomTree(network);\r
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow,\r
- NodeHelper.AddNamespaceToPattern(\r
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));\r
-\r
- @SuppressWarnings("unchecked")\r
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>)\r
- nodeModificationBuilder.getMutableEquivalent(needle);\r
-\r
- mutableNeedle.setValue("tpId_18x");\r
- nodeModificationBuilder.mergeNode(mutableNeedle.getParent().asMutable());\r
- dumpResult();\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}\r
- * .\r
- * @throws Exception\r
- */\r
- @Test\r
- public void testBuildDiffTreeRemoveComposite() throws Exception {\r
- LOG.debug("testBuildDiffTreeRemoveComposite");\r
- Document networkShadow = NodeUtils.buildShadowDomTree(network);\r
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow,\r
- NodeHelper.AddNamespaceToPattern(\r
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));\r
-\r
- @SuppressWarnings("unchecked")\r
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>)\r
- nodeModificationBuilder.getMutableEquivalent(needle);\r
-\r
- nodeModificationBuilder.removeNode(mutableNeedle.getParent().asMutable());\r
- dumpResult();\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}\r
- * .\r
- * @throws Exception\r
- */\r
- @Test\r
- public void testBuildDiffTreeRemoveSimple() throws Exception {\r
- LOG.debug("testBuildDiffTreeRemoveSimple");\r
- Document networkShadow = NodeUtils.buildShadowDomTree(network);\r
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow,\r
- NodeHelper.AddNamespaceToPattern(\r
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));\r
-\r
- @SuppressWarnings("unchecked")\r
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>)\r
- nodeModificationBuilder.getMutableEquivalent(needle);\r
-\r
- nodeModificationBuilder.removeNode(mutableNeedle);\r
- dumpResult();\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}\r
- * .\r
- * @throws Exception\r
- */\r
- @Test\r
- public void testBuildDiffTreeReplaceComposite() throws Exception {\r
- LOG.debug("testBuildDiffTreeReplaceComposite");\r
- Document networkShadow = NodeUtils.buildShadowDomTree(network);\r
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow,\r
- NodeHelper.AddNamespaceToPattern(\r
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));\r
-\r
- @SuppressWarnings("unchecked")\r
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>)\r
- nodeModificationBuilder.getMutableEquivalent(needle);\r
-\r
- mutableNeedle.setValue("tpId_18x");\r
- nodeModificationBuilder.replaceNode(mutableNeedle.getParent().asMutable());\r
- dumpResult();\r
- }\r
-\r
- /**\r
- * Test method for\r
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}\r
- * .\r
- * @throws Exception\r
- */\r
- @Test\r
- public void testBuildDiffTreeReplaceSimple() throws Exception {\r
- LOG.debug("testBuildDiffTreeReplaceSimple");\r
- Document networkShadow = NodeUtils.buildShadowDomTree(network);\r
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow,\r
- NodeHelper.AddNamespaceToPattern(\r
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));\r
-\r
- @SuppressWarnings("unchecked")\r
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>)\r
- nodeModificationBuilder.getMutableEquivalent(needle);\r
-\r
- mutableNeedle.setValue("tpId_18x");\r
- nodeModificationBuilder.replaceNode(mutableNeedle);\r
- dumpResult();\r
- }\r
-\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl;
+
+import java.net.URI;
+import java.util.Date;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+/**
+ * @author michal.rehak
+ *
+ */
+public class NodeModificationBuilderImplTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(NodeModificationBuilderImplTest.class);
+
+ private SchemaContext schemaCtx;
+ private QName qName;
+ private CompositeNode network;
+ private NodeModificationBuilderImpl nodeModificationBuilder;
+
+ private String ns;
+
+ /**
+ * @throws Exception
+ */
+ private void dumpResult() throws Exception {
+ CompositeNode diffTree = nodeModificationBuilder.buildDiffTree();
+ CompositeNode diffTreeImmutable = NodeFactory.copyDeepAsImmutable(diffTree, null);
+
+ Document diffShadow = NodeUtils.buildShadowDomTree(diffTreeImmutable);
+ NodeHelper.dumpDoc(diffShadow, System.out);
+ }
+
+ /**
+ * prepare schemaContext
+ *
+ * @throws Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ schemaCtx = NodeHelper.loadSchemaContext();
+
+ ns = "urn:opendaylight:controller:network";
+ qName = new QName(new URI(ns), new Date(1369000800000L), "topos");
+ network = NodeHelper.buildTestConfigTree(qName);
+
+ nodeModificationBuilder = new NodeModificationBuilderImpl(schemaCtx);
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)}
+ * .
+ */
+ @Test
+ public void testGetMutableEquivalent() {
+ MutableCompositeNode rootMutable = (MutableCompositeNode) nodeModificationBuilder.getMutableEquivalent(network);
+
+ CompositeNode topologies = network.getCompositesByName("topologies").iterator().next();
+ Node<?> mutableEquivalent = nodeModificationBuilder.getMutableEquivalent(topologies);
+ CompositeNode topologiesMutable = rootMutable.getCompositesByName("topologies").iterator().next();
+
+ Assert.assertSame(topologiesMutable, mutableEquivalent);
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
+ * .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBuildDiffTreeAddSimple() throws Exception {
+ LOG.debug("testBuildDiffTreeAddSimple");
+ Document networkShadow = NodeUtils.buildShadowDomTree(network);
+ CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow,
+ NodeHelper.AddNamespaceToPattern("//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns));
+
+ MutableCompositeNode mutableParent = (MutableCompositeNode) nodeModificationBuilder
+ .getMutableEquivalent(needle);
+
+ MutableSimpleNode<String> newMutable = NodeFactory.createMutableSimpleNode(new QName(needle.getNodeType(),
+ "anySubNode"), mutableParent, "42", null, null);
+
+ nodeModificationBuilder.addNode(newMutable);
+ dumpResult();
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
+ * .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBuildDiffTreeAddComposite() throws Exception {
+ LOG.debug("testBuildDiffTreeAddComposite");
+ Document networkShadow = NodeUtils.buildShadowDomTree(network);
+ CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow,
+ NodeHelper.AddNamespaceToPattern("//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns));
+
+ MutableCompositeNode mutableParent = (MutableCompositeNode) nodeModificationBuilder
+ .getMutableEquivalent(needle);
+
+ MutableSimpleNode<String> newMutable = NodeFactory.createMutableSimpleNode(new QName(needle.getNodeType(),
+ "anySubNode"), null, "42", null, null);
+
+ MutableCompositeNode newMutableCom = NodeFactory.createMutableCompositeNode(new QName(needle.getNodeType(),
+ "anySubNode"), mutableParent, NodeUtils.buildChildrenList(newMutable), null, null);
+ NodeUtils.fixChildrenRelation(newMutableCom);
+ newMutableCom.init();
+
+ nodeModificationBuilder.addNode(newMutableCom);
+ dumpResult();
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
+ * .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBuildDiffTreeDeleteComposite() throws Exception {
+ LOG.debug("testBuildDiffTreeDeleteComposite");
+ Document networkShadow = NodeUtils.buildShadowDomTree(network);
+ SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
+ "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
+
+ @SuppressWarnings("unchecked")
+ MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
+ .getMutableEquivalent(needle);
+
+ nodeModificationBuilder.deleteNode(mutableNeedle.getParent().asMutable());
+ dumpResult();
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
+ * .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBuildDiffTreeDeleteSimple() throws Exception {
+ LOG.debug("testBuildDiffTreeDeleteSimple");
+ Document networkShadow = NodeUtils.buildShadowDomTree(network);
+ SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
+ "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
+
+ @SuppressWarnings("unchecked")
+ MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
+ .getMutableEquivalent(needle);
+
+ nodeModificationBuilder.deleteNode(mutableNeedle);
+ dumpResult();
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
+ * .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBuildDiffTreeMerge() throws Exception {
+ LOG.debug("testBuildDiffTreeMerge");
+ Document networkShadow = NodeUtils.buildShadowDomTree(network);
+ SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
+ "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
+
+ @SuppressWarnings("unchecked")
+ MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
+ .getMutableEquivalent(needle);
+
+ mutableNeedle.setValue("tpId_18x");
+ nodeModificationBuilder.mergeNode(mutableNeedle.getParent().asMutable());
+ dumpResult();
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
+ * .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBuildDiffTreeRemoveComposite() throws Exception {
+ LOG.debug("testBuildDiffTreeRemoveComposite");
+ Document networkShadow = NodeUtils.buildShadowDomTree(network);
+ SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
+ "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
+
+ @SuppressWarnings("unchecked")
+ MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
+ .getMutableEquivalent(needle);
+
+ nodeModificationBuilder.removeNode(mutableNeedle.getParent().asMutable());
+ dumpResult();
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
+ * .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBuildDiffTreeRemoveSimple() throws Exception {
+ LOG.debug("testBuildDiffTreeRemoveSimple");
+ Document networkShadow = NodeUtils.buildShadowDomTree(network);
+ SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
+ "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
+
+ @SuppressWarnings("unchecked")
+ MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
+ .getMutableEquivalent(needle);
+
+ nodeModificationBuilder.removeNode(mutableNeedle);
+ dumpResult();
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
+ * .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBuildDiffTreeReplaceComposite() throws Exception {
+ LOG.debug("testBuildDiffTreeReplaceComposite");
+ Document networkShadow = NodeUtils.buildShadowDomTree(network);
+ SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
+ "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
+
+ @SuppressWarnings("unchecked")
+ MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
+ .getMutableEquivalent(needle);
+
+ mutableNeedle.setValue("tpId_18x");
+ nodeModificationBuilder.replaceNode(mutableNeedle.getParent().asMutable());
+ dumpResult();
+ }
+
+ /**
+ * Test method for
+ * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
+ * .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBuildDiffTreeReplaceSimple() throws Exception {
+ LOG.debug("testBuildDiffTreeReplaceSimple");
+ Document networkShadow = NodeUtils.buildShadowDomTree(network);
+ SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
+ "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
+
+ @SuppressWarnings("unchecked")
+ MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
+ .getMutableEquivalent(needle);
+
+ mutableNeedle.setValue("tpId_18x");
+ nodeModificationBuilder.replaceNode(mutableNeedle);
+ dumpResult();
+ }
+
+}
import com.google.common.collect.Maps;
final class Util {
+
+ /**
+ * It isn't desirable to create instances of this class
+ */
+ private Util() {
+ }
+
static final String YANG_SUFFIX = "yang";
+ private static final int CACHE_SIZE = 10;
// Cache for listed directories and found yang files. Typically yang files
// are utilized twice. First: code is generated during generate-sources
// phase Second: yang files are copied as resources during
// generate-resources phase. This cache ensures that yang files are listed
// only once.
- private static Map<File, Collection<File>> cache = Maps.newHashMapWithExpectedSize(10);
+ private static Map<File, Collection<File>> cache = Maps.newHashMapWithExpectedSize(CACHE_SIZE);
/**
* List files recursively and return as array of String paths. Use cache of
* size 1.
*/
static Collection<File> listFiles(File root) throws FileNotFoundException {
- if (cache.get(root) != null)
+ if (cache.get(root) != null) {
return cache.get(root);
+ }
if (!root.exists()) {
throw new FileNotFoundException(root.toString());
}
}
if (excluded) {
- if(log != null) {
+ if (log != null) {
log.info(Util.message("%s file excluded %s", YangToSourcesProcessor.LOG_PREFIX,
Util.YANG_SUFFIX.toUpperCase(), f));
}
private static Class<?> resolveClass(String codeGeneratorClass, Class<?> baseType) throws ClassNotFoundException {
Class<?> clazz = Class.forName(codeGeneratorClass);
- if (!isImplemented(baseType, clazz))
+ if (!isImplemented(baseType, clazz)) {
throw new IllegalArgumentException("Code generator " + clazz + " has to implement " + baseType);
+ }
return clazz;
}
private static boolean isImplemented(Class<?> expectedIface, Class<?> byClazz) {
for (Class<?> iface : byClazz.getInterfaces()) {
- if (iface.equals(expectedIface))
+ if (iface.equals(expectedIface)) {
return true;
+ }
}
return false;
}
return Preconditions.checkNotNull(obj, "Parameter " + paramName + " is null");
}
- final static class YangsInZipsResult implements Closeable {
- final List<InputStream> yangStreams;
+ static final class YangsInZipsResult implements Closeable {
+ private final List<InputStream> yangStreams;
private final List<Closeable> zipInputStreams;
private YangsInZipsResult(List<InputStream> yangStreams, List<Closeable> zipInputStreams) {
is.close();
}
}
+
+ public List<InputStream> getYangStreams() {
+ return this.yangStreams;
+ }
}
static YangsInZipsResult findYangFilesInDependenciesAsStream(Log log, MavenProject project)
ZipEntry entry = entries.nextElement();
String entryName = entry.getName();
- if (entryName.startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR)) {
- if (entry.isDirectory() == false && entryName.endsWith(".yang")) {
- foundFilesForReporting.add(entryName);
- // This will be closed after all strams are
- // parsed.
- InputStream entryStream = zip.getInputStream(entry);
- yangsFromDependencies.add(entryStream);
- }
+ if (entryName.startsWith(YangToSourcesProcessor.META_INF_YANG_STRING_JAR)
+ && !entry.isDirectory() && entryName.endsWith(".yang")) {
+ foundFilesForReporting.add(entryName);
+ // This will be closed after all strams are
+ // parsed.
+ InputStream entryStream = zip.getInputStream(entry);
+ yangsFromDependencies.add(entryStream);
}
}
}
return new YangsInZipsResult(yangsFromDependencies, zips);
}
- final static class ContextHolder {
+ static final class ContextHolder {
private final SchemaContext context;
private final Set<Module> yangModules;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
import org.slf4j.impl.StaticLoggerBinder;
* with .yang suffix).
*/
@Parameter(required = false)
- private String yangFilesRootDir; // defaults to ${basedir}/src/main/yang
+ // defaults to ${basedir}/src/main/yang
+ private String yangFilesRootDir;
@Parameter(required = false)
private String[] excludeFiles;
@Parameter(property = "project", required = true, readonly = true)
- protected MavenProject project;
+ private MavenProject project;
@Parameter(property = "inspectDependencies", required = true, readonly = true)
private boolean inspectDependencies;
}
+ public void setProject(MavenProject project) {
+ this.project = project;
+ }
+
@VisibleForTesting
YangToSourcesMojo(YangToSourcesProcessor processor) {
this.yangToSourcesProcessor = processor;
MavenProject project, boolean inspectDependencies, YangProvider yangProvider) {
this.log = Util.checkNotNull(log, "log");
this.yangFilesRootDir = Util.checkNotNull(yangFilesRootDir, "yangFilesRootDir");
- this.excludedFiles = excludedFiles;
+ this.excludedFiles = new File[excludedFiles.length];
+ int i = 0;
+ for (File file : excludedFiles) {
+ this.excludedFiles[i++] = new File(file.getPath());
+ }
this.codeGenerators = Collections.unmodifiableList(Util.checkNotNull(codeGenerators, "codeGenerators"));
this.project = Util.checkNotNull(project, "project");
this.inspectDependencies = inspectDependencies;
public void execute() throws MojoExecutionException, MojoFailureException {
ContextHolder context = processYang();
generateSources(context);
- yangProvider.addYangsToMETA_INF(log, project, yangFilesRootDir, excludedFiles);
+ yangProvider.addYangsToMetaInf(log, project, yangFilesRootDir, excludedFiles);
}
private ContextHolder processYang() throws MojoExecutionException {
YangsInZipsResult dependentYangResult = Util.findYangFilesInDependenciesAsStream(log, project);
Closeable dependentYangResult1 = dependentYangResult;
closeables.add(dependentYangResult1);
- all.addAll(dependentYangResult.yangStreams);
+ all.addAll(dependentYangResult.getYangStreams());
}
allYangModules = parser.parseYangModelsFromStreamsMapped(all);
static class YangProvider {
- private static final String yangResourceDir = "target" + File.separator + "yang";
+ private static final String YANG_RESOURCE_DIR = "target" + File.separator + "yang";
- void addYangsToMETA_INF(Log log, MavenProject project, File yangFilesRootDir, File[] excludedFiles)
+ void addYangsToMetaInf(Log log, MavenProject project, File yangFilesRootDir, File[] excludedFiles)
throws MojoFailureException {
- File targetYangDir = new File(project.getBasedir(), yangResourceDir);
+ File targetYangDir = new File(project.getBasedir(), YANG_RESOURCE_DIR);
try {
Collection<File> files = Util.listFiles(yangFilesRootDir, excludedFiles, null);
private static void setResource(File targetYangDir, String targetPath, MavenProject project) {
Resource res = new Resource();
res.setDirectory(targetYangDir.getPath());
- if (targetPath != null)
+ if (targetPath != null) {
res.setTargetPath(targetPath);
+ }
project.addResource(res);
}
}
yang = new File(getClass().getResource("/yang/mock.yang").getFile()).getParent();
outDir = new File("/outputDir");
YangProvider mock = mock(YangProvider.class);
- doNothing().when(mock).addYangsToMETA_INF(any(Log.class), any(MavenProject.class), any(File.class),
+ doNothing().when(mock).addYangsToMetaInf(any(Log.class), any(MavenProject.class), any(File.class),
any(File[].class));
YangToSourcesProcessor processor = new YangToSourcesProcessor(mock(Log.class), new File(yang), new File[] {},
mock);
mojo = new YangToSourcesMojo(processor);
doReturn(new File("")).when(project).getBasedir();
- mojo.project = project;
+ mojo.setProject(project);
}
@Test
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.model.api;\r
-\r
-import java.util.List;\r
-\r
-/**\r
- * AugmentationSchema represents augment definition. The "augment" statement\r
- * allows a module or submodule to add to the schema tree defined in an external\r
- * module, or the current module and its submodules, and to add to the nodes\r
- * from a grouping in a "uses" statement.\r
- */\r
-public interface AugmentationSchema extends DataNodeContainer {\r
-\r
- /**\r
- * @return when statement\r
- */\r
- RevisionAwareXPath getWhenCondition();\r
-\r
- /**\r
- * @return textual description of this augment.\r
- */\r
- String getDescription();\r
-\r
- /**\r
- * @return textual cross-reference to an external document that provides\r
- * additional information relevant to this node.\r
- */\r
- String getReference();\r
-\r
- /**\r
- * @return actual status of this node.\r
- */\r
- Status getStatus();\r
-\r
- /**\r
- * @return SchemaPath that identifies a node in the schema tree. This node\r
- * is called the augment's target node. The target node MUST be\r
- * either a container, list, choice, case, input, output, or\r
- * notification node. It is augmented with the nodes defined as\r
- * child nodes of this AugmentationSchema.\r
- */\r
- SchemaPath getTargetPath();\r
-\r
- /**\r
- * @return collection of all unknown nodes defined in this augmentation\r
- */\r
- public List<UnknownSchemaNode> getUnknownSchemaNodes();\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.api;
+
+import java.util.List;
+
+/**
+ * AugmentationSchema represents augment definition. The "augment" statement
+ * allows a module or submodule to add to the schema tree defined in an external
+ * module, or the current module and its submodules, and to add to the nodes
+ * from a grouping in a "uses" statement.
+ */
+public interface AugmentationSchema extends DataNodeContainer {
+
+ /**
+ * @return when statement
+ */
+ RevisionAwareXPath getWhenCondition();
+
+ /**
+ * @return textual description of this augment.
+ */
+ String getDescription();
+
+ /**
+ * @return textual cross-reference to an external document that provides
+ * additional information relevant to this node.
+ */
+ String getReference();
+
+ /**
+ * @return actual status of this node.
+ */
+ Status getStatus();
+
+ /**
+ * @return SchemaPath that identifies a node in the schema tree. This node
+ * is called the augment's target node. The target node MUST be
+ * either a container, list, choice, case, input, output, or
+ * notification node. It is augmented with the nodes defined as
+ * child nodes of this AugmentationSchema.
+ */
+ SchemaPath getTargetPath();
+
+ /**
+ * @return collection of all unknown nodes defined in this augmentation
+ */
+ List<UnknownSchemaNode> getUnknownSchemaNodes();
+
+}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.model.api;\r
-\r
-import java.util.List;\r
-\r
-/**\r
- * Interface describing YANG 'deviation' statement.\r
- * <p>\r
- * The 'deviation' statement defines a hierarchy of a module that the device\r
- * does not implement faithfully. Deviations define the way a device deviate\r
- * from a standard.\r
- * </p>\r
- */\r
-public interface Deviation {\r
-\r
- /**\r
- * Enum describing YANG deviation 'deviate' statement. It defines how the\r
- * device's implementation of the target node deviates from its original\r
- * definition.\r
- */\r
- enum Deviate {\r
- NOT_SUPPORTED, ADD, REPLACE, DELETE\r
- }\r
-\r
- /**\r
- * @return SchemaPath that identifies the node in the schema tree where a\r
- * deviation from the module occurs.\r
- */\r
- SchemaPath getTargetPath();\r
-\r
- /**\r
- * @return deviate statement of this deviation\r
- */\r
- Deviate getDeviate();\r
-\r
- /**\r
- * @return textual cross-reference to an external document that provides\r
- * additional information relevant to this node.\r
- */\r
- String getReference();\r
-\r
- /**\r
- * @return collection of all unknown nodes defined under this schema node.\r
- */\r
- public List<UnknownSchemaNode> getUnknownSchemaNodes();\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.api;
+
+import java.util.List;
+
+/**
+ * Interface describing YANG 'deviation' statement.
+ * <p>
+ * The 'deviation' statement defines a hierarchy of a module that the device
+ * does not implement faithfully. Deviations define the way a device deviate
+ * from a standard.
+ * </p>
+ */
+public interface Deviation {
+
+ /**
+ * Enum describing YANG deviation 'deviate' statement. It defines how the
+ * device's implementation of the target node deviates from its original
+ * definition.
+ */
+ enum Deviate {
+ NOT_SUPPORTED, ADD, REPLACE, DELETE
+ }
+
+ /**
+ * @return SchemaPath that identifies the node in the schema tree where a
+ * deviation from the module occurs.
+ */
+ SchemaPath getTargetPath();
+
+ /**
+ * @return deviate statement of this deviation
+ */
+ Deviate getDeviate();
+
+ /**
+ * @return textual cross-reference to an external document that provides
+ * additional information relevant to this node.
+ */
+ String getReference();
+
+ /**
+ * @return collection of all unknown nodes defined under this schema node.
+ */
+ List<UnknownSchemaNode> getUnknownSchemaNodes();
+
+}
* Keyword. If no argument statement is present the method will
* return <code>null</code>
*/
- public String getArgument();
+ String getArgument();
/**
* This statement indicates if the argument is mapped to an XML element in
* YIN or returns <code>false</code> if the argument is mapped to an
* XML attribute.
*/
- public boolean isYinElement();
+ boolean isYinElement();
}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.model.api;\r
-\r
-import java.util.List;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-\r
-/**\r
- * Interface describing YANG 'list' statement.\r
- * <p>\r
- * The 'list' statement is used to define an interior data node in the schema\r
- * tree. A list entry is uniquely identified by the values of the list's keys,\r
- * if defined.\r
- * </p>\r
- */\r
-public interface ListSchemaNode extends DataNodeContainer, AugmentationTarget,\r
- DataSchemaNode {\r
-\r
- /**\r
- * @return List of QNames of leaf identifiers of this list\r
- */\r
- public List<QName> getKeyDefinition();\r
-\r
- /**\r
- * YANG 'ordered-by' statement. It defines whether the order of entries\r
- * within a list are determined by the user or the system. If not present,\r
- * default is false.\r
- *\r
- * @return true if ordered-by argument is "user", false otherwise\r
- */\r
- boolean isUserOrdered();\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.api;
+
+import java.util.List;
+
+import org.opendaylight.yangtools.yang.common.QName;
+
+/**
+ * Interface describing YANG 'list' statement.
+ * <p>
+ * The 'list' statement is used to define an interior data node in the schema
+ * tree. A list entry is uniquely identified by the values of the list's keys,
+ * if defined.
+ * </p>
+ */
+public interface ListSchemaNode extends DataNodeContainer, AugmentationTarget, DataSchemaNode {
+
+ /**
+ * @return List of QNames of leaf identifiers of this list
+ */
+ List<QName> getKeyDefinition();
+
+ /**
+ * YANG 'ordered-by' statement. It defines whether the order of entries
+ * within a list are determined by the user or the system. If not present,
+ * default is false.
+ *
+ * @return true if ordered-by argument is "user", false otherwise
+ */
+ boolean isUserOrdered();
+
+}
* @return <code>true</code> if the XPapth starts in root of Yang model,
* otherwise returns <code>false</cdoe>
*/
- public boolean isAbsolute();
+ boolean isAbsolute();
/**
* Returns the XPath formatted string as is defined in model. <br>
*
* @return the XPath formatted string as is defined in model.
*/
- public String toString();
+ String toString();
}
*
* @return QName with the name of the schema node
*/
- public QName getQName();
+ QName getQName();
/**
* Returns the schema path of the instance of the type
*
* @return schema path of the schema node
*/
- public SchemaPath getPath();
+ SchemaPath getPath();
/**
* Returns description of the instance of the type <code>SchemaNode</code>
* @return string with textual description the node which represents the
* argument of the YANG <code>description</code> substatement
*/
- public String getDescription();
+ String getDescription();
/**
* Returns reference of the instance of the type <code>SchemaNode</code>
* represents the argument of the YANG <code>reference</code>
* substatement
*/
- public String getReference();
+ String getReference();
/**
* Returns status of the instance of the type <code>SchemaNode</code>
* @return status of this node which represents the argument of the YANG
* <code>status</code> substatement
*/
- public Status getStatus();
+ Status getStatus();
/**
*
*
* @return list of unknown schema nodes defined under this schema node.
*/
- public List<UnknownSchemaNode> getUnknownSchemaNodes();
+ List<UnknownSchemaNode> getUnknownSchemaNodes();
}
*
*/
public class SchemaPath {
+ private final int hashBooleanTrue = 1231;
+ private final int hashBooleanFalse = 1237;
/**
* List of QName instances which represents complete path to the node.
*/
- final List<QName> path;
+ private final List<QName> path;
/**
* Boolean value which represents type of schema path (relative or
* absolute).
*/
- final boolean absolute;
+ private final boolean absolute;
/**
* Constructs new instance of this class with the concrete path.
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + (absolute ? 1231 : 1237);
+ result = prime * result + (absolute ? hashBooleanTrue : hashBooleanFalse);
result = prime * result + ((path == null) ? 0 : path.hashCode());
return result;
}
*
* @return name of each assigned name of an enumeration type.
*/
- public String getName();
+ String getName();
/**
* The "value" statement, which is optional, is used to associate an
*
* @return integer value assigned to enumeration
*/
- public Integer getValue();
+ Integer getValue();
}
}
*
* @return QName of the YANG identity
*/
- public QName getIdentityName();
+ QName getIdentityName();
}
*
* @return instance of type <code>RevisionAwareXPath</code>
*/
- public RevisionAwareXPath getPathStatement();
+ RevisionAwareXPath getPathStatement();
/**
* Returns true|false which represents argument of
* @return boolean value which is true if the <code>require-instance</code>
* statement is true and vice versa
*/
- public boolean requireInstance();
+ boolean requireInstance();
}
--- /dev/null
+/src/main/xtend-gen
\ No newline at end of file
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
-\r
- <parent>\r
- <groupId>org.opendaylight.yangtools</groupId>\r
- <artifactId>yang</artifactId>\r
- <version>0.5.7-SNAPSHOT</version>\r
- </parent>\r
-\r
- <modelVersion>4.0.0</modelVersion>\r
- <artifactId>yang-model-util</artifactId>\r
- <name>${project.artifactId}</name>\r
- <description>${project.artifactId}</description>\r
-\r
-\r
- <build>\r
- <plugins>\r
- <plugin>\r
- <groupId>org.eclipse.xtend</groupId>\r
- <artifactId>xtend-maven-plugin</artifactId>\r
- <version>2.4.2</version>\r
- <executions>\r
- <execution>\r
- <goals>\r
- <goal>compile</goal>\r
- </goals>\r
- <configuration>\r
- <outputDirectory>${basedir}/src/main/xtend-gen</outputDirectory>\r
- </configuration>\r
- </execution>\r
- </executions>\r
- </plugin>\r
- <plugin>\r
- <artifactId>maven-clean-plugin</artifactId>\r
- <version>2.4.1</version>\r
- <configuration>\r
- <filesets>\r
- <fileset>\r
- <directory>${basedir}/src/main/xtend-gen</directory>\r
- <includes>\r
- <include>**</include>\r
- </includes>\r
- </fileset>\r
- </filesets>\r
- </configuration>\r
- </plugin>\r
- </plugins>\r
- </build>\r
-\r
- <dependencies>\r
- <dependency>\r
- <groupId>${project.groupId}</groupId>\r
- <artifactId>yang-model-api</artifactId>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.eclipse.xtend</groupId>\r
- <artifactId>org.eclipse.xtend.lib</artifactId>\r
- <version>2.4.2</version>\r
- </dependency>\r
- </dependencies>\r
-</project>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang</artifactId>
+ <version>0.5.7-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>yang-model-util</artifactId>
+ <name>${project.artifactId}</name>
+ <description>${project.artifactId}</description>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.xtend</groupId>
+ <artifactId>xtend-maven-plugin</artifactId>
+ <version>2.4.2</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/src/main/xtend-gen</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>2.4.1</version>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>${basedir}/src/main/xtend-gen</directory>
+ <includes>
+ <include>**</include>
+ </includes>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>yang-model-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.xtend</groupId>
+ <artifactId>org.eclipse.xtend.lib</artifactId>
+ <version>2.4.2</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
* interface which represents SIGNED Integer values defined in Yang language. <br>
* The integer built-in types in Yang are int8, int16, int32, int64. They
* represent signed integers of different sizes:
- *
+ *
* <ul>
* <li>int8 - represents integer values between -128 and 127, inclusively.</li>
* <li>int16 - represents integer values between -32768 and 32767, inclusively.</li>
* <li>int64 - represents integer values between -9223372036854775808 and
* 9223372036854775807, inclusively.</li>
* </ul>
- *
+ *
*/
public abstract class AbstractSignedInteger implements IntegerTypeDefinition {
private final QName name;
private final SchemaPath path;
private final String description;
- private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2";
private final String units;
private final List<RangeConstraint> rangeStatements;
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
@Override
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
- result = prime * result + ((reference == null) ? 0 : reference.hashCode());
result = prime * result + ((units == null) ? 0 : units.hashCode());
return result;
}
} else if (!rangeStatements.equals(other.rangeStatements)) {
return false;
}
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
- return false;
- }
if (units == null) {
if (other.units != null) {
return false;
builder.append(", description=");
builder.append(description);
builder.append(", reference=");
- builder.append(reference);
+ builder.append(REFERENCE);
builder.append(", units=");
builder.append(units);
builder.append(", rangeStatements=");
* interface which represents UNSIGNED Integer values defined in Yang language. <br>
* The integer built-in types in Yang are uint8, uint16, uint32, and uint64.
* They represent unsigned integers of different sizes:
- *
+ *
* <ul>
* <li>uint8 - represents integer values between 0 and 255, inclusively.</li>
* <li>uint16 - represents integer values between 0 and 65535, inclusively.</li>
* <li>uint64 - represents integer values between 0 and 18446744073709551615,
* inclusively.</li>
* </ul>
- *
+ *
*/
public abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition {
private static final long MIN_VALUE = 0;
private final QName name;
private final SchemaPath path;
private final String description;
- private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2";
private final String units;
private final List<RangeConstraint> rangeStatements;
/**
- *
+ *
* @param name
* @param description
* @param maxRange
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
@Override
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
- result = prime * result + ((reference == null) ? 0 : reference.hashCode());
result = prime * result + ((units == null) ? 0 : units.hashCode());
return result;
}
} else if (!rangeStatements.equals(other.rangeStatements)) {
return false;
}
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
- return false;
- }
if (units == null) {
if (other.units != null) {
return false;
builder.append(", description=");
builder.append(description);
builder.append(", reference=");
- builder.append(reference);
+ builder.append(REFERENCE);
builder.append(", units=");
builder.append(units);
builder.append(", rangeStatements=");
private BaseConstraints() {
}
- public static LengthConstraint lengthConstraint(final Number min,
- final Number max, final String description, final String reference) {
+ public static LengthConstraint lengthConstraint(final Number min, final Number max, final String description,
+ final String reference) {
return new LengthConstraintImpl(min, max, description, reference);
}
- public static RangeConstraint rangeConstraint(final Number min,
- final Number max, final String description, final String reference) {
+ public static RangeConstraint rangeConstraint(final Number min, final Number max, final String description,
+ final String reference) {
return new RangeConstraintImpl(min, max, description, reference);
}
- public static PatternConstraint patternConstraint(final String pattern,
- final String description, final String reference) {
+ public static PatternConstraint patternConstraint(final String pattern, final String description,
+ final String reference) {
return new PatternConstraintImpl(pattern, description, reference);
}
private final String errorAppTag;
private final String errorMessage;
- public LengthConstraintImpl(Number min, Number max,
- final String description, final String reference) {
+ public LengthConstraintImpl(Number min, Number max, final String description, final String reference) {
super();
this.min = min;
this.max = max;
this.reference = reference;
this.errorAppTag = "length-out-of-specified-bounds";
- this.errorMessage = "The argument is out of bounds <" + min + ", "
- + max + ">";
+ this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((description == null) ? 0 : description.hashCode());
- result = prime * result
- + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
- result = prime * result
- + ((errorMessage == null) ? 0 : errorMessage.hashCode());
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
+ result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode());
result = prime * result + ((max == null) ? 0 : max.hashCode());
result = prime * result + ((min == null) ? 0 : min.hashCode());
- result = prime * result
- + ((reference == null) ? 0 : reference.hashCode());
+ result = prime * result + ((reference == null) ? 0 : reference.hashCode());
return result;
}
}
}
- private final static class RangeConstraintImpl implements RangeConstraint {
+ private static final class RangeConstraintImpl implements RangeConstraint {
private final Number min;
private final Number max;
private final String errorAppTag;
private final String errorMessage;
- public RangeConstraintImpl(Number min, Number max, String description,
- String reference) {
+ public RangeConstraintImpl(Number min, Number max, String description, String reference) {
super();
this.min = min;
this.max = max;
this.reference = reference;
this.errorAppTag = "range-out-of-specified-bounds";
- this.errorMessage = "The argument is out of bounds <" + min + ", "
- + max + ">";
+ this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((description == null) ? 0 : description.hashCode());
- result = prime * result
- + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
- result = prime * result
- + ((errorMessage == null) ? 0 : errorMessage.hashCode());
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
+ result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode());
result = prime * result + ((max == null) ? 0 : max.hashCode());
result = prime * result + ((min == null) ? 0 : min.hashCode());
- result = prime * result
- + ((reference == null) ? 0 : reference.hashCode());
+ result = prime * result + ((reference == null) ? 0 : reference.hashCode());
return result;
}
}
}
- private final static class PatternConstraintImpl implements
- PatternConstraint {
+ private static final class PatternConstraintImpl implements PatternConstraint {
private final String regex;
private final String description;
private final String errorAppTag;
private final String errorMessage;
- public PatternConstraintImpl(final String regex,
- final String description, final String reference) {
+ public PatternConstraintImpl(final String regex, final String description, final String reference) {
super();
this.regex = regex;
this.description = description;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((description == null) ? 0 : description.hashCode());
- result = prime * result
- + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
- result = prime * result
- + ((errorMessage == null) ? 0 : errorMessage.hashCode());
- result = prime * result
- + ((reference == null) ? 0 : reference.hashCode());
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
+ result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode());
+ result = prime * result + ((reference == null) ? 0 : reference.hashCode());
result = prime * result + ((regex == null) ? 0 : regex.hashCode());
return result;
}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.model.util;\r
-\r
-import java.net.URI;\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
-\r
-public final class BaseTypes {\r
-\r
- private BaseTypes() {}\r
-\r
- public static final URI BaseTypesNamespace = URI\r
- .create("urn:ietf:params:xml:ns:yang:1");\r
-\r
- /**\r
- * Construct QName for Built-in base Yang type. The namespace for\r
- * built-in base yang types is defined as: urn:ietf:params:xml:ns:yang:1\r
- *\r
- * @param typeName yang type name\r
- * @return built-in base yang type QName.\r
- */\r
- public static final QName constructQName(final String typeName) {\r
- return new QName(BaseTypesNamespace, typeName);\r
- }\r
-\r
- /**\r
- * Creates Schema Path from Qname.\r
- *\r
- * @param typeName yang type QName\r
- * @return Schema Path from Qname.\r
- */\r
- public static final SchemaPath schemaPath(final QName typeName) {\r
- List<QName> pathList = Collections.singletonList(typeName);\r
- return new SchemaPath(pathList, true);\r
- }\r
-\r
- /**\r
- * Creates Schema Path from List of partial paths defined as Strings, module Namespace and\r
- * module latest Revision Date.\r
- *\r
- * @param actualPath List of partial paths\r
- * @param namespace Module Namespace\r
- * @param revision Revision Date\r
- * @return Schema Path\r
- */\r
- public static final SchemaPath schemaPath(final List<String> actualPath, final URI namespace, final Date revision) {\r
- if (actualPath == null) {\r
- throw new IllegalArgumentException("The actual path List MUST be specified.");\r
- }\r
- final List<QName> pathList = new ArrayList<QName>();\r
- for (final String path : actualPath) {\r
- final QName qname = new QName(namespace, revision, path);\r
- if (qname != null) {\r
- pathList.add(qname);\r
- }\r
- }\r
- return new SchemaPath(pathList, true);\r
- }\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+public final class BaseTypes {
+
+ private BaseTypes() {
+ }
+
+ public static final URI BASE_TYPES_NAMESPACE = URI.create("urn:ietf:params:xml:ns:yang:1");
+
+ /**
+ * Construct QName for Built-in base Yang type. The namespace for built-in
+ * base yang types is defined as: urn:ietf:params:xml:ns:yang:1
+ *
+ * @param typeName
+ * yang type name
+ * @return built-in base yang type QName.
+ */
+ public static QName constructQName(final String typeName) {
+ return new QName(BASE_TYPES_NAMESPACE, typeName);
+ }
+
+ /**
+ * Creates Schema Path from Qname.
+ *
+ * @param typeName
+ * yang type QName
+ * @return Schema Path from Qname.
+ */
+ public static SchemaPath schemaPath(final QName typeName) {
+ List<QName> pathList = Collections.singletonList(typeName);
+ return new SchemaPath(pathList, true);
+ }
+
+ /**
+ * Creates Schema Path from List of partial paths defined as Strings, module
+ * Namespace and module latest Revision Date.
+ *
+ * @param actualPath
+ * List of partial paths
+ * @param namespace
+ * Module Namespace
+ * @param revision
+ * Revision Date
+ * @return Schema Path
+ */
+ public static SchemaPath schemaPath(final List<String> actualPath, final URI namespace, final Date revision) {
+ if (actualPath == null) {
+ throw new IllegalArgumentException("The actual path List MUST be specified.");
+ }
+ final List<QName> pathList = new ArrayList<QName>();
+ for (final String path : actualPath) {
+ final QName qname = new QName(namespace, revision, path);
+ if (qname != null) {
+ pathList.add(qname);
+ }
+ }
+ return new SchemaPath(pathList, true);
+ }
+}
/**
* The <code>default</code> implementation of Binary Type Definition interface.
- *
+ *
* @see BinaryTypeDefinition
*/
public final class BinaryType implements BinaryTypeDefinition {
private static final BinaryType INSTANCE = new BinaryType();
private final QName name = BaseTypes.constructQName("binary");
private final SchemaPath path = new SchemaPath(Collections.singletonList(name), true);
- private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
- private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8";
+ private static final String DESCRIPTION = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.8";
private final List<Byte> bytes;
private final List<LengthConstraint> lengthConstraints;
- private final String units = "";
+ private static final String UNITS = "";
private BinaryType() {
final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
*/
@Override
public String getUnits() {
- return units;
+ return UNITS;
}
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
* ()
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
*/
@Override
public String getDescription() {
- return description;
+ return DESCRIPTION;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
*/
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.base.type.api.BinaryTypeDefinition
* #getLengthConstraint ()
final int prime = 31;
int result = 1;
result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
- result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
- result = prime * result + ((reference == null) ? 0 : reference.hashCode());
- result = prime * result + ((units == null) ? 0 : units.hashCode());
return result;
}
} else if (!bytes.equals(other.bytes)) {
return false;
}
- if (description == null) {
- if (other.description != null) {
- return false;
- }
- } else if (!description.equals(other.description)) {
- return false;
- }
if (lengthConstraints == null) {
if (other.lengthConstraints != null) {
return false;
} else if (!path.equals(other.path)) {
return false;
}
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
- return false;
- }
- if (units == null) {
- if (other.units != null) {
- return false;
- }
- } else if (!units.equals(other.units)) {
- return false;
- }
return true;
}
builder.append(", path=");
builder.append(path);
builder.append(", description=");
- builder.append(description);
+ builder.append(DESCRIPTION);
builder.append(", reference=");
- builder.append(reference);
+ builder.append(REFERENCE);
builder.append(", bytes=");
builder.append(bytes);
builder.append(", lengthConstraints=");
builder.append(lengthConstraints);
builder.append(", units=");
- builder.append(units);
+ builder.append(UNITS);
builder.append("]");
return builder.toString();
}
/**
* The <code>default</code> implementation of Bits Type Definition interface.
- *
+ *
* @see BitsTypeDefinition
*/
public final class BitsType implements BitsTypeDefinition {
+ "That is, a bits value is a set of flags identified by small integer position "
+ "numbers starting at 0. Each bit number has an assigned name.";
- private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
private final BitsTypeDefinition baseType;
private final List<Bit> bits;
- private final String units = "";
+ private static final String UNITS = "";
/**
* Default constructor. <br>
* Instantiates Bits type as empty bits list.
- *
+ *
* @param path
*/
public BitsType(final SchemaPath path) {
/**
* Constructor with explicit definition of bits assigned to BitsType.
- *
+ *
* @param path
* @param bits
*/
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
*/
@Override
public String getUnits() {
- return units;
+ return UNITS;
}
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
* ()
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
*/
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
*/
@Override
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
- result = prime * result + ((reference == null) ? 0 : reference.hashCode());
- result = prime * result + ((units == null) ? 0 : units.hashCode());
return result;
}
} else if (!path.equals(other.path)) {
return false;
}
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
- return false;
- }
- if (units == null) {
- if (other.units != null) {
- return false;
- }
- } else if (!units.equals(other.units)) {
- return false;
- }
return true;
}
builder.append(", description=");
builder.append(description);
builder.append(", reference=");
- builder.append(reference);
+ builder.append(REFERENCE);
builder.append(", bits=");
builder.append(bits);
builder.append(", units=");
- builder.append(units);
+ builder.append(UNITS);
builder.append("]");
return builder.toString();
}
/**
* The <code>default</code> implementation of Boolean Type Definition interface.
- *
+ *
* @see BooleanTypeDefinition
*/
public final class BooleanType implements BooleanTypeDefinition {
private static final BooleanType INSTANCE = new BooleanType();
- private static final QName name = BaseTypes.constructQName("boolean");
- private static final SchemaPath path = new SchemaPath(Collections.singletonList(name), true);
- private static final String description = "The boolean built-in type represents a boolean value.";
- private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.5";
- private final String units = "";
+ private static final QName NAME = BaseTypes.constructQName("boolean");
+ private static final SchemaPath PATH = new SchemaPath(Collections.singletonList(NAME), true);
+ private static final String DESCRIPTION = "The boolean built-in type represents a boolean value.";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.5";
+ private static final String UNITS = "";
/**
* Default constructor with default value set to "false".
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
*/
@Override
public String getUnits() {
- return units;
+ return UNITS;
}
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
* ()
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
*/
@Override
public QName getQName() {
- return name;
+ return NAME;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
*/
@Override
public SchemaPath getPath() {
- return path;
+ return PATH;
}
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
*/
@Override
public String getDescription() {
- return description;
+ return DESCRIPTION;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
*/
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("BooleanType [name=");
- builder.append(name);
+ builder.append(NAME);
builder.append(", path=");
- builder.append(path);
+ builder.append(PATH);
builder.append("]");
return builder.toString();
}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.model.util;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.yangtools.yang.model.api.*;\r
-\r
-public class DataNodeIterator implements Iterator<DataSchemaNode> {\r
-\r
- private final DataNodeContainer container;\r
- private final List<ListSchemaNode> allLists;\r
- private final List<ContainerSchemaNode> allContainers;\r
- private final List<ChoiceNode> allChoices;\r
- private final List<DataSchemaNode> allChilds;\r
- \r
- public DataNodeIterator(final DataNodeContainer container) {\r
- if (container == null) {\r
- throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");\r
- }\r
-\r
- this.allContainers = new ArrayList<>();\r
- this.allLists = new ArrayList<>();\r
- this.allChilds = new ArrayList<>();\r
- this.allChoices = new ArrayList<>();\r
-\r
- this.container = container;\r
- traverse(this.container);\r
- }\r
-\r
- public List<ContainerSchemaNode> allContainers() {\r
- return allContainers;\r
- }\r
-\r
- public List<ListSchemaNode> allLists() {\r
- return allLists;\r
- }\r
-\r
- public List<ChoiceNode> allChoices() {\r
- return allChoices;\r
- }\r
-\r
- private void traverse(final DataNodeContainer dataNode) {\r
- if (dataNode == null) {\r
- return;\r
- }\r
-\r
- final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();\r
- if (childNodes != null) {\r
- for (DataSchemaNode childNode : childNodes) {\r
- if (childNode.isAugmenting()) {\r
- continue;\r
- }\r
- allChilds.add(childNode);\r
- if (childNode instanceof ContainerSchemaNode) {\r
- final ContainerSchemaNode container = (ContainerSchemaNode) childNode;\r
- allContainers.add(container);\r
- traverse(container);\r
- } else if (childNode instanceof ListSchemaNode) {\r
- final ListSchemaNode list = (ListSchemaNode) childNode;\r
- allLists.add(list);\r
- traverse(list);\r
- } else if (childNode instanceof ChoiceNode) {\r
- final ChoiceNode choiceNode = (ChoiceNode) childNode;\r
- allChoices.add(choiceNode);\r
- final Set<ChoiceCaseNode> cases = choiceNode.getCases();\r
- if (cases != null) {\r
- for (final ChoiceCaseNode caseNode : cases) {\r
- traverse(caseNode);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- if(dataNode instanceof Module) {\r
- traverseModule((Module)dataNode);\r
- }\r
- \r
- final Set<GroupingDefinition> groupings = dataNode.getGroupings();\r
- if (groupings != null) {\r
- for (GroupingDefinition grouping : groupings) {\r
- traverse(grouping);\r
- }\r
- }\r
- }\r
- \r
-\r
- private void traverseModule(Module module) {\r
- final Set<NotificationDefinition> notifications = module.getNotifications();\r
- for (NotificationDefinition notificationDefinition : notifications) {\r
- traverse(notificationDefinition);\r
- }\r
- final Set<RpcDefinition> rpcs = module.getRpcs();\r
- for (RpcDefinition rpcDefinition : rpcs) {\r
- ContainerSchemaNode input = rpcDefinition.getInput();\r
- if(input != null) {\r
- traverse(input);\r
- }\r
- ContainerSchemaNode output = rpcDefinition.getInput();\r
- if(input != null) {\r
- traverse(output);\r
- }\r
- }\r
- }\r
- \r
- @Override\r
- public boolean hasNext() {\r
- if (container.getChildNodes() != null) {\r
- final Set<DataSchemaNode> childNodes = container.getChildNodes();\r
-\r
- if ((childNodes != null) && !childNodes.isEmpty()) {\r
- return childNodes.iterator().hasNext();\r
- }\r
- }\r
- return false;\r
- }\r
-\r
- @Override\r
- public DataSchemaNode next() {\r
- return allChilds.iterator().next();\r
- }\r
-\r
- @Override\r
- public void remove() {\r
- throw new UnsupportedOperationException();\r
- }\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.opendaylight.yangtools.yang.model.api.*;
+
+public class DataNodeIterator implements Iterator<DataSchemaNode> {
+
+ private final DataNodeContainer container;
+ private final List<ListSchemaNode> allLists;
+ private final List<ContainerSchemaNode> allContainers;
+ private final List<ChoiceNode> allChoices;
+ private final List<DataSchemaNode> allChilds;
+
+ public DataNodeIterator(final DataNodeContainer container) {
+ if (container == null) {
+ throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");
+ }
+
+ this.allContainers = new ArrayList<>();
+ this.allLists = new ArrayList<>();
+ this.allChilds = new ArrayList<>();
+ this.allChoices = new ArrayList<>();
+
+ this.container = container;
+ traverse(this.container);
+ }
+
+ public List<ContainerSchemaNode> allContainers() {
+ return allContainers;
+ }
+
+ public List<ListSchemaNode> allLists() {
+ return allLists;
+ }
+
+ public List<ChoiceNode> allChoices() {
+ return allChoices;
+ }
+
+ private void traverse(final DataNodeContainer dataNode) {
+ if (dataNode == null) {
+ return;
+ }
+
+ final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
+ if (childNodes != null) {
+ for (DataSchemaNode childNode : childNodes) {
+ if (childNode.isAugmenting()) {
+ continue;
+ }
+ allChilds.add(childNode);
+ if (childNode instanceof ContainerSchemaNode) {
+ final ContainerSchemaNode containerNode = (ContainerSchemaNode) childNode;
+ allContainers.add(containerNode);
+ traverse(containerNode);
+ } else if (childNode instanceof ListSchemaNode) {
+ final ListSchemaNode list = (ListSchemaNode) childNode;
+ allLists.add(list);
+ traverse(list);
+ } else if (childNode instanceof ChoiceNode) {
+ final ChoiceNode choiceNode = (ChoiceNode) childNode;
+ allChoices.add(choiceNode);
+ final Set<ChoiceCaseNode> cases = choiceNode.getCases();
+ if (cases != null) {
+ for (final ChoiceCaseNode caseNode : cases) {
+ traverse(caseNode);
+ }
+ }
+ }
+ }
+ }
+
+ traverseModule(dataNode);
+ traverseGroupings(dataNode);
+
+ }
+
+ private void traverseModule(DataNodeContainer dataNode) {
+ final Module module;
+ if (dataNode instanceof Module) {
+ module = (Module) dataNode;
+ } else {
+ return;
+ }
+ final Set<NotificationDefinition> notifications = module.getNotifications();
+ for (NotificationDefinition notificationDefinition : notifications) {
+ traverse(notificationDefinition);
+ }
+ final Set<RpcDefinition> rpcs = module.getRpcs();
+ for (RpcDefinition rpcDefinition : rpcs) {
+ ContainerSchemaNode input = rpcDefinition.getInput();
+ if (input != null) {
+ traverse(input);
+ }
+ ContainerSchemaNode output = rpcDefinition.getInput();
+ if (input != null) {
+ traverse(output);
+ }
+ }
+ }
+
+ private void traverseGroupings(DataNodeContainer dataNode) {
+ final Set<GroupingDefinition> groupings = dataNode.getGroupings();
+ if (groupings != null) {
+ for (GroupingDefinition grouping : groupings) {
+ traverse(grouping);
+ }
+ }
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (container.getChildNodes() != null) {
+ final Set<DataSchemaNode> childNodes = container.getChildNodes();
+
+ if ((childNodes != null) && !childNodes.isEmpty()) {
+ return childNodes.iterator().hasNext();
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public DataSchemaNode next() {
+ return allChilds.iterator().next();
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+}
/**
* The <code>default</code> implementation of Decimal Type Definition interface.
- *
- *
+ *
+ *
* @see DecimalTypeDefinition
*/
public final class Decimal64 implements DecimalTypeDefinition {
private final QName name = BaseTypes.constructQName("decimal64");
private final SchemaPath path;
- private final String units = "";
- private final BigDecimal defaultValue = null;
+ private static final String UNITS = "";
+ private static final BigDecimal DEFAULT_VALUE = null;
private final String description = "The decimal64 type represents a subset of the real numbers, which can "
+ "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can "
+ "be obtained by multiplying a 64-bit signed integer by a negative power of ten, i.e., expressible as "
+ "'i x 10^-n' where i is an integer64 and n is an integer between 1 and 18, inclusively.";
- private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.3";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.3";
private final List<RangeConstraint> rangeStatements;
private final Integer fractionDigits;
private final DecimalTypeDefinition baseType;
+ private static final int MAX_NUMBER_OF_FRACTION_DIGITS = 18;
/**
* Default Decimal64 Type Constructor. <br>
* The initial range statements are set to Decimal64
* <code>min=-922337203685477580.8</code> and
* <code>max=922337203685477580.7</code> <br>
- * The fractions digits MUST be defined as integer between 1 and 18
- * inclusively as defined interface {@link DecimalTypeDefinition} <br>
+ * The fractions digits MUST be defined as integer between 1 and
+ * {@link #MAX_NUMBER_OF_FRACTION_DIGITS} inclusively as defined interface
+ * {@link DecimalTypeDefinition} <br>
* If the fraction digits are not defined inner the definition boundaries
* the constructor will throw {@link IllegalArgumentException}
- *
+ *
* @param path
* @param fractionDigits
* integer between 1 and 18 inclusively
- *
+ *
* @see DecimalTypeDefinition
* @exception IllegalArgumentException
*/
public Decimal64(final SchemaPath path, final Integer fractionDigits) {
- if (!((fractionDigits.intValue() >= 1) && (fractionDigits.intValue() <= 18))) {
+ if (!((fractionDigits.intValue() >= 1) && (fractionDigits.intValue() <= MAX_NUMBER_OF_FRACTION_DIGITS))) {
throw new IllegalArgumentException(
"The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
}
/**
* Returns unmodifiable List with default definition of Range Statements.
- *
+ *
* @return unmodifiable List with default definition of Range Statements.
*/
private List<RangeConstraint> defaultRangeStatements() {
- final List<RangeConstraint> rangeStatements = new ArrayList<RangeConstraint>();
+ final List<RangeConstraint> rangeStmts = new ArrayList<RangeConstraint>();
final BigDecimal min = new BigDecimal("-922337203685477580.8");
final BigDecimal max = new BigDecimal("922337203685477580.7");
- final String rangeDescription = "Integer values between " + min
- + " and " + max + ", inclusively.";
- rangeStatements.add(BaseConstraints.rangeConstraint(min, max,
- rangeDescription,
+ final String rangeDescription = "Integer values between " + min + " and " + max + ", inclusively.";
+ rangeStmts.add(BaseConstraints.rangeConstraint(min, max, rangeDescription,
"https://tools.ietf.org/html/rfc6020#section-9.2.4"));
- return Collections.unmodifiableList(rangeStatements);
+ return Collections.unmodifiableList(rangeStmts);
}
@Override
@Override
public String getUnits() {
- return units;
+ return UNITS;
}
@Override
public Object getDefaultValue() {
- return defaultValue;
+ return DEFAULT_VALUE;
}
@Override
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
@Override
@Override
public String toString() {
- return Decimal64.class.getSimpleName() + "[qname=" + name
- + ", fractionDigits=" + fractionDigits + "]";
+ return Decimal64.class.getSimpleName() + "[qname=" + name + ", fractionDigits=" + fractionDigits + "]";
}
}
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
public final class EmptyType implements EmptyTypeDefinition {
- private static EmptyType INSTANCE;
+ private static EmptyType instance;
private static final QName NAME = BaseTypes.constructQName("empty");
- private static final SchemaPath path = new SchemaPath(Collections.singletonList(NAME), true);
- private static final String description = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence.";
- private static final String reference = "https://tools.ietf.org/html/rfc6020#page-131";
+ private static final SchemaPath PATH = new SchemaPath(Collections.singletonList(NAME), true);
+ private static final String DESCRIPTION = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence.";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#page-131";
private EmptyType() {
}
public static EmptyType getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new EmptyType();
+ if (instance == null) {
+ instance = new EmptyType();
}
- return INSTANCE;
+ return instance;
}
@Override
@Override
public SchemaPath getPath() {
- return path;
+ return PATH;
}
@Override
public String getDescription() {
- return description;
+ return DESCRIPTION;
}
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
@Override
/*
- * 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
- */
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.yangtools.yang.model.util;
import java.util.Collections;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
/**
- * The <code>default</code> implementation of Enumertaion Type Definition interface.
- *
+ * The <code>default</code> implementation of Enumertaion Type Definition
+ * interface.
+ *
* @see EnumTypeDefinition
*/
public final class EnumerationType implements EnumTypeDefinition {
private final QName name = BaseTypes.constructQName("enumeration");
private final SchemaPath path;
- private final String description = "The enumeration built-in type represents values from a set of assigned names.";
- private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.6";
+ private static final String DESCRIPTION = "The enumeration built-in type represents values from a set of assigned names.";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.6";
private final EnumPair defaultEnum;
private final List<EnumPair> enums;
- private final String units = "";
+ private static final String UNITS = "";
private final EnumTypeDefinition baseType;
public EnumerationType(final SchemaPath path, final List<EnumPair> enums) {
this.baseType = this;
}
- public EnumerationType(final SchemaPath path, final EnumPair defaultEnum,
- final List<EnumPair> enums) {
+ public EnumerationType(final SchemaPath path, final EnumPair defaultEnum, final List<EnumPair> enums) {
super();
this.path = path;
this.baseType = this;
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
+ *
+ * @see
+ * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
*/
@Override
public EnumTypeDefinition getBaseType() {
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
*/
@Override
public String getUnits() {
- return units;
+ return UNITS;
}
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue()
+ *
+ * @see
+ * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
+ * ()
*/
@Override
public Object getDefaultValue() {
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
*/
@Override
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
+ *
+ * @see
+ * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
*/
@Override
public String getDescription() {
- return description;
+ return DESCRIPTION;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
*/
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
*/
@Override
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.base.type.api.EnumTypeDefinition#getValues()
+ *
+ * @see
+ * org.opendaylight.yangtools.yang.model.base.type.api.EnumTypeDefinition
+ * #getValues()
*/
@Override
public List<EnumPair> getValues() {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((defaultEnum == null) ? 0 : defaultEnum.hashCode());
- result = prime * result
- + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((defaultEnum == null) ? 0 : defaultEnum.hashCode());
result = prime * result + ((enums == null) ? 0 : enums.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
- result = prime * result
- + ((reference == null) ? 0 : reference.hashCode());
- result = prime * result + ((units == null) ? 0 : units.hashCode());
return result;
}
} else if (!defaultEnum.equals(other.defaultEnum)) {
return false;
}
- if (description == null) {
- if (other.description != null) {
- return false;
- }
- } else if (!description.equals(other.description)) {
- return false;
- }
if (enums == null) {
if (other.enums != null) {
return false;
} else if (!path.equals(other.path)) {
return false;
}
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
- return false;
- }
- if (units == null) {
- if (other.units != null) {
- return false;
- }
- } else if (!units.equals(other.units)) {
- return false;
- }
return true;
}
builder.append(", path=");
builder.append(path);
builder.append(", description=");
- builder.append(description);
+ builder.append(DESCRIPTION);
builder.append(", reference=");
- builder.append(reference);
+ builder.append(REFERENCE);
builder.append(", defaultEnum=");
builder.append(defaultEnum);
builder.append(", enums=");
builder.append(enums);
builder.append(", units=");
- builder.append(units);
+ builder.append(UNITS);
builder.append("]");
return builder.toString();
}
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.model.util;\r
-\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import org.opendaylight.yangtools.yang.common.QName;\r
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
-import org.opendaylight.yangtools.yang.model.api.Status;\r
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;\r
-import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;\r
-\r
-/**\r
- * The <code>default</code> implementation of Identityref Type Definition\r
- * interface.\r
- *\r
- * @see IdentityrefTypeDefinition\r
- */\r
-public final class IdentityrefType implements IdentityrefTypeDefinition {\r
- private final QName name = BaseTypes.constructQName("identityref");\r
- private final SchemaPath path;\r
- private final String description = "The identityref type is used to reference an existing identity.";\r
- private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.10";\r
- private final IdentityrefTypeDefinition baseType;\r
- private final QName identity;\r
- private final String units = "";\r
-\r
- public IdentityrefType(QName identity, SchemaPath schemaPath) {\r
- this.identity = identity;\r
- this.path = schemaPath;\r
- this.baseType = this;\r
- }\r
-\r
- @Override\r
- public String getUnits() {\r
- return units;\r
- }\r
-\r
- @Override\r
- public Object getDefaultValue() {\r
- return identity;\r
- }\r
-\r
- @Override\r
- public QName getQName() {\r
- return name;\r
- }\r
-\r
- @Override\r
- public SchemaPath getPath() {\r
- return path;\r
- }\r
-\r
- @Override\r
- public String getDescription() {\r
- return description;\r
- }\r
-\r
- @Override\r
- public String getReference() {\r
- return reference;\r
- }\r
-\r
- @Override\r
- public Status getStatus() {\r
- return Status.CURRENT;\r
- }\r
-\r
- @Override\r
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
- return Collections.emptyList();\r
- }\r
-\r
- @Override\r
- public QName getIdentity() {\r
- return identity;\r
- }\r
-\r
- @Override\r
- public IdentityrefTypeDefinition getBaseType() {\r
- return baseType;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "identityref " + identity.getLocalName();\r
- }\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+
+/**
+ * The <code>default</code> implementation of Identityref Type Definition
+ * interface.
+ *
+ * @see IdentityrefTypeDefinition
+ */
+public final class IdentityrefType implements IdentityrefTypeDefinition {
+ private final QName name = BaseTypes.constructQName("identityref");
+ private final SchemaPath path;
+ private static final String DESCRIPTION = "The identityref type is used to reference an existing identity.";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.10";
+ private final IdentityrefTypeDefinition baseType;
+ private final QName identity;
+ private static final String UNITS = "";
+
+ public IdentityrefType(QName identity, SchemaPath schemaPath) {
+ this.identity = identity;
+ this.path = schemaPath;
+ this.baseType = this;
+ }
+
+ @Override
+ public String getUnits() {
+ return UNITS;
+ }
+
+ @Override
+ public Object getDefaultValue() {
+ return identity;
+ }
+
+ @Override
+ public QName getQName() {
+ return name;
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return path;
+ }
+
+ @Override
+ public String getDescription() {
+ return DESCRIPTION;
+ }
+
+ @Override
+ public String getReference() {
+ return REFERENCE;
+ }
+
+ @Override
+ public Status getStatus() {
+ return Status.CURRENT;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public QName getIdentity() {
+ return identity;
+ }
+
+ @Override
+ public IdentityrefTypeDefinition getBaseType() {
+ return baseType;
+ }
+
+ @Override
+ public String toString() {
+ return "identityref " + identity.getLocalName();
+ }
+
+}
/**
* The <code>default</code> implementation of Instance Identifier Type
* Definition interface.
- *
+ *
* @see InstanceIdentifierTypeDefinition
*/
public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
- private static final QName name = BaseTypes.constructQName("instance-identifier");
- private static final SchemaPath path = new SchemaPath(Collections.singletonList(name), true);
- private static final String description = "The instance-identifier built-in type is used to "
+ private static final QName NAME = BaseTypes.constructQName("instance-identifier");
+ private static final SchemaPath PATH = new SchemaPath(Collections.singletonList(NAME), true);
+ private static final String DESCRIPTION = "The instance-identifier built-in type is used to "
+ "uniquely identify a particular instance node in the data tree.";
- private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.13";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.13";
private final RevisionAwareXPath xpath;
- private static final String units = "";
+ private static final String UNITS = "";
private boolean requireInstance = true;
+ private static final int HASH_BOOLEAN_TRUE = 1231;
+ private static final int HASH_BOOLEAN_FALSE = 1237;
+
public InstanceIdentifier(final RevisionAwareXPath xpath) {
this.xpath = xpath;
}
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
*/
@Override
public String getUnits() {
- return units;
+ return UNITS;
}
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
* ()
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
*/
@Override
public QName getQName() {
- return name;
+ return NAME;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
*/
@Override
public SchemaPath getPath() {
- return path;
+ return PATH;
}
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
*/
@Override
public String getDescription() {
- return description;
+ return DESCRIPTION;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
*/
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
* ()
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.type.
* InstanceIdentifierTypeDefinition# getPathStatement()
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.type.
* InstanceIdentifierTypeDefinition# requireInstance()
*/
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + (requireInstance ? 1231 : 1237);
+ result = prime * result + (requireInstance ? HASH_BOOLEAN_TRUE : HASH_BOOLEAN_FALSE);
result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
InstanceIdentifier other = (InstanceIdentifier) obj;
- if (requireInstance != other.requireInstance)
+ if (requireInstance != other.requireInstance) {
return false;
+ }
if (xpath == null) {
- if (other.xpath != null)
+ if (other.xpath != null) {
return false;
- } else if (!xpath.equals(other.xpath))
+ }
+ } else if (!xpath.equals(other.xpath)) {
return false;
+ }
return true;
}
* Implementation of Yang int16 built-in type. <br>
* int16 represents integer values between -32768 and 32767, inclusively. The
* Java counterpart of Yang int16 built-in type is {@link Short}.
- *
+ *
* @see AbstractSignedInteger
*/
public final class Int16 extends AbstractSignedInteger {
- private static Int16 INSTANCE;
+ private static Int16 instance;
private static final QName NAME = BaseTypes.constructQName("int16");
private static final String DESCRIPTION = "int16 represents integer values between -32768 and 32767, inclusively.";
}
public static Int16 getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new Int16();
+ if (instance == null) {
+ instance = new Int16();
}
- return INSTANCE;
+ return instance;
}
@Override
* int32 represents integer values between -2147483648 and 2147483647,
* inclusively. The Java counterpart of Yang int32 built-in type is
* {@link Integer}.
- *
+ *
* @see AbstractSignedInteger
- *
+ *
*/
public final class Int32 extends AbstractSignedInteger {
- private static Int32 INSTANCE;
+ private static Int32 instance;
private static final QName NAME = BaseTypes.constructQName("int32");
private static final String DESCRIPTION = "int32 represents integer values between -2147483648 and 2147483647, inclusively.";
}
public static Int32 getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new Int32();
+ if (instance == null) {
+ instance = new Int32();
}
- return INSTANCE;
+ return instance;
}
@Override
* int64 represents integer values between -9223372036854775808 and
* 9223372036854775807, inclusively. The Java counterpart of Yang int64 built-in
* type is {@link Long}.
- *
+ *
*/
public final class Int64 extends AbstractSignedInteger {
- private static Int64 INSTANCE;
+ private static Int64 instance;
private static final QName NAME = BaseTypes.constructQName("int64");
private static final String DESCRIPTION = "int64 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.";
}
public static Int64 getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new Int64();
+ if (instance == null) {
+ instance = new Int64();
}
- return INSTANCE;
+ return instance;
}
@Override
* Implementation of Yang int8 built-in type. <br>
* int8 represents integer values between -128 and 127, inclusively. The Java
* counterpart of Yang int8 built-in type is {@link Byte}.
- *
+ *
* @see AbstractSignedInteger
*/
public final class Int8 extends AbstractSignedInteger {
- private static Int8 INSTANCE;
+ private static Int8 instance;
private static final QName NAME = BaseTypes.constructQName("int8");
private static final String DESCRIPTION = "represents integer values between -128 and 127, inclusively.";
}
public static Int8 getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new Int8();
+ if (instance == null) {
+ instance = new Int8();
}
- return INSTANCE;
+ return instance;
}
@Override
import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
/**
- * The <code>default</code> implementation of Instance Rewision Aware XPath interface.
+ * The <code>default</code> implementation of Instance Rewision Aware XPath
+ * interface.
*
* @see RevisionAwareXPath
*/
private final String xpath;
private final boolean absolute;
+ private static final int HASH_BOOLEAN_TRUE = 1231;
+ private static final int HASH_BOOLEAN_FALSE = 1237;
+
public RevisionAwareXPathImpl(String xpath, boolean absolute) {
this.xpath = xpath;
this.absolute = absolute;
final int prime = 31;
int result = 1;
result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
- result = prime * result + (absolute ? 1231 : 1237);
+ result = prime * result + (absolute ? HASH_BOOLEAN_TRUE : HASH_BOOLEAN_FALSE);
return result;
}
}
return false;
}
-
+
@Override
public String toString() {
return xpath;
/*
- * 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
- */
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.yangtools.yang.model.util;
import java.util.ArrayList;
/**
* The <code>default</code> implementation of String Type Definition interface.
- *
+ *
* @see StringTypeDefinition
*/
public final class StringType implements StringTypeDefinition {
private static final StringType INSTANCE = new StringType();
private final QName name = BaseTypes.constructQName("string");
private final SchemaPath path = new SchemaPath(Collections.singletonList(name), true);
- private final String defaultValue = "";
- private final String description = "";
- private final String reference = "";
+ private static final String DEFAULT_VALUE = "";
+ private static final String DESCRIPTION = "";
+ private static final String REFERENCE = "";
private final List<LengthConstraint> lengthStatements;
private final List<PatternConstraint> patterns;
- private final String units = "";
+ private static final String UNITS = "";
/**
* Default Constructor.
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
+ *
+ * @see
+ * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
*/
@Override
public StringTypeDefinition getBaseType() {
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
*/
@Override
public String getUnits() {
- return units;
+ return UNITS;
}
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue()
+ *
+ * @see
+ * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
+ * ()
*/
@Override
public Object getDefaultValue() {
- return defaultValue;
+ return DEFAULT_VALUE;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
*/
@Override
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
+ *
+ * @see
+ * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
*/
@Override
public String getDescription() {
- return description;
+ return DESCRIPTION;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
*/
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see
* com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
* ()
/*
* (non-Javadoc)
- *
+ *
* @see
* com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
*/
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((defaultValue == null) ? 0 : defaultValue.hashCode());
- result = prime * result
- + ((description == null) ? 0 : description.hashCode());
- result = prime
- * result
- + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
+ result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
- result = prime * result
- + ((patterns == null) ? 0 : patterns.hashCode());
- result = prime * result
- + ((reference == null) ? 0 : reference.hashCode());
- result = prime * result + ((units == null) ? 0 : units.hashCode());
+ result = prime * result + ((patterns == null) ? 0 : patterns.hashCode());
return result;
}
return false;
}
StringType other = (StringType) obj;
- if (defaultValue == null) {
- if (other.defaultValue != null) {
- return false;
- }
- } else if (!defaultValue.equals(other.defaultValue)) {
- return false;
- }
- if (description == null) {
- if (other.description != null) {
- return false;
- }
- } else if (!description.equals(other.description)) {
- return false;
- }
if (lengthStatements == null) {
if (other.lengthStatements != null) {
return false;
if (other.path != null) {
return false;
}
- } else if ((path != null) && (other.path != null)) {
- if (!path.getPath().equals(other.path.getPath())) {
- return false;
- }
+ } else if (!path.getPath().equals(other.path.getPath())) {
+ return false;
}
if (patterns == null) {
if (other.patterns != null) {
} else if (!patterns.equals(other.patterns)) {
return false;
}
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
- return false;
- }
- if (units == null) {
- if (other.units != null) {
- return false;
- }
- } else if (!units.equals(other.units)) {
- return false;
- }
return true;
}
builder.append(", path=");
builder.append(path);
builder.append(", defaultValue=");
- builder.append(defaultValue);
+ builder.append(DEFAULT_VALUE);
builder.append(", description=");
- builder.append(description);
+ builder.append(DESCRIPTION);
builder.append(", reference=");
- builder.append(reference);
+ builder.append(REFERENCE);
builder.append(", lengthStatements=");
builder.append(lengthStatements);
builder.append(", patterns=");
builder.append(patterns);
builder.append(", units=");
- builder.append(units);
+ builder.append(UNITS);
builder.append("]");
return builder.toString();
}
* Implementation of Yang uint16 built-in type. <br>
* uint16 represents integer values between 0 and 65535, inclusively. The Java
* counterpart of Yang uint16 built-in type is {@link Integer}.
- *
+ *
*/
public final class Uint16 extends AbstractUnsignedInteger {
public static final int MAX_VALUE = 65535;
- private static Uint16 INSTANCE;
+ private static Uint16 instance;
private static final QName NAME = BaseTypes.constructQName("uint16");
private static final String DESCRIPTION = "uint16 represents integer values between 0 and 65535, inclusively.";
}
public static Uint16 getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new Uint16();
+ if (instance == null) {
+ instance = new Uint16();
}
- return INSTANCE;
+ return instance;
}
@Override
/**
* Implementation of Yang uint32 built-in type. <br>
* uint32 represents integer values between 0 and 4294967295, inclusively.
- *
+ *
*/
public final class Uint32 extends AbstractUnsignedInteger {
public static final long MAX_VALUE = 4294967295L;
- private static Uint32 INSTANCE;
+ private static Uint32 instance;
private static final QName NAME = BaseTypes.constructQName("uint32");
private static final String DESCRIPTION = "uint32 represents integer values between 0 and 4294967295, inclusively.";
}
public static Uint32 getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new Uint32();
+ if (instance == null) {
+ instance = new Uint32();
}
- return INSTANCE;
+ return instance;
}
@Override
* uint64 represents integer values between 0 and 18446744073709551615,
* inclusively. The Java counterpart of Yang uint64 built-in type is
* {@link BigInteger}.
- *
+ *
*/
public final class Uint64 extends AbstractUnsignedInteger {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
- private static Uint64 INSTANCE;
+ private static Uint64 instance;
private static final QName NAME = BaseTypes.constructQName("uint64");
private static final String DESCRIPTION = "uint64 represents integer values between 0 and 18446744073709551615, inclusively.";
}
public static Uint64 getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new Uint64();
+ if (instance == null) {
+ instance = new Uint64();
}
- return INSTANCE;
+ return instance;
}
@Override
/**
* Implementation of Yang uint8 built-in type. <br>
* uint8 represents integer values between 0 and 255, inclusively.
- *
+ *
* @see AbstractUnsignedInteger
*/
public final class Uint8 extends AbstractUnsignedInteger {
public static final int MAX_VALUE = 255;
- private static Uint8 INSTANCE;
+ private static Uint8 instance;
private static final QName NAME = BaseTypes.constructQName("uint8");
private static final String DESCRIPTION = "uint8 represents integer values between 0 and 255, inclusively.";
}
public static Uint8 getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new Uint8();
+ if (instance == null) {
+ instance = new Uint8();
}
- return INSTANCE;
+ return instance;
}
@Override
public final class UnionType implements UnionTypeDefinition {
private final QName name = BaseTypes.constructQName("union");
private final SchemaPath path = BaseTypes.schemaPath(name);
- private final String description = "The union built-in type represents a value that corresponds to one of its member types.";
- private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12";
+ private static final String DESCRIPTION = "The union built-in type represents a value that corresponds to one of its member types.";
+ private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.12";
private final List<TypeDefinition<?>> types;
public UnionType(List<TypeDefinition<?>> types) {
if (types == null) {
- throw new NullPointerException(
- "When the type is 'union', the 'type' statement MUST be present.");
+ throw new IllegalArgumentException("When the type is 'union', the 'type' statement MUST be present.");
}
this.types = types;
}
@Override
public String getDescription() {
- return description;
+ return DESCRIPTION;
}
@Override
public String getReference() {
- return reference;
+ return REFERENCE;
}
@Override
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition;
-public class UnknownType implements UnknownTypeDefinition {
+public final class UnknownType implements UnknownTypeDefinition {
private final QName name;
private final SchemaPath path;
private String description;
private String reference;
- private List<LengthConstraint> lengthStatements = Collections
- .emptyList();
+ private List<LengthConstraint> lengthStatements = Collections.emptyList();
private List<PatternConstraint> patterns = Collections.emptyList();
private List<RangeConstraint> rangeStatements = Collections.emptyList();
private List<UnknownSchemaNode> extensions = Collections.emptyList();
private Object defaultValue = null;
private boolean referenceOnly = false;
- public Builder(final QName name, final String description,
- final String reference) {
+ public Builder(final QName name, final String description, final String reference) {
this.name = name;
this.path = BaseTypes.schemaPath(name);
this.description = description;
return this;
}
- public Builder lengthStatements(
- final List<LengthConstraint> lengthStatements) {
+ public Builder lengthStatements(final List<LengthConstraint> lengthStatements) {
this.lengthStatements = lengthStatements;
return this;
}
return this;
}
- public Builder rangeStatements(
- final List<RangeConstraint> rangeStatements) {
+ public Builder rangeStatements(final List<RangeConstraint> rangeStatements) {
this.rangeStatements = rangeStatements;
return this;
}
}
public void setReferenceOnly(boolean b) {
- this.referenceOnly = b;
-
+ this.referenceOnly = b;
+
}
}
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
* ()
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see
* org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
* ()
/*
* (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
+ *
+ * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
* #getRangeStatements()
*/
@Override
/*
* (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
+ *
+ * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
* #getLengthStatements()
*/
@Override
/*
* (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
+ *
+ * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
* #getPatterns()
*/
@Override
/*
* (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
+ *
+ * @see org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition
* #getLengthConstraint()
*/
@Override
public boolean isReferenceOnly() {
return referenceOnly;
}
-
+
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((defaultValue == null) ? 0 : defaultValue.hashCode());
- result = prime * result
- + ((description == null) ? 0 : description.hashCode());
- result = prime * result
- + ((extensions == null) ? 0 : extensions.hashCode());
- result = prime
- * result
- + ((lengthConstraint == null) ? 0 : lengthConstraint.hashCode());
- result = prime
- * result
- + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
+ result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((extensions == null) ? 0 : extensions.hashCode());
+ result = prime * result + ((lengthConstraint == null) ? 0 : lengthConstraint.hashCode());
+ result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((path == null) ? 0 : path.hashCode());
- result = prime * result
- + ((patterns == null) ? 0 : patterns.hashCode());
- result = prime * result
- + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
- result = prime * result
- + ((reference == null) ? 0 : reference.hashCode());
+ result = prime * result + ((patterns == null) ? 0 : patterns.hashCode());
+ result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
+ result = prime * result + ((reference == null) ? 0 : reference.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((units == null) ? 0 : units.hashCode());
return result;
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.model.util;\r
-\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
-\r
-public final class YangTypesConverter {\r
- private static final Set<String> baseYangTypes = new HashSet<String>();\r
-\r
- static {\r
- baseYangTypes.add("binary");\r
- baseYangTypes.add("bits");\r
- baseYangTypes.add("boolean");\r
- baseYangTypes.add("decimal64");\r
- baseYangTypes.add("empty");\r
- baseYangTypes.add("enumeration");\r
- baseYangTypes.add("identityref");\r
- baseYangTypes.add("instance-identifier");\r
- baseYangTypes.add("int8");\r
- baseYangTypes.add("int16");\r
- baseYangTypes.add("int32");\r
- baseYangTypes.add("int64");\r
- baseYangTypes.add("leafref");\r
- baseYangTypes.add("string");\r
- baseYangTypes.add("uint8");\r
- baseYangTypes.add("uint16");\r
- baseYangTypes.add("uint32");\r
- baseYangTypes.add("uint64");\r
- baseYangTypes.add("union");\r
- }\r
-\r
- public static boolean isBaseYangType(String type) {\r
- return baseYangTypes.contains(type);\r
- }\r
-\r
- public static TypeDefinition<?> javaTypeForBaseYangType(String typeName) {\r
- TypeDefinition<?> type = null;\r
-\r
- if (typeName.startsWith("int")) {\r
- if ("int8".equals(typeName)) {\r
- type = Int8.getInstance();\r
- } else if ("int16".equals(typeName)) {\r
- type = Int16.getInstance();\r
- } else if ("int32".equals(typeName)) {\r
- type = Int32.getInstance();\r
- } else if ("int64".equals(typeName)) {\r
- type = Int64.getInstance();\r
- }\r
- } else if (typeName.startsWith("uint")) {\r
- if ("uint8".equals(typeName)) {\r
- type = Uint8.getInstance();\r
- } else if ("uint16".equals(typeName)) {\r
- type = Uint16.getInstance();\r
- } else if ("uint32".equals(typeName)) {\r
- type = Uint32.getInstance();\r
- } else if ("uint64".equals(typeName)) {\r
- type = Uint64.getInstance();\r
- }\r
- } else if ("string".equals(typeName)) {\r
- type = StringType.getIntance();\r
- } else if("binary".equals(typeName)) {\r
- type = BinaryType.getInstance();\r
- } else if("boolean".equals(typeName)) {\r
- type = BooleanType.getInstance();\r
- } else if("empty".equals(typeName)) {\r
- type = EmptyType.getInstance();\r
- } else if("instance-identifier".equals(typeName)) {\r
- // FIXME\r
- type = new InstanceIdentifier(null, true);\r
- }\r
-\r
- return type;\r
- }\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+
+public final class YangTypesConverter {
+ private static final Set<String> BASE_YANG_TYPES = new HashSet<String>();
+
+ /**
+ * It isn't desirable to create the instances of this class
+ */
+ private YangTypesConverter() {
+ }
+
+ static {
+ BASE_YANG_TYPES.add("binary");
+ BASE_YANG_TYPES.add("bits");
+ BASE_YANG_TYPES.add("boolean");
+ BASE_YANG_TYPES.add("decimal64");
+ BASE_YANG_TYPES.add("empty");
+ BASE_YANG_TYPES.add("enumeration");
+ BASE_YANG_TYPES.add("identityref");
+ BASE_YANG_TYPES.add("instance-identifier");
+ BASE_YANG_TYPES.add("int8");
+ BASE_YANG_TYPES.add("int16");
+ BASE_YANG_TYPES.add("int32");
+ BASE_YANG_TYPES.add("int64");
+ BASE_YANG_TYPES.add("leafref");
+ BASE_YANG_TYPES.add("string");
+ BASE_YANG_TYPES.add("uint8");
+ BASE_YANG_TYPES.add("uint16");
+ BASE_YANG_TYPES.add("uint32");
+ BASE_YANG_TYPES.add("uint64");
+ BASE_YANG_TYPES.add("union");
+ }
+
+ public static boolean isBaseYangType(String type) {
+ return BASE_YANG_TYPES.contains(type);
+ }
+
+ public static TypeDefinition<?> javaTypeForBaseYangType(String typeName) {
+ TypeDefinition<?> type = null;
+
+ if (typeName.startsWith("int")) {
+ if ("int8".equals(typeName)) {
+ type = Int8.getInstance();
+ } else if ("int16".equals(typeName)) {
+ type = Int16.getInstance();
+ } else if ("int32".equals(typeName)) {
+ type = Int32.getInstance();
+ } else if ("int64".equals(typeName)) {
+ type = Int64.getInstance();
+ }
+ } else if (typeName.startsWith("uint")) {
+ if ("uint8".equals(typeName)) {
+ type = Uint8.getInstance();
+ } else if ("uint16".equals(typeName)) {
+ type = Uint16.getInstance();
+ } else if ("uint32".equals(typeName)) {
+ type = Uint32.getInstance();
+ } else if ("uint64".equals(typeName)) {
+ type = Uint64.getInstance();
+ }
+ } else if ("string".equals(typeName)) {
+ type = StringType.getIntance();
+ } else if ("binary".equals(typeName)) {
+ type = BinaryType.getInstance();
+ } else if ("boolean".equals(typeName)) {
+ type = BooleanType.getInstance();
+ } else if ("empty".equals(typeName)) {
+ type = EmptyType.getInstance();
+ } else if ("instance-identifier".equals(typeName)) {
+ // FIXME
+ type = new InstanceIdentifier(null, true);
+ }
+
+ return type;
+ }
+
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.model.util;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+public class Int8Test {
+
+ @Test
+ public void testInt8() {
+ Int8 int8 = Int8.getInstance();
+ Int8 int8Second = Int8.getInstance();
+ assertTrue("The method 'getInstance()' has to return the same instance", int8 == int8Second);
+ assertTrue("The method 'getBaseType()' is returning incorrect value", int8.getBaseType() == int8);
+ assertTrue("The method 'getDefaultType()' is returning incorrect value", int8.getDefaultValue() == null);
+ assertEquals("The method 'toString()' is returning incorrect value",
+ "type (urn:ietf:params:xml:ns:yang:1)int8", int8.toString());
+
+ }
+
+}
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition;
/**
* Yang Model Parser interface is designed for parsing yang models and convert
* the information to Data Schema Tree.
- *
+ *
*/
public interface YangModelParser {
* modules defined in *.yang files; <br>
* This method SHOULD be used if user need to parse multiple yang models
* that are referenced either through import or include statements.
- *
+ *
* @param yangFiles
* yang files to parse
* @return Set of Yang Modules
* This method SHOULD be used if user has already parsed context and need to
* parse additinal yang models which can have dependencies on models in this
* context.
- *
+ *
* @param yangFiles
* yang files to parse
* @param context
/**
* Equivalent to {@link #parseYangModels(List)} that returns parsed modules
* mapped to Files from which they were parsed.
- *
+ *
* @param yangFiles
* yang files to parse
* @return Map of Yang Modules
* modules defined in *.yang files; <br>
* This method SHOULD be used if user need to parse multiple yang models
* that are referenced either through import or include statements.
- *
+ *
* @param yangModelStreams
* yang streams to parse
* @return Set of Yang Modules
* This method SHOULD be used if user has already parsed context and need to
* parse additinal yang models which can have dependencies on models in this
* context.
- *
+ *
* @param yangModelStreams
* yang streams to parse
* @param context
/**
* Equivalent to {@link #parseYangModels(List)} that returns parsed modules
* mapped to IputStreams from which they were parsed.
- *
+ *
* @param yangModelStreams
* yang streams to parse
* @return Map of Yang Modules
* should not contain ANY Schema Nodes that contains
* {@link UnknownTypeDefinition} and all dependencies although via import or
* include definitions are resolved.
- *
+ *
* @param modules
* Set of Yang Modules
* @return Schema Context instance constructed from whole Set of Modules.
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-public class Comparators {
+public final class Comparators {
public static final QNameComparator QNAME_COMP = new QNameComparator();
public static final SchemaNodeComparator SCHEMA_NODE_COMP = new SchemaNodeComparator();
* Utility class with helper methods to perform operations tied to refine
* process.
*/
-public class RefineUtils {
+public final class RefineUtils {
private RefineUtils() {
}
/**
* Check if refine can be performed on given node.
- *
+ *
* @param node
* node to refine
* @param refine
* <li>reference</li>
* <li>config</li>
* </ul>
- *
+ *
* These parameters may be refined for any node.
- *
+ *
* @param node
* node to refine
* @param refine
/**
* Perform refine operation on given node.
- *
+ *
* @param nodeToRefine
* builder of node to refine
* @param refine
assertEquals("iit", identity.getPrefix());
assertEquals("service-type", identity.getLocalName());
- LeafSchemaNode type = (LeafSchemaNode)tested.getDataChildByName("type");
+ LeafSchemaNode type = (LeafSchemaNode) tested.getDataChildByName("type");
assertNotNull(type);
}