Short port = Short.decode(ingressPort);
if (isPortValid(sw, port) == false) {
String msg = String.format("Ingress port %d is not valid for the Switch", port);
- if ((container != null) && !container.getName().equals(GlobalConstants.DEFAULT.toString())) {
- msg += " in Container " + container.getName();
+ if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
+ msg += " in Container " + containerName;
}
return new Status(StatusCode.BADREQUEST, msg);
}
Short port = Short.parseShort(n.group(1));
if (isPortValid(sw, port) == false) {
String msg = String.format("Output port %d is not valid for this switch", port);
- if ((container != null)
- && !container.getName().equals(GlobalConstants.DEFAULT.toString())) {
- msg += " in Container " + container.getName();
+ if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
+ msg += " in Container " + containerName;
}
return new Status(StatusCode.BADREQUEST, msg);
}
// Check src IP
sstr = Pattern.compile(ActionType.FLOOD.toString()).matcher(actiongrp);
if (sstr.matches()) {
- if (container != null) {
+ if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
return new Status(StatusCode.BADREQUEST, String.format(
- "flood is not allowed in container %s", container.getName()));
+ "flood is not allowed in container %s", containerName));
}
continue;
}
}
// Check against the container flow
Status status;
- if ((container != null) && !(status = conflictWithContainerFlow(container)).isSuccess()) {
+ if (!containerName.equals(GlobalConstants.DEFAULT.toString()) && !(status = conflictWithContainerFlow(container)).isSuccess()) {
return status;
}
} catch (NumberFormatException e) {
}
// Program the network node
- Status status = this.removeEntry(config.getFlowEntry(), false);
+ Status status = this.uninstallFlowEntry(config.getFlowEntry());
// Update configuration database if programming was successful
if (status.isSuccess()) {
// If flow is installed, program the network node
status = new Status(StatusCode.SUCCESS, "Saved in config");
if (oldFlowConfig.installInHw()) {
- status = this.modifyEntry(oldFlowConfig.getFlowEntry(), newFlowConfig.getFlowEntry(), false);
+ status = this.modifyFlowEntry(oldFlowConfig.getFlowEntry(), newFlowConfig.getFlowEntry());
}
// Update configuration database if programming was successful
}
if (target != null) {
// Program the network node
- Status status;
- if (target.installInHw()) {
- status = this.removeEntry(target.getFlowEntry(), false);
- } else {
- status = this.addEntry(target.getFlowEntry(), false);
+ Status status = (target.installInHw()) ? this.uninstallFlowEntry(target.getFlowEntry()) : this
+ .installFlowEntry(target.getFlowEntry());
+ if (status.isSuccess()) {
+ // Update Configuration database
+ target.setStatus(SUCCESS);
+ target.toggleInstallation();
+ staticFlows.put(key, target);
}
- // Update Configuration database
- target.setStatus(SUCCESS);
- target.toggleInstallation();
- staticFlows.put(key, target);
return status;
}
* Function called by the dependency manager before the services exported by
* the component are unregistered, this will be followed by a "destroy ()"
* calls
- *
*/
void stop() {
- // Set graceful stop flag
stopping = true;
+ uninstallAllFlowEntries();
}
public void setFlowProgrammerService(IFlowProgrammerService service) {
<groupId>junit</groupId>\r
<artifactId>junit</artifactId>\r
</dependency>\r
+ <dependency>\r
+ <groupId>commons-lang</groupId>\r
+ <artifactId>commons-lang</artifactId>\r
+ <version>2.1</version>\r
+ </dependency>\r
</dependencies>\r
</project>
\ No newline at end of file
*/
package org.opendaylight.controller.sal.binding.generator.impl;
+import static org.opendaylight.controller.binding.generator.util.BindingGeneratorUtil.*;
+import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findDataSchemaNode;
+import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findParentModule;
+
+import java.util.*;
+import java.util.concurrent.Future;
+
import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
import org.opendaylight.controller.binding.generator.util.Types;
import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
import org.opendaylight.controller.sal.binding.generator.spi.TypeProvider;
-import org.opendaylight.controller.sal.binding.model.api.*;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
import org.opendaylight.controller.sal.binding.yang.types.TypeProviderImpl;
import org.opendaylight.controller.yang.binding.Notification;
import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.SchemaContextUtil;
-import java.util.*;
-import java.util.concurrent.Future;
-
-import static org.opendaylight.controller.binding.generator.util.BindingGeneratorUtil.*;
-import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findDataSchemaNode;
-import static org.opendaylight.controller.yang.model.util.SchemaContextUtil.findParentModule;
-
public final class BindingGeneratorImpl implements BindingGenerator {
private Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders;
@Override
public List<Type> generateTypes(final SchemaContext context) {
if (context == null) {
- throw new IllegalArgumentException("Schema Context reference "
- + "cannot be NULL!");
+ throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
}
if (context.getModules() == null) {
- throw new IllegalStateException("Schema Context does not contain "
- + "defined modules!");
+ throw new IllegalStateException("Schema Context does not contain defined modules!");
}
final List<Type> generatedTypes = new ArrayList<>();
generatedTypes.addAll(allTypeDefinitionsToGenTypes(module));
generatedTypes.addAll(allContainersToGenTypes(module));
generatedTypes.addAll(allListsToGenTypes(module));
+ generatedTypes.addAll(allChoicesToGenTypes(module));
generatedTypes.addAll(allAugmentsToGenTypes(module));
generatedTypes.addAll(allRPCMethodsToGenType(module));
generatedTypes.addAll(allNotificationsToGenType(module));
}
@Override
- public List<Type> generateTypes(final SchemaContext context,
- final Set<Module> modules) {
+ public List<Type> generateTypes(final SchemaContext context, final Set<Module> modules) {
if (context == null) {
- throw new IllegalArgumentException("Schema Context reference "
- + "cannot be NULL!");
+ throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
}
if (context.getModules() == null) {
- throw new IllegalStateException("Schema Context does not contain "
- + "defined modules!");
+ throw new IllegalStateException("Schema Context does not contain defined modules!");
}
if (modules == null) {
- throw new IllegalArgumentException("Sef of Modules cannot be "
- + "NULL!");
+ throw new IllegalArgumentException("Sef of Modules cannot be NULL!");
}
final List<Type> filteredGenTypes = new ArrayList<>();
generatedTypes.addAll(allTypeDefinitionsToGenTypes(contextModule));
generatedTypes.addAll(allContainersToGenTypes(contextModule));
generatedTypes.addAll(allListsToGenTypes(contextModule));
+ generatedTypes.addAll(allChoicesToGenTypes(contextModule));
generatedTypes.addAll(allAugmentsToGenTypes(contextModule));
generatedTypes.addAll(allRPCMethodsToGenType(contextModule));
generatedTypes.addAll(allNotificationsToGenType(contextModule));
- generatedTypes.addAll(allIdentitiesToGenTypes(contextModule,
- context));
+ generatedTypes.addAll(allIdentitiesToGenTypes(contextModule, context));
generatedTypes.addAll(allGroupingsToGenTypes(contextModule));
if (modules.contains(contextModule)) {
private List<Type> allTypeDefinitionsToGenTypes(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
throw new IllegalArgumentException("Module name cannot be NULL!");
}
if (module.getTypeDefinitions() == null) {
- throw new IllegalArgumentException("Type Definitions for module "
- + module.getName() + " cannot be NULL!");
+ throw new IllegalArgumentException("Type Definitions for module " + module.getName() + " cannot be NULL!");
}
- final Set<TypeDefinition<?>> typeDefinitions = module
- .getTypeDefinitions();
+ final Set<TypeDefinition<?>> typeDefinitions = module.getTypeDefinitions();
final List<Type> generatedTypes = new ArrayList<>();
for (final TypeDefinition<?> typedef : typeDefinitions) {
if (typedef != null) {
- final Type type = ((TypeProviderImpl) typeProvider)
- .generatedTypeForExtendedDefinitionType(typedef);
+ final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef);
if ((type != null) && !generatedTypes.contains(type)) {
generatedTypes.add(type);
}
private List<Type> allContainersToGenTypes(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
}
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of Child "
- + "Nodes in module " + module.getName() + " cannot be "
- + "NULL!");
+ throw new IllegalArgumentException("Reference to Set of Child Nodes in module " + module.getName()
+ + " cannot be NULL!");
}
final List<Type> generatedTypes = new ArrayList<>();
private List<Type> allListsToGenTypes(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
}
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of Child "
- + "Nodes in module " + module.getName() + " cannot be "
- + "NULL!");
+ throw new IllegalArgumentException("Reference to Set of Child Nodes in module " + module.getName()
+ + " cannot be NULL!");
}
final List<Type> generatedTypes = new ArrayList<>();
return generatedTypes;
}
- private List<Type> allAugmentsToGenTypes(final Module module) {
+ private List<GeneratedType> allChoicesToGenTypes(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
-
if (module.getName() == null) {
throw new IllegalArgumentException("Module name cannot be NULL!");
}
+ final DataNodeIterator it = new DataNodeIterator(module);
+ final List<ChoiceNode> choiceNodes = it.allChoices();
+ final String basePackageName = moduleNamespaceToPackageName(module);
+
+ final List<GeneratedType> generatedTypes = new ArrayList<>();
+ for (final ChoiceNode choice : choiceNodes) {
+ if (choice != null) {
+ generatedTypes.addAll(choiceToGeneratedType(basePackageName, choice));
+ }
+ }
+ return generatedTypes;
+ }
+
+ private List<Type> allAugmentsToGenTypes(final Module module) {
+ if (module == null) {
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
+ }
+ if (module.getName() == null) {
+ throw new IllegalArgumentException("Module name cannot be NULL!");
+ }
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of "
- + "Augmentation Definitions in module " + module.getName()
- + " cannot be NULL!");
+ throw new IllegalArgumentException("Reference to Set of Augmentation Definitions in module "
+ + module.getName() + " cannot be NULL!");
}
final List<Type> generatedTypes = new ArrayList<>();
final String basePackageName = moduleNamespaceToPackageName(module);
final List<AugmentationSchema> augmentations = resolveAugmentations(module);
for (final AugmentationSchema augment : augmentations) {
- generatedTypes.addAll(augmentationToGenTypes(basePackageName,
- augment));
+ generatedTypes.addAll(augmentationToGenTypes(basePackageName, augment));
}
return generatedTypes;
}
private List<AugmentationSchema> resolveAugmentations(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getAugmentations() == null) {
throw new IllegalStateException("Augmentations Set cannot be NULL!");
}
final Set<AugmentationSchema> augmentations = module.getAugmentations();
- final List<AugmentationSchema> sortedAugmentations = new ArrayList<>(
- augmentations);
- Collections.sort(sortedAugmentations,
- new Comparator<AugmentationSchema>() {
-
- @Override
- public int compare(AugmentationSchema augSchema1,
- AugmentationSchema augSchema2) {
-
- if (augSchema1.getTargetPath().getPath().size() > augSchema2
- .getTargetPath().getPath().size()) {
- return 1;
- } else if (augSchema1.getTargetPath().getPath().size() < augSchema2
- .getTargetPath().getPath().size()) {
- return -1;
- }
- return 0;
+ final List<AugmentationSchema> sortedAugmentations = new ArrayList<>(augmentations);
+ Collections.sort(sortedAugmentations, new Comparator<AugmentationSchema>() {
- }
- });
+ @Override
+ public int compare(AugmentationSchema augSchema1, AugmentationSchema augSchema2) {
+
+ if (augSchema1.getTargetPath().getPath().size() > augSchema2.getTargetPath().getPath().size()) {
+ return 1;
+ } else if (augSchema1.getTargetPath().getPath().size() < augSchema2.getTargetPath().getPath().size()) {
+ return -1;
+ }
+ return 0;
+
+ }
+ });
return sortedAugmentations;
}
private GeneratedType moduleToDataType(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
- final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(
- module, "Data");
+ final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(module, "Data");
final String basePackageName = moduleNamespaceToPackageName(module);
if (moduleDataTypeBuilder != null) {
final Set<DataSchemaNode> dataNodes = module.getChildNodes();
- resolveDataSchemaNodes(basePackageName, moduleDataTypeBuilder,
- dataNodes);
+ resolveDataSchemaNodes(basePackageName, moduleDataTypeBuilder, dataNodes);
}
return moduleDataTypeBuilder.toInstance();
}
private List<Type> allRPCMethodsToGenType(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
}
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of "
- + "RPC Method Definitions in module " + module.getName()
- + " cannot be NULL!");
+ throw new IllegalArgumentException("Reference to Set of RPC Method Definitions in module "
+ + module.getName() + " cannot be NULL!");
}
final String basePackageName = moduleNamespaceToPackageName(module);
final Set<RpcDefinition> rpcDefinitions = module.getRpcs();
final List<Type> genRPCTypes = new ArrayList<>();
- final GeneratedTypeBuilder interfaceBuilder = moduleTypeBuilder(module,
- "Service");
+ final GeneratedTypeBuilder interfaceBuilder = moduleTypeBuilder(module, "Service");
final Type future = Types.typeForClass(Future.class);
for (final RpcDefinition rpc : rpcDefinitions) {
if (rpc != null) {
- String rpcName = parseToClassName(rpc.getQName()
- .getLocalName());
- MethodSignatureBuilder method = interfaceBuilder
- .addMethod(rpcName);
+ String rpcName = parseToClassName(rpc.getQName().getLocalName());
+ MethodSignatureBuilder method = interfaceBuilder.addMethod(rpcName);
final List<DataNodeIterator> rpcInOut = new ArrayList<>();
if (input != null) {
rpcInOut.add(new DataNodeIterator(input));
- GeneratedTypeBuilder inType = addRawInterfaceDefinition(
- basePackageName, input, rpcName);
+ GeneratedTypeBuilder inType = addRawInterfaceDefinition(basePackageName, input, rpcName);
resolveDataSchemaNodes(basePackageName, inType, input.getChildNodes());
Type inTypeInstance = inType.toInstance();
genRPCTypes.add(inTypeInstance);
if (output != null) {
rpcInOut.add(new DataNodeIterator(output));
- GeneratedTypeBuilder outType = addRawInterfaceDefinition(
- basePackageName, output, rpcName);
+ GeneratedTypeBuilder outType = addRawInterfaceDefinition(basePackageName, output, rpcName);
resolveDataSchemaNodes(basePackageName, outType, output.getChildNodes());
outTypeInstance = outType.toInstance();
genRPCTypes.add(outTypeInstance);
}
- final Type rpcRes = Types.parameterizedTypeFor(
- Types.typeForClass(RpcResult.class), outTypeInstance);
+ final Type rpcRes = Types.parameterizedTypeFor(Types.typeForClass(RpcResult.class), outTypeInstance);
method.setReturnType(Types.parameterizedTypeFor(future, rpcRes));
for (DataNodeIterator it : rpcInOut) {
List<ContainerSchemaNode> nContainers = it.allContainers();
if ((nContainers != null) && !nContainers.isEmpty()) {
for (final ContainerSchemaNode container : nContainers) {
- genRPCTypes.add(containerToGenType(basePackageName,
- container));
+ genRPCTypes.add(containerToGenType(basePackageName, container));
}
}
List<ListSchemaNode> nLists = it.allLists();
if ((nLists != null) && !nLists.isEmpty()) {
for (final ListSchemaNode list : nLists) {
- genRPCTypes.addAll(listToGenType(basePackageName,
- list));
+ genRPCTypes.addAll(listToGenType(basePackageName, list));
}
}
}
private List<Type> allNotificationsToGenType(final Module module) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
if (module.getName() == null) {
}
if (module.getChildNodes() == null) {
- throw new IllegalArgumentException("Reference to Set of "
- + "Notification Definitions in module " + module.getName()
- + " cannot be NULL!");
+ throw new IllegalArgumentException("Reference to Set of Notification Definitions in module "
+ + module.getName() + " cannot be NULL!");
}
final String basePackageName = moduleNamespaceToPackageName(module);
final List<Type> genNotifyTypes = new ArrayList<>();
- final Set<NotificationDefinition> notifications = module
- .getNotifications();
+ final Set<NotificationDefinition> notifications = module.getNotifications();
for (final NotificationDefinition notification : notifications) {
if (notification != null) {
// Containers
for (ContainerSchemaNode node : it.allContainers()) {
- genNotifyTypes
- .add(containerToGenType(basePackageName, node));
+ genNotifyTypes.add(containerToGenType(basePackageName, node));
}
// Lists
for (ListSchemaNode node : it.allLists()) {
genNotifyTypes.addAll(listToGenType(basePackageName, node));
}
- final GeneratedTypeBuilder notificationTypeBuilder = addRawInterfaceDefinition(
- basePackageName, notification);
- notificationTypeBuilder.addImplementsType(Types
- .typeForClass(Notification.class));
+ final GeneratedTypeBuilder notificationTypeBuilder = addDefaultInterfaceDefinition(basePackageName,
+ notification);
+ notificationTypeBuilder.addImplementsType(Types.typeForClass(Notification.class));
// Notification object
- resolveDataSchemaNodes(basePackageName,
- notificationTypeBuilder, notification.getChildNodes());
+ resolveDataSchemaNodes(basePackageName, notificationTypeBuilder, notification.getChildNodes());
genNotifyTypes.add(notificationTypeBuilder.toInstance());
}
}
return genNotifyTypes;
}
- private List<Type> allIdentitiesToGenTypes(final Module module,
- final SchemaContext context) {
- List<Type> genTypes = new ArrayList<Type>();
+ private List<Type> allIdentitiesToGenTypes(final Module module, final SchemaContext context) {
+ List<Type> genTypes = new ArrayList<>();
final Set<IdentitySchemaNode> schemaIdentities = module.getIdentities();
if (schemaIdentities != null && !schemaIdentities.isEmpty()) {
for (final IdentitySchemaNode identity : schemaIdentities) {
- genTypes.add(identityToGenType(basePackageName, identity,
- context));
+ genTypes.add(identityToGenType(basePackageName, identity, context));
}
}
return genTypes;
}
- private GeneratedType identityToGenType(final String basePackageName,
- IdentitySchemaNode identity, SchemaContext context) {
+ private GeneratedType identityToGenType(final String basePackageName, final IdentitySchemaNode identity,
+ final SchemaContext context) {
if (identity == null) {
return null;
}
- final String packageName = packageNameForGeneratedType(basePackageName,
- identity.getPath());
-
- final String genTypeName = parseToClassName(identity.getQName()
- .getLocalName());
- final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(
- packageName, genTypeName);
+ final String packageName = packageNameForGeneratedType(basePackageName, identity.getPath());
+ final String genTypeName = parseToClassName(identity.getQName().getLocalName());
+ final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(packageName, genTypeName);
IdentitySchemaNode baseIdentity = identity.getBaseIdentity();
if (baseIdentity != null) {
- Module baseIdentityParentModule = SchemaContextUtil.findParentModule(
- context, baseIdentity);
+ Module baseIdentityParentModule = SchemaContextUtil.findParentModule(context, baseIdentity);
final String returnTypePkgName = moduleNamespaceToPackageName(baseIdentityParentModule);
- final String returnTypeName = parseToClassName(baseIdentity
- .getQName().getLocalName());
+ final String returnTypeName = parseToClassName(baseIdentity.getQName().getLocalName());
- GeneratedTransferObject gto = new GeneratedTOBuilderImpl(
- returnTypePkgName, returnTypeName).toInstance();
+ GeneratedTransferObject gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName).toInstance();
newType.setExtendsType(gto);
} else {
newType.setExtendsType(Types.getBaseIdentityTO());
return newType.toInstance();
}
- private List<Type> allGroupingsToGenTypes(Module module) {
+ private List<Type> allGroupingsToGenTypes(final Module module) {
final List<Type> genTypes = new ArrayList<>();
final String basePackageName = moduleNamespaceToPackageName(module);
- Set<GroupingDefinition> groupings = module.getGroupings();
+ final Set<GroupingDefinition> groupings = module.getGroupings();
if (groupings != null && !groupings.isEmpty()) {
for (final GroupingDefinition grouping : groupings) {
genTypes.add(groupingToGenType(basePackageName, grouping));
return genTypes;
}
- private GeneratedType groupingToGenType(final String basePackageName,
- GroupingDefinition grouping) {
+ private GeneratedType groupingToGenType(final String basePackageName, GroupingDefinition grouping) {
if (grouping == null) {
return null;
}
- final String packageName = packageNameForGeneratedType(basePackageName,
- grouping.getPath());
+ final String packageName = packageNameForGeneratedType(basePackageName, grouping.getPath());
final Set<DataSchemaNode> schemaNodes = grouping.getChildNodes();
- final GeneratedTypeBuilder typeBuilder = addRawInterfaceDefinition(
- packageName, grouping);
+ final GeneratedTypeBuilder typeBuilder = addDefaultInterfaceDefinition(packageName, grouping);
resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes);
return typeBuilder.toInstance();
}
- private EnumTypeDefinition enumTypeDefFromExtendedType(
- final TypeDefinition<?> typeDefinition) {
+ private EnumTypeDefinition enumTypeDefFromExtendedType(final TypeDefinition<?> typeDefinition) {
if (typeDefinition != null) {
if (typeDefinition.getBaseType() instanceof EnumTypeDefinition) {
return (EnumTypeDefinition) typeDefinition.getBaseType();
return null;
}
- private EnumBuilder resolveInnerEnumFromTypeDefinition(
- final EnumTypeDefinition enumTypeDef, final String enumName,
+ private EnumBuilder resolveInnerEnumFromTypeDefinition(final EnumTypeDefinition enumTypeDef, final String enumName,
final GeneratedTypeBuilder typeBuilder) {
- if ((enumTypeDef != null) && (typeBuilder != null)
- && (enumTypeDef.getQName() != null)
+ if ((enumTypeDef != null) && (typeBuilder != null) && (enumTypeDef.getQName() != null)
&& (enumTypeDef.getQName().getLocalName() != null)) {
final String enumerationName = parseToClassName(enumName);
- final EnumBuilder enumBuilder = typeBuilder
- .addEnumeration(enumerationName);
+ final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumerationName);
if (enumBuilder != null) {
final List<EnumPair> enums = enumTypeDef.getValues();
int listIndex = 0;
for (final EnumPair enumPair : enums) {
if (enumPair != null) {
- final String enumPairName = parseToClassName(enumPair
- .getName());
+ final String enumPairName = parseToClassName(enumPair.getName());
Integer enumPairValue = enumPair.getValue();
if (enumPairValue == null) {
return null;
}
- private GeneratedTypeBuilder moduleTypeBuilder(final Module module,
- final String postfix) {
+ private GeneratedTypeBuilder moduleTypeBuilder(final Module module, final String postfix) {
if (module == null) {
- throw new IllegalArgumentException(
- "Module reference cannot be NULL!");
+ throw new IllegalArgumentException("Module reference cannot be NULL!");
}
String packageName = moduleNamespaceToPackageName(module);
final String moduleName = parseToClassName(module.getName()) + postfix;
}
- private List<Type> augmentationToGenTypes(final String augmentPackageName,
- final AugmentationSchema augSchema) {
+ private List<Type> augmentationToGenTypes(final String augmentPackageName, final AugmentationSchema augSchema) {
if (augmentPackageName == null) {
throw new IllegalArgumentException("Package Name cannot be NULL!");
}
if (augSchema == null) {
- throw new IllegalArgumentException(
- "Augmentation Schema cannot be NULL!");
+ throw new IllegalArgumentException("Augmentation Schema cannot be NULL!");
}
if (augSchema.getTargetPath() == null) {
- throw new IllegalStateException(
- "Augmentation Schema does not contain Target Path (Target Path is NULL).");
+ throw new IllegalStateException("Augmentation Schema does not contain Target Path (Target Path is NULL).");
}
final List<Type> genTypes = new ArrayList<>();
// EVERY augmented interface will extends Augmentation<T> interface
// and DataObject interface!!!
final SchemaPath targetPath = augSchema.getTargetPath();
- final DataSchemaNode targetSchemaNode = findDataSchemaNode(
- schemaContext, targetPath);
+ final DataSchemaNode targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
if ((targetSchemaNode != null) && (targetSchemaNode.getQName() != null)
&& (targetSchemaNode.getQName().getLocalName() != null)) {
- final Module targetModule = findParentModule(schemaContext,
- targetSchemaNode);
+ final Module targetModule = findParentModule(schemaContext, targetSchemaNode);
final String targetBasePackage = moduleNamespaceToPackageName(targetModule);
- final String targetPackageName = packageNameForGeneratedType(
- targetBasePackage, targetSchemaNode.getPath());
+ final String targetPackageName = packageNameForGeneratedType(targetBasePackage, targetSchemaNode.getPath());
- final String targetSchemaNodeName = targetSchemaNode.getQName()
- .getLocalName();
+ final String targetSchemaNodeName = targetSchemaNode.getQName().getLocalName();
final Set<DataSchemaNode> augChildNodes = augSchema.getChildNodes();
- final GeneratedTypeBuilder augTypeBuilder = addRawAugmentGenTypeDefinition(
- augmentPackageName, targetPackageName,
- targetSchemaNodeName, augSchema);
+ final GeneratedTypeBuilder augTypeBuilder = addRawAugmentGenTypeDefinition(augmentPackageName,
+ targetPackageName, targetSchemaNodeName, augSchema);
if (augTypeBuilder != null) {
genTypes.add(augTypeBuilder.toInstance());
}
- genTypes.addAll(augmentationBodyToGenTypes(augmentPackageName,
- augChildNodes));
+ genTypes.addAll(augmentationBodyToGenTypes(augmentPackageName, augChildNodes));
}
return genTypes;
}
- private GeneratedTypeBuilder addRawAugmentGenTypeDefinition(
- final String augmentPackageName, final String targetPackageName,
- final String targetSchemaNodeName,
- final AugmentationSchema augSchema) {
+ private GeneratedTypeBuilder addRawAugmentGenTypeDefinition(final String augmentPackageName,
+ final String targetPackageName, final String targetSchemaNodeName, final AugmentationSchema augSchema) {
final String targetTypeName = parseToClassName(targetSchemaNodeName);
- Map<String, GeneratedTypeBuilder> augmentBuilders = genTypeBuilders
- .get(augmentPackageName);
+ Map<String, GeneratedTypeBuilder> augmentBuilders = genTypeBuilders.get(augmentPackageName);
if (augmentBuilders == null) {
augmentBuilders = new HashMap<>();
genTypeBuilders.put(augmentPackageName, augmentBuilders);
}
- final String augTypeName = augGenTypeName(augmentBuilders,
- targetTypeName);
- final Type targetTypeRef = new ReferencedTypeImpl(targetPackageName,
- targetTypeName);
+ final String augTypeName = augGenTypeName(augmentBuilders, targetTypeName);
+ final Type targetTypeRef = new ReferencedTypeImpl(targetPackageName, targetTypeName);
final Set<DataSchemaNode> augChildNodes = augSchema.getChildNodes();
- final GeneratedTypeBuilder augTypeBuilder = new GeneratedTypeBuilderImpl(
- augmentPackageName, augTypeName);
+ final GeneratedTypeBuilder augTypeBuilder = new GeneratedTypeBuilderImpl(augmentPackageName, augTypeName);
augTypeBuilder.addImplementsType(Types.DATA_OBJECT);
- augTypeBuilder.addImplementsType(Types
- .augmentationTypeFor(targetTypeRef));
+ augTypeBuilder.addImplementsType(Types.augmentationTypeFor(targetTypeRef));
- augSchemaNodeToMethods(augmentPackageName, augTypeBuilder,
- augChildNodes);
+ augSchemaNodeToMethods(augmentPackageName, augTypeBuilder, augChildNodes);
augmentBuilders.put(augTypeName, augTypeBuilder);
return augTypeBuilder;
}
- private List<Type> augmentationBodyToGenTypes(
- final String augBasePackageName,
+ private List<Type> augmentationBodyToGenTypes(final String augBasePackageName,
final Set<DataSchemaNode> augChildNodes) {
final List<Type> genTypes = new ArrayList<>();
final List<DataNodeIterator> augSchemaIts = new ArrayList<>();
for (final DataSchemaNode childNode : augChildNodes) {
if (childNode instanceof DataNodeContainer) {
- augSchemaIts.add(new DataNodeIterator(
- (DataNodeContainer) childNode));
+ augSchemaIts.add(new DataNodeIterator((DataNodeContainer) childNode));
if (childNode instanceof ContainerSchemaNode) {
- genTypes.add(containerToGenType(augBasePackageName,
- (ContainerSchemaNode) childNode));
+ genTypes.add(containerToGenType(augBasePackageName, (ContainerSchemaNode) childNode));
} else if (childNode instanceof ListSchemaNode) {
- genTypes.addAll(listToGenType(augBasePackageName,
- (ListSchemaNode) childNode));
+ genTypes.addAll(listToGenType(augBasePackageName, (ListSchemaNode) childNode));
}
}
}
if ((augContainers != null) && !augContainers.isEmpty()) {
for (final ContainerSchemaNode container : augContainers) {
- genTypes.add(containerToGenType(augBasePackageName,
- container));
+ genTypes.add(containerToGenType(augBasePackageName, container));
}
}
if ((augLists != null) && !augLists.isEmpty()) {
return genTypes;
}
- private String augGenTypeName(
- final Map<String, GeneratedTypeBuilder> builders,
- final String genTypeName) {
+ private String augGenTypeName(final Map<String, GeneratedTypeBuilder> builders, final String genTypeName) {
String augTypeName = genTypeName;
int index = 1;
return augTypeName;
}
- private GeneratedType containerToGenType(final String basePackageName,
- ContainerSchemaNode containerNode) {
+ private GeneratedType containerToGenType(final String basePackageName, ContainerSchemaNode containerNode) {
if (containerNode == null) {
return null;
}
- final String packageName = packageNameForGeneratedType(basePackageName,
- containerNode.getPath());
+ final String packageName = packageNameForGeneratedType(basePackageName, containerNode.getPath());
final Set<DataSchemaNode> schemaNodes = containerNode.getChildNodes();
- final GeneratedTypeBuilder typeBuilder = addRawInterfaceDefinition(
- packageName, containerNode);
+ final GeneratedTypeBuilder typeBuilder = addDefaultInterfaceDefinition(packageName, containerNode);
resolveDataSchemaNodes(basePackageName, typeBuilder, schemaNodes);
return typeBuilder.toInstance();
}
- private GeneratedTypeBuilder resolveDataSchemaNodes(
- final String basePackageName,
- final GeneratedTypeBuilder typeBuilder,
- final Set<DataSchemaNode> schemaNodes) {
-
+ private GeneratedTypeBuilder resolveDataSchemaNodes(final String basePackageName,
+ final GeneratedTypeBuilder typeBuilder, final Set<DataSchemaNode> schemaNodes) {
if ((schemaNodes != null) && (typeBuilder != null)) {
for (final DataSchemaNode schemaNode : schemaNodes) {
if (schemaNode.isAugmenting()) {
continue;
}
- addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode,
- typeBuilder);
+ addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder);
}
}
return typeBuilder;
}
- private GeneratedTypeBuilder augSchemaNodeToMethods(
- final String basePackageName,
- final GeneratedTypeBuilder typeBuilder,
- final Set<DataSchemaNode> schemaNodes) {
-
+ private GeneratedTypeBuilder augSchemaNodeToMethods(final String basePackageName,
+ final GeneratedTypeBuilder typeBuilder, final Set<DataSchemaNode> schemaNodes) {
if ((schemaNodes != null) && (typeBuilder != null)) {
for (final DataSchemaNode schemaNode : schemaNodes) {
if (schemaNode.isAugmenting()) {
- addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode,
- typeBuilder);
+ addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder);
}
}
}
return typeBuilder;
}
- private void addSchemaNodeToBuilderAsMethod(final String basePackageName,
- final DataSchemaNode schemaNode,
+ private void addSchemaNodeToBuilderAsMethod(final String basePackageName, final DataSchemaNode schemaNode,
final GeneratedTypeBuilder typeBuilder) {
if (schemaNode != null && typeBuilder != null) {
if (schemaNode instanceof LeafSchemaNode) {
- resolveLeafSchemaNodeAsMethod(typeBuilder,
- (LeafSchemaNode) schemaNode);
+ resolveLeafSchemaNodeAsMethod(typeBuilder, (LeafSchemaNode) schemaNode);
} else if (schemaNode instanceof LeafListSchemaNode) {
- resolveLeafListSchemaNode(typeBuilder,
- (LeafListSchemaNode) schemaNode);
+ resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) schemaNode);
} else if (schemaNode instanceof ContainerSchemaNode) {
- resolveContainerSchemaNode(basePackageName, typeBuilder,
- (ContainerSchemaNode) schemaNode);
+ resolveContainerSchemaNode(basePackageName, typeBuilder, (ContainerSchemaNode) schemaNode);
} else if (schemaNode instanceof ListSchemaNode) {
- resolveListSchemaNode(basePackageName, typeBuilder,
- (ListSchemaNode) schemaNode);
+ resolveListSchemaNode(basePackageName, typeBuilder, (ListSchemaNode) schemaNode);
+ } else if (schemaNode instanceof ChoiceNode) {
+ resolveChoiceSchemaNode(basePackageName, typeBuilder, (ChoiceNode) schemaNode);
}
}
}
- private boolean resolveLeafSchemaNodeAsMethod(
- final GeneratedTypeBuilder typeBuilder, final LeafSchemaNode leaf) {
+ private void resolveChoiceSchemaNode(final String basePackageName, final GeneratedTypeBuilder typeBuilder,
+ final ChoiceNode choiceNode) {
+ if (basePackageName == null) {
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+ }
+ if (typeBuilder == null) {
+ throw new IllegalArgumentException("Generated Type Builder cannot be NULL!");
+ }
+ if (choiceNode == null) {
+ throw new IllegalArgumentException("Choice Schema Node cannot be NULL!");
+ }
+
+ final String choiceName = choiceNode.getQName().getLocalName();
+ if (choiceName != null) {
+ final String packageName = packageNameForGeneratedType(basePackageName, choiceNode.getPath());
+ final GeneratedTypeBuilder choiceType = addDefaultInterfaceDefinition(packageName, choiceNode);
+ constructGetter(typeBuilder, choiceName, choiceNode.getDescription(), choiceType);
+ }
+ }
+
+ private List<GeneratedType> choiceToGeneratedType(final String basePackageName, final ChoiceNode choiceNode) {
+ if (basePackageName == null) {
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+ }
+ if (choiceNode == null) {
+ throw new IllegalArgumentException("Choice Schema Node cannot be NULL!");
+ }
+
+ final List<GeneratedType> generatedTypes = new ArrayList<>();
+ final String packageName = packageNameForGeneratedType(basePackageName, choiceNode.getPath());
+ final GeneratedTypeBuilder choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode);
+ choiceTypeBuilder.addImplementsType(Types.DATA_OBJECT);
+ final GeneratedType choiceType = choiceTypeBuilder.toInstance();
+
+ generatedTypes.add(choiceType);
+ final Set<ChoiceCaseNode> caseNodes = choiceNode.getCases();
+ if ((caseNodes != null) && !caseNodes.isEmpty()) {
+ generatedTypes.addAll(generateTypesFromChoiceCases(basePackageName, choiceType, caseNodes));
+ }
+ return generatedTypes;
+ }
+
+ private List<GeneratedType> generateTypesFromChoiceCases(final String basePackageName, final Type refChoiceType,
+ final Set<ChoiceCaseNode> caseNodes) {
+ if (basePackageName == null) {
+ throw new IllegalArgumentException("Base Package Name cannot be NULL!");
+ }
+ if (refChoiceType == null) {
+ throw new IllegalArgumentException("Referenced Choice Type cannot be NULL!");
+ }
+ if (caseNodes == null) {
+ throw new IllegalArgumentException("Set of Choice Case Nodes cannot be NULL!");
+ }
+
+ final List<GeneratedType> generatedTypes = new ArrayList<>();
+ for (final ChoiceCaseNode caseNode : caseNodes) {
+ if (caseNode != null) {
+ final String packageName = packageNameForGeneratedType(basePackageName, caseNode.getPath());
+ final GeneratedTypeBuilder caseTypeBuilder = addDefaultInterfaceDefinition(packageName, caseNode);
+ caseTypeBuilder.addImplementsType(refChoiceType);
+
+ final Set<DataSchemaNode> childNodes = caseNode.getChildNodes();
+ if (childNodes != null) {
+ resolveDataSchemaNodes(basePackageName, caseTypeBuilder, childNodes);
+ }
+ generatedTypes.add(caseTypeBuilder.toInstance());
+ }
+ }
+
+ return generatedTypes;
+ }
+
+ private boolean resolveLeafSchemaNodeAsMethod(final GeneratedTypeBuilder typeBuilder, final LeafSchemaNode leaf) {
if ((leaf != null) && (typeBuilder != null)) {
final String leafName = leaf.getQName().getLocalName();
String leafDesc = leaf.getDescription();
Type returnType = null;
if (!(typeDef instanceof EnumTypeDefinition)) {
- returnType = typeProvider
- .javaTypeForSchemaDefinitionType(typeDef);
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef);
} else {
final EnumTypeDefinition enumTypeDef = enumTypeDefFromExtendedType(typeDef);
- final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(
- enumTypeDef, leafName, typeBuilder);
+ final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leafName,
+ typeBuilder);
if (enumBuilder != null) {
- returnType = new ReferencedTypeImpl(
- enumBuilder.getPackageName(),
- enumBuilder.getName());
+ returnType = new ReferencedTypeImpl(enumBuilder.getPackageName(), enumBuilder.getName());
}
- ((TypeProviderImpl) typeProvider).putReferencedType(
- leaf.getPath(), returnType);
+ ((TypeProviderImpl) typeProvider).putReferencedType(leaf.getPath(), returnType);
}
if (returnType != null) {
constructGetter(typeBuilder, leafName, leafDesc, returnType);
if (!leaf.isConfiguration()) {
- constructSetter(typeBuilder, leafName, leafDesc,
- returnType);
+ constructSetter(typeBuilder, leafName, leafDesc, returnType);
}
return true;
}
return false;
}
- private boolean resolveLeafSchemaNodeAsProperty(
- final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf,
+ private boolean resolveLeafSchemaNodeAsProperty(final GeneratedTOBuilder toBuilder, final LeafSchemaNode leaf,
boolean isReadOnly) {
if ((leaf != null) && (toBuilder != null)) {
final String leafName = leaf.getQName().getLocalName();
final TypeDefinition<?> typeDef = leaf.getType();
// TODO: properly resolve enum types
- final Type returnType = typeProvider
- .javaTypeForSchemaDefinitionType(typeDef);
+ final Type returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef);
if (returnType != null) {
- final GeneratedPropertyBuilder propBuilder = toBuilder
- .addProperty(parseToClassName(leafName));
+ final GeneratedPropertyBuilder propBuilder = toBuilder.addProperty(parseToClassName(leafName));
propBuilder.setReadOnly(isReadOnly);
propBuilder.setReturnType(returnType);
return false;
}
- private boolean resolveLeafListSchemaNode(
- final GeneratedTypeBuilder typeBuilder,
- final LeafListSchemaNode node) {
+ private boolean resolveLeafListSchemaNode(final GeneratedTypeBuilder typeBuilder, final LeafListSchemaNode node) {
if ((node != null) && (typeBuilder != null)) {
final String nodeName = node.getQName().getLocalName();
String nodeDesc = node.getDescription();
if (nodeName != null) {
final TypeDefinition<?> type = node.getType();
- final Type listType = Types.listTypeFor(typeProvider
- .javaTypeForSchemaDefinitionType(type));
+ final Type listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type));
constructGetter(typeBuilder, nodeName, nodeDesc, listType);
if (!node.isConfiguration()) {
return false;
}
- private boolean resolveContainerSchemaNode(final String basePackageName,
- final GeneratedTypeBuilder typeBuilder,
+ private boolean resolveContainerSchemaNode(final String basePackageName, final GeneratedTypeBuilder typeBuilder,
final ContainerSchemaNode containerNode) {
if ((containerNode != null) && (typeBuilder != null)) {
final String nodeName = containerNode.getQName().getLocalName();
if (nodeName != null) {
- final String packageName = packageNameForGeneratedType(
- basePackageName, containerNode.getPath());
+ final String packageName = packageNameForGeneratedType(basePackageName, containerNode.getPath());
- final GeneratedTypeBuilder rawGenType = addRawInterfaceDefinition(
- packageName, containerNode);
- constructGetter(typeBuilder, nodeName, "", rawGenType);
+ final GeneratedTypeBuilder rawGenType = addDefaultInterfaceDefinition(packageName, containerNode);
+ constructGetter(typeBuilder, nodeName, containerNode.getDescription(), rawGenType);
return true;
}
return false;
}
- private boolean resolveListSchemaNode(final String basePackageName,
- final GeneratedTypeBuilder typeBuilder,
+ private boolean resolveListSchemaNode(final String basePackageName, final GeneratedTypeBuilder typeBuilder,
final ListSchemaNode schemaNode) {
if ((schemaNode != null) && (typeBuilder != null)) {
final String listName = schemaNode.getQName().getLocalName();
if (listName != null) {
- final String packageName = packageNameForGeneratedType(
- basePackageName, schemaNode.getPath());
- final GeneratedTypeBuilder rawGenType = addRawInterfaceDefinition(
- packageName, schemaNode);
- constructGetter(typeBuilder, listName, "",
- Types.listTypeFor(rawGenType));
+ final String packageName = packageNameForGeneratedType(basePackageName, schemaNode.getPath());
+ final GeneratedTypeBuilder rawGenType = addDefaultInterfaceDefinition(packageName, schemaNode);
+ constructGetter(typeBuilder, listName, schemaNode.getDescription(), Types.listTypeFor(rawGenType));
if (!schemaNode.isConfiguration()) {
- constructSetter(typeBuilder, listName, "",
- Types.listTypeFor(rawGenType));
+ constructSetter(typeBuilder, listName, schemaNode.getDescription(), Types.listTypeFor(rawGenType));
}
return true;
}
return false;
}
- private GeneratedTypeBuilder addRawInterfaceDefinition(
- final String packageName, final SchemaNode schemaNode) {
+ /**
+ * Method instantiates new Generated Type Builder and sets the implements definitions of Data Object and
+ * Augmentable.
+ *
+ * @param packageName Generated Type Package Name
+ * @param schemaNode Schema Node definition
+ * @return Generated Type Builder instance for Schema Node definition
+ */
+ private GeneratedTypeBuilder addDefaultInterfaceDefinition(final String packageName, final SchemaNode schemaNode) {
+ final GeneratedTypeBuilder builder = addRawInterfaceDefinition(packageName, schemaNode, "");
+ builder.addImplementsType(Types.DATA_OBJECT);
+ builder.addImplementsType(Types.augmentableTypeFor(builder));
+ return builder;
+ }
+
+ /**
+ *
+ * @param packageName
+ * @param schemaNode
+ * @return
+ */
+ private GeneratedTypeBuilder addRawInterfaceDefinition(final String packageName, final SchemaNode schemaNode) {
return addRawInterfaceDefinition(packageName, schemaNode, "");
}
- private GeneratedTypeBuilder addRawInterfaceDefinition(
- final String packageName, final SchemaNode schemaNode,
+ private GeneratedTypeBuilder addRawInterfaceDefinition(final String packageName, final SchemaNode schemaNode,
final String prefix) {
if (schemaNode == null) {
- return null;
+ throw new IllegalArgumentException("Data Schema Node cannot be NULL!");
+ }
+ if (packageName == null) {
+ throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!");
+ }
+ if (schemaNode.getQName() == null) {
+ throw new IllegalArgumentException("QName for Data Schema Node cannot be NULL!");
}
-
final String schemaNodeName = schemaNode.getQName().getLocalName();
+ if (schemaNodeName == null) {
+ throw new IllegalArgumentException("Local Name of QName for Data Schema Node cannot be NULL!");
+ }
- if ((packageName != null) && (schemaNodeName != null)) {
- final String genTypeName = prefix + parseToClassName(schemaNodeName)
- ;
- final GeneratedTypeBuilder newType = new GeneratedTypeBuilderImpl(
- packageName, genTypeName);
-
- newType.addImplementsType(Types.DATA_OBJECT);
- newType.addImplementsType(Types.augmentableTypeFor(newType));
+ final String genTypeName;
+ if (prefix == null) {
+ genTypeName = parseToClassName(schemaNodeName);
+ } else {
+ genTypeName = prefix + parseToClassName(schemaNodeName);
+ }
- if (!genTypeBuilders.containsKey(packageName)) {
- final Map<String, GeneratedTypeBuilder> builders = new HashMap<>();
+ final GeneratedTypeBuilder newType = new GeneratedTypeBuilderImpl(packageName, genTypeName);
+ if (!genTypeBuilders.containsKey(packageName)) {
+ final Map<String, GeneratedTypeBuilder> builders = new HashMap<>();
+ builders.put(genTypeName, newType);
+ genTypeBuilders.put(packageName, builders);
+ } else {
+ final Map<String, GeneratedTypeBuilder> builders = genTypeBuilders.get(packageName);
+ if (!builders.containsKey(genTypeName)) {
builders.put(genTypeName, newType);
- genTypeBuilders.put(packageName, builders);
- } else {
- final Map<String, GeneratedTypeBuilder> builders = genTypeBuilders
- .get(packageName);
- if (!builders.containsKey(genTypeName)) {
- builders.put(genTypeName, newType);
- }
}
- return newType;
}
- return null;
+ return newType;
}
private String getterMethodName(final String methodName) {
return method.toString();
}
- private MethodSignatureBuilder constructGetter(
- final GeneratedTypeBuilder interfaceBuilder,
- final String schemaNodeName, final String comment,
- final Type returnType) {
- final MethodSignatureBuilder getMethod = interfaceBuilder
- .addMethod(getterMethodName(schemaNodeName));
+ private MethodSignatureBuilder constructGetter(final GeneratedTypeBuilder interfaceBuilder,
+ final String schemaNodeName, final String comment, final Type returnType) {
+ final MethodSignatureBuilder getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName));
getMethod.setComment(comment);
getMethod.setReturnType(returnType);
return getMethod;
}
- private MethodSignatureBuilder constructSetter(
- final GeneratedTypeBuilder interfaceBuilder,
- final String schemaNodeName, final String comment,
- final Type parameterType) {
- final MethodSignatureBuilder setMethod = interfaceBuilder
- .addMethod(setterMethodName(schemaNodeName));
+ private MethodSignatureBuilder constructSetter(final GeneratedTypeBuilder interfaceBuilder,
+ final String schemaNodeName, final String comment, final Type parameterType) {
+ final MethodSignatureBuilder setMethod = interfaceBuilder.addMethod(setterMethodName(schemaNodeName));
setMethod.setComment(comment);
- setMethod.addParameter(parameterType,
- parseToValidParamName(schemaNodeName));
+ setMethod.addParameter(parameterType, parseToValidParamName(schemaNodeName));
setMethod.setReturnType(Types.voidType());
return setMethod;
}
- private List<Type> listToGenType(final String basePackageName,
- final ListSchemaNode list) {
+ private List<Type> listToGenType(final String basePackageName, final ListSchemaNode list) {
if (basePackageName == null) {
- throw new IllegalArgumentException(
- "Package Name for Generated Type cannot be NULL!");
+ throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!");
}
if (list == null) {
- throw new IllegalArgumentException(
- "List Schema Node cannot be NULL!");
+ throw new IllegalArgumentException("List Schema Node cannot be NULL!");
}
- final String packageName = packageNameForGeneratedType(basePackageName,
- list.getPath());
- final GeneratedTypeBuilder typeBuilder = resolveListTypeBuilder(
- packageName, list);
+ final String packageName = packageNameForGeneratedType(basePackageName, list.getPath());
+ final GeneratedTypeBuilder typeBuilder = resolveListTypeBuilder(packageName, list);
final List<String> listKeys = listKeys(list);
- GeneratedTOBuilder genTOBuilder = resolveListKeyTOBuilder(packageName,
- list, listKeys);
+ GeneratedTOBuilder genTOBuilder = resolveListKeyTOBuilder(packageName, list, listKeys);
final Set<DataSchemaNode> schemaNodes = list.getChildNodes();
if (schemaNode.isAugmenting()) {
continue;
}
- addSchemaNodeToListBuilders(basePackageName, schemaNode,
- typeBuilder, genTOBuilder, listKeys);
+ addSchemaNodeToListBuilders(basePackageName, schemaNode, typeBuilder, genTOBuilder, listKeys);
}
return typeBuildersToGenTypes(typeBuilder, genTOBuilder);
}
- private void addSchemaNodeToListBuilders(final String basePackageName,
- final DataSchemaNode schemaNode,
- final GeneratedTypeBuilder typeBuilder,
- final GeneratedTOBuilder genTOBuilder, final List<String> listKeys) {
+ private void addSchemaNodeToListBuilders(final String basePackageName, final DataSchemaNode schemaNode,
+ final GeneratedTypeBuilder typeBuilder, final GeneratedTOBuilder genTOBuilder, final List<String> listKeys) {
if (schemaNode == null) {
- throw new IllegalArgumentException(
- "Data Schema Node cannot be NULL!");
+ throw new IllegalArgumentException("Data Schema Node cannot be NULL!");
}
if (typeBuilder == null) {
- throw new IllegalArgumentException(
- "Generated Type Builder cannot be NULL!");
+ throw new IllegalArgumentException("Generated Type Builder cannot be NULL!");
}
if (schemaNode instanceof LeafSchemaNode) {
resolveLeafSchemaNodeAsProperty(genTOBuilder, leaf, true);
}
} else if (schemaNode instanceof LeafListSchemaNode) {
- resolveLeafListSchemaNode(typeBuilder,
- (LeafListSchemaNode) schemaNode);
+ resolveLeafListSchemaNode(typeBuilder, (LeafListSchemaNode) schemaNode);
} else if (schemaNode instanceof ContainerSchemaNode) {
- resolveContainerSchemaNode(basePackageName, typeBuilder,
- (ContainerSchemaNode) schemaNode);
+ resolveContainerSchemaNode(basePackageName, typeBuilder, (ContainerSchemaNode) schemaNode);
} else if (schemaNode instanceof ListSchemaNode) {
- resolveListSchemaNode(basePackageName, typeBuilder,
- (ListSchemaNode) schemaNode);
+ resolveListSchemaNode(basePackageName, typeBuilder, (ListSchemaNode) schemaNode);
}
}
- private List<Type> typeBuildersToGenTypes(
- final GeneratedTypeBuilder typeBuilder,
- GeneratedTOBuilder genTOBuilder) {
+ private List<Type> typeBuildersToGenTypes(final GeneratedTypeBuilder typeBuilder, GeneratedTOBuilder genTOBuilder) {
final List<Type> genTypes = new ArrayList<>();
if (typeBuilder == null) {
- throw new IllegalArgumentException(
- "Generated Type Builder cannot be NULL!");
+ throw new IllegalArgumentException("Generated Type Builder cannot be NULL!");
}
if (genTOBuilder != null) {
final GeneratedTransferObject genTO = genTOBuilder.toInstance();
- constructGetter(typeBuilder, genTO.getName(),
- "Returns Primary Key of Yang List Type", genTO);
+ constructGetter(typeBuilder, genTO.getName(), "Returns Primary Key of Yang List Type", genTO);
genTypes.add(genTO);
}
genTypes.add(typeBuilder.toInstance());
* @param list
* @return
*/
- private GeneratedTOBuilder resolveListKey(final String packageName,
- final ListSchemaNode list) {
+ private GeneratedTOBuilder resolveListKey(final String packageName, final ListSchemaNode list) {
final String listName = list.getQName().getLocalName() + "Key";
return schemaNodeToTransferObjectBuilder(packageName, list, listName);
}
- private boolean isPartOfListKey(final LeafSchemaNode leaf,
- final List<String> keys) {
+ private boolean isPartOfListKey(final LeafSchemaNode leaf, final List<String> keys) {
if ((leaf != null) && (keys != null) && (leaf.getQName() != null)) {
final String leafName = leaf.getQName().getLocalName();
if (keys.contains(leafName)) {
return listKeys;
}
- private GeneratedTypeBuilder resolveListTypeBuilder(
- final String packageName, final ListSchemaNode list) {
+ private GeneratedTypeBuilder resolveListTypeBuilder(final String packageName, final ListSchemaNode list) {
if (packageName == null) {
- throw new IllegalArgumentException(
- "Package Name for Generated Type cannot be NULL!");
+ throw new IllegalArgumentException("Package Name for Generated Type cannot be NULL!");
}
if (list == null) {
- throw new IllegalArgumentException(
- "List Schema Node cannot be NULL!");
+ throw new IllegalArgumentException("List Schema Node cannot be NULL!");
}
final String schemaNodeName = list.getQName().getLocalName();
final String genTypeName = parseToClassName(schemaNodeName);
GeneratedTypeBuilder typeBuilder = null;
- final Map<String, GeneratedTypeBuilder> builders = genTypeBuilders
- .get(packageName);
+ final Map<String, GeneratedTypeBuilder> builders = genTypeBuilders.get(packageName);
if (builders != null) {
typeBuilder = builders.get(genTypeName);
}
if (typeBuilder == null) {
- typeBuilder = addRawInterfaceDefinition(packageName, list);
+ typeBuilder = addDefaultInterfaceDefinition(packageName, list);
}
return typeBuilder;
}
- private GeneratedTOBuilder resolveListKeyTOBuilder(
- final String packageName, final ListSchemaNode list,
+ private GeneratedTOBuilder resolveListKeyTOBuilder(final String packageName, final ListSchemaNode list,
final List<String> listKeys) {
GeneratedTOBuilder genTOBuilder = null;
if (listKeys.size() > 0) {
*/
package org.opendaylight.controller.sal.binding.yang.types;
+import org.apache.commons.lang.StringEscapeUtils;
import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
+import org.opendaylight.controller.binding.generator.util.TypeConstants;
import org.opendaylight.controller.binding.generator.util.Types;
import org.opendaylight.controller.binding.generator.util.generated.type.builder.EnumerationBuilderImpl;
import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition.EnumPair;
import org.opendaylight.controller.yang.model.util.ExtendedType;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
genTOBuilder.addEqualsIdentity(genPropBuilder);
genTOBuilder.addHashIdentity(genPropBuilder);
genTOBuilder.addToStringProperty(genPropBuilder);
+ if (javaType == BaseYangTypes.STRING_TYPE) {
+ if (typedef instanceof ExtendedType) {
+ List<PatternConstraint> patternConstraints = ((ExtendedType) typedef).getPatterns();
+ List<String> regularExpressions = new ArrayList<String>();
+ String regEx;
+ String modifiedRegEx;
+ for (PatternConstraint ptrnCons : patternConstraints) {
+ regEx = ptrnCons.getRegularExpression();
+ modifiedRegEx = StringEscapeUtils.escapeJava(regEx);
+ regularExpressions.add(modifiedRegEx);
+ }
+
+ genTOBuilder.addConstant(Types.listTypeFor(BaseYangTypes.STRING_TYPE),
+ TypeConstants.PATTERN_CONSTANT_NAME, regularExpressions);
+ }
+ }
+
return genTOBuilder.toInstance();
}
return null;
}
return genTOBuilder.toInstance();
}
+
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.binding.generator.impl;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+public class ChoiceCaseGenTypesTest {
+
+ private final static List<File> yangModels = new ArrayList<>();
+ private final static String yangModelsFolder = AugmentedTypeTest.class.getResource("/choice-case-type-test-models")
+ .getPath();
+
+ @BeforeClass
+ public static void loadTestResources() {
+ final File augFolder = new File(yangModelsFolder);
+ for (final File fileEntry : augFolder.listFiles()) {
+ if (fileEntry.isFile()) {
+ yangModels.add(fileEntry);
+ }
+ }
+ }
+
+ @Test
+ public void choiceCaseResolvingTypeTest() {
+ final YangModelParser parser = new YangParserImpl();
+ final Set<Module> modules = parser.parseYangModels(yangModels);
+ final SchemaContext context = parser.resolveSchemaContext(modules);
+
+ assertNotNull("context is null", context);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
+ final List<Type> genTypes = bindingGen.generateTypes(context);
+
+ assertNotNull("genTypes is null", genTypes);
+ assertFalse("genTypes is empty", genTypes.isEmpty());
+
+ //Expected 23 types from ietf-netconf-monitoring
+ //Expected 14 types from ietf-yang-types
+ //Expected 14 types from ietf-inet-types
+ }
+}
*/
package org.opendaylight.controller.sal.binding.generator.impl;
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
import org.junit.Test;
import org.opendaylight.controller.binding.generator.util.ReferencedTypeImpl;
import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
public class GenEnumResolvingTest {
private SchemaContext resolveSchemaContextFromFiles(
assertNotNull("Generated Interface cannot contain NULL reference for " +
"Method Signature Definitions!", methods);
- assertEquals("Expected count of method signature definitions is 26",
- 26, methods.size());
+ assertEquals("Expected count of method signature definitions is 21",
+ 21, methods.size());
Enumeration ianaIfType = null;
for (final MethodSignature method : methods) {
if (method.getName().equals("getType")) {
final List<MethodSignature> methods = genInterface.getMethodDefinitions();
assertNotNull("Generated Type Interface cannot contain NULL reference" +
" to Enumeration types!", methods);
- assertEquals("Generated Type Interface MUST contain 7 Methods ",
- 7, methods.size());
+ assertEquals("Generated Type Interface MUST contain 4 Methods ",
+ 4, methods.size());
for (final MethodSignature method : methods) {
if (method.getName().equals("getLinkUpDownTrapEnable")) {
linkUpDownTrapEnable = method.getReturnType();
package org.opendaylight.controller.sal.binding.generator.impl;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.io.File;
import java.util.ArrayList;
import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
-public class GeneretedTypesBitsTest {
+public class GeneratedTypesBitsTest {
- private SchemaContext resolveSchemaContextFromFiles(
- final String... yangFiles) {
+ private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
final YangModelParser parser = new YangParserImpl();
final List<File> inputFiles = new ArrayList<File>();
@Test
public void testGeneretedTypesBitsTest() {
- final String yangTypesPath = getClass().getResource(
- "/simple-bits-demo.yang").getPath();
+ final String yangTypesPath = getClass().getResource("/simple-bits-demo.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
assertTrue(context != null);
for (final Type type : genTypes) {
if (type instanceof GeneratedTransferObject) { // searching for
- // ByteType
+ // ByteType
final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
if (genTO.getName().equals("ByteType")) {
byteTypeFound = true;
- List<GeneratedProperty> genProperties = genTO
- .getProperties();
+ List<GeneratedProperty> genProperties = genTO.getProperties();
classPropertiesNumb = genProperties.size();
genProperties = null;
// interface
// LeafParameterContainer
final GeneratedType genType = (GeneratedType) type;
- if (genType.getName().compareTo("LeafParentContainer") == 0) {
+ if (genType.getName().equals("LeafParentContainer")) {
leafParentFound = true;
// check of methods
methodSignaturesList = genType.getMethodDefinitions();
if (methodSignaturesList != null) {
for (MethodSignature methodSignature : methodSignaturesList) { // loop
- // through
- // all
- // methods
- if (methodSignature.getName().compareTo(
- "getByteLeaf") == 0) {
+ // through
+ // all
+ // methods
+ if (methodSignature.getName().equals("getByteLeaf")) {
getByteLeafMethodFound = true;
- nameReturnParamType = methodSignature
- .getReturnType().getName();
- } else if (methodSignature.getName().compareTo(
- "setByteLeaf") == 0) {
+ nameReturnParamType = methodSignature.getReturnType().getName();
+ } else if (methodSignature.getName().equals("setByteLeaf")) {
setByteLeafMethodFound = true;
- List<Parameter> parameters = methodSignature
- .getParameters();
+ List<Parameter> parameters = methodSignature.getParameters();
setByteLeafMethodParamNum = parameters.size();
for (Parameter parameter : parameters) {
- nameMethodeParamType = parameter.getType()
- .getName();
+ nameMethodeParamType = parameter.getType().getName();
}
}
}
- assertTrue("type >ByteType< wasn't in YANG file", byteTypeFound == true);
+ assertTrue(byteTypeFound);
- assertTrue("Incorrect number of bit properties in class",
- classPropertiesNumb == 8);
+ assertEquals(classPropertiesNumb,8);
- assertTrue("Incorrect number of properties in toString method",
- toStringPropertiesNum == 8);
- assertTrue("Incorrect number of properties in equals method",
- equalPropertiesNum == 8);
- assertTrue("Incorrect number of properties in hash method",
- hashPropertiesNum == 8);
- assertTrue("LeafParameterContainer container wasn't found",
- leafParentFound == true);
+ assertEquals(toStringPropertiesNum,8);
+ assertEquals(equalPropertiesNum,8);
+ assertEquals(hashPropertiesNum,8);
+ assertTrue(leafParentFound);
- assertTrue("No methods were generated", methodSignaturesList != null);
+ assertNotNull(methodSignaturesList);
- assertTrue("Method getByteLeaf wasn't generated.",
- getByteLeafMethodFound == true);
- assertTrue("Wrong returning parameter type of method getByteLeaf",
- nameReturnParamType.compareTo("ByteType") == 0);
-
- assertTrue("Method setByteLeaf wasn't generated.",
- setByteLeafMethodFound == true);
- assertTrue("Incorrect number of input parameters for setByteLeaf",
- setByteLeafMethodParamNum == 1);
- assertTrue("Wrong input parameter type",
- nameMethodeParamType.compareTo("ByteType") == 0);
+ assertTrue(getByteLeafMethodFound);
+ assertEquals(nameReturnParamType,"ByteType");
+ assertFalse(setByteLeafMethodFound);
+ assertEquals(0, setByteLeafMethodParamNum);
}
}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.controller.sal.binding.generator.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.generator.impl.BindingGeneratorImpl;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
+import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
+
+public class GeneratedTypesStringTest {
+
+ private final static List<File> testModels = new ArrayList<File>();
+
+ @BeforeClass
+ public static void loadTestResources() {
+ final File listModelFile = new File(GeneratedTypesStringTest.class.getResource("/simple-string-demo.yang")
+ .getPath());
+ testModels.add(listModelFile);
+ }
+
+ @Test
+ public void constantGenerationTest() {
+ final YangModelParser parser = new YangParserImpl();
+ final Set<Module> modules = parser.parseYangModels(testModels);
+ final SchemaContext context = parser.resolveSchemaContext(modules);
+
+ assertNotNull(context);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
+ final List<Type> genTypes = bindingGen.generateTypes(context);
+
+ boolean typedefStringFound = false;
+ boolean constantRegExListFound = false;
+ boolean constantRegExListTypeGeneric = false;
+ boolean constantRegExListTypeContainer = false;
+ boolean noStringInReqExListFound = false;
+ boolean constantRegExListValueOK = false;
+ boolean constantRegExListTypeOneGeneric = false;
+ for (final Type type : genTypes) {
+ if (type instanceof GeneratedTransferObject) {
+ final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
+
+ if (genTO.getName().equals("TypedefString")) {
+ typedefStringFound = true;
+
+ List<Constant> constants = genTO.getConstantDefinitions();
+ for (Constant con : constants) {
+ if (con.getName().equals("PATTERN_CONSTANTS")) {
+ constantRegExListFound = true;
+ } else
+ break;
+ ParameterizedType pType;
+ if (con.getType() instanceof ParameterizedType) {
+ pType = (ParameterizedType) con.getType();
+ } else
+ break;
+
+ Type[] types;
+ if (pType.getName().equals("List")) {
+ constantRegExListTypeContainer = true;
+ types = pType.getActualTypeArguments();
+ } else
+ break;
+
+ if (types.length == 1) {
+ constantRegExListTypeOneGeneric = true;
+ } else
+ break;
+
+ if (types[0].getName().equals("String")) {
+ constantRegExListTypeGeneric = true;
+ } else
+ break;
+
+ if (con.getValue() instanceof List) {
+ constantRegExListValueOK = true;
+ } else
+ break;
+
+ for (Object obj : (List<?>) con.getValue()) {
+ if (!(obj instanceof String)) {
+ noStringInReqExListFound = true;
+ break;
+ }
+ }
+
+ }
+ }
+ }
+
+ }
+
+ assertTrue("Typedef >>TypedefString<< wasn't found", typedefStringFound);
+ assertTrue("Constant PATTERN_CONSTANTS is missing in TO", constantRegExListFound);
+ assertTrue("Constant PATTERN_CONSTANTS doesn't have correct container type", constantRegExListTypeContainer);
+ assertTrue("Constant PATTERN_CONSTANTS has more than one generic type", constantRegExListTypeOneGeneric);
+ assertTrue("Constant PATTERN_CONSTANTS doesn't have correct generic type", constantRegExListTypeGeneric);
+ assertTrue("Constant PATTERN_CONSTANTS doesn't contain List object", constantRegExListValueOK);
+ assertTrue("In list found other type than String", !noStringInReqExListFound);
+
+ }
+
+}
public class GeneratedTypesTest {
- private SchemaContext resolveSchemaContextFromFiles(
- final String... yangFiles) {
+ private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
final YangModelParser parser = new YangParserImpl();
final List<File> inputFiles = new ArrayList<File>();
@Test
public void testMultipleModulesResolving() {
- final String topologyPath = getClass().getResource(
- "/abstract-topology.yang").getPath();
- final String typesPath = getClass().getResource(
- "/ietf-inet-types@2010-09-24.yang").getPath();
- final SchemaContext context = resolveSchemaContextFromFiles(
- topologyPath, typesPath);
- assertTrue(context != null);
+ final String topologyPath = getClass().getResource("/abstract-topology.yang").getPath();
+ final String typesPath = getClass().getResource("/ietf-inet-types@2010-09-24.yang").getPath();
+ final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, typesPath);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(29, genTypes.size());
}
@Test
public void testLeafrefResolving() {
- final String topologyPath = getClass().getResource(
- "/leafref-test-models/abstract-topology@2013-02-08.yang")
+ final String topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang")
.getPath();
- final String interfacesPath = getClass().getResource(
- "/leafref-test-models/ietf-interfaces@2012-11-15.yang")
+ final String interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang")
.getPath();
// final String ifTypePath = getClass().getResource(
// "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath();
- final String inetTypesPath = getClass().getResource(
- "/leafref-test-models/ietf-inet-types@2010-09-24.yang")
+ final String inetTypesPath = getClass().getResource("/leafref-test-models/ietf-inet-types@2010-09-24.yang")
.getPath();
- final String yangTypesPath = getClass().getResource(
- "/leafref-test-models/ietf-yang-types@2010-09-24.yang")
+ final String yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang")
.getPath();
- assertTrue(topologyPath != null);
- assertTrue(interfacesPath != null);
+ assertNotNull(topologyPath);
+ assertNotNull(interfacesPath);
// assertTrue(ifTypePath != null);
- assertTrue(inetTypesPath != null);
- assertTrue(yangTypesPath != null);
+ assertNotNull(inetTypesPath);
+ assertNotNull(yangTypesPath);
// final SchemaContext context = resolveSchemaContextFromFiles(
// topologyPath, interfacesPath, ifTypePath, inetTypesPath,
// yangTypesPath);
- final SchemaContext context = resolveSchemaContextFromFiles(
- topologyPath, interfacesPath, inetTypesPath, yangTypesPath);
- assertTrue(context != null);
+ final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, interfacesPath, inetTypesPath,
+ yangTypesPath);
+ assertNotNull(context);
assertEquals(4, context.getModules().size());
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertEquals(57, genTypes.size());
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
GeneratedTransferObject gtIfcKey = null;
GeneratedType gtIfc = null;
Type ifcIdPropType = ifcIdProp.getReturnType();
assertNotNull(ifcIdPropType);
assertFalse(ifcIdPropType.equals("java.lang.Void"));
- assertTrue(ifcIdPropType.getName().equals("String"));
+ assertEquals(ifcIdPropType.getName(), "String");
// Interface
final List<MethodSignature> gtIfcMethods = gtIfc.getMethodDefinitions();
Type getIfcKeyType = getIfcKey.getReturnType();
assertNotNull(getIfcKeyType);
assertFalse(getIfcKeyType.equals("java.lang.Void"));
- assertTrue(getIfcKeyType.getName().equals("InterfaceKey"));
+ assertEquals(getIfcKeyType.getName(), "InterfaceKey");
assertNotNull(getHigherLayerIf);
Type getHigherLayerIfType = getHigherLayerIf.getReturnType();
assertNotNull(getHigherLayerIfType);
assertFalse(getHigherLayerIfType.equals("java.lang.Void"));
- assertTrue(getHigherLayerIfType.getName().equals("List"));
+ assertEquals(getHigherLayerIfType.getName(), "List");
// NetworkLink
- final List<MethodSignature> gtNetworkLinkMethods = gtNetworkLink
- .getMethodDefinitions();
+ final List<MethodSignature> gtNetworkLinkMethods = gtNetworkLink.getMethodDefinitions();
assertNotNull(gtNetworkLinkMethods);
MethodSignature getIfc = null;
for (MethodSignature method : gtNetworkLinkMethods) {
Type getIfcType = getIfc.getReturnType();
assertNotNull(getIfcType);
assertFalse(getIfcType.equals("java.lang.Void"));
- assertTrue(getIfcType.getName().equals("String"));
+ assertEquals(getIfcType.getName(), "String");
// SourceNode
- final List<MethodSignature> gtSourceMethods = gtSource
- .getMethodDefinitions();
+ final List<MethodSignature> gtSourceMethods = gtSource.getMethodDefinitions();
assertNotNull(gtSourceMethods);
MethodSignature getIdSource = null;
for (MethodSignature method : gtSourceMethods) {
Type getIdType = getIdSource.getReturnType();
assertNotNull(getIdType);
assertFalse(getIdType.equals("java.lang.Void"));
- assertTrue(getIdType.getName().equals("Uri"));
+ assertEquals(getIdType.getName(), "Uri");
// DestinationNode
- final List<MethodSignature> gtDestMethods = gtDest
- .getMethodDefinitions();
+ final List<MethodSignature> gtDestMethods = gtDest.getMethodDefinitions();
assertNotNull(gtDestMethods);
MethodSignature getIdDest = null;
for (MethodSignature method : gtDestMethods) {
Type getIdDestType = getIdDest.getReturnType();
assertNotNull(getIdDestType);
assertFalse(getIdDestType.equals("java.lang.Void"));
- assertTrue(getIdDestType.getName().equals("Uri"));
+ assertEquals(getIdDestType.getName(), "Uri");
// Tunnel
- final List<MethodSignature> gtTunnelMethods = gtTunnel
- .getMethodDefinitions();
+ final List<MethodSignature> gtTunnelMethods = gtTunnel.getMethodDefinitions();
assertNotNull(gtTunnelMethods);
MethodSignature getTunnelKey = null;
for (MethodSignature method : gtTunnelMethods) {
Type getTunnelKeyType = getTunnelKey.getReturnType();
assertNotNull(getTunnelKeyType);
assertFalse(getTunnelKeyType.equals("java.lang.Void"));
- assertTrue(getTunnelKeyType.getName().equals("TunnelKey"));
+ assertEquals(getTunnelKeyType.getName(), "TunnelKey");
// TunnelKey
- final List<GeneratedProperty> gtTunnelKeyProps = gtTunnelKey
- .getProperties();
+ final List<GeneratedProperty> gtTunnelKeyProps = gtTunnelKey.getProperties();
assertNotNull(gtTunnelKeyProps);
GeneratedProperty tunnelId = null;
for (final GeneratedProperty property : gtTunnelKeyProps) {
Type tunnelIdType = tunnelId.getReturnType();
assertNotNull(tunnelIdType);
assertFalse(tunnelIdType.equals("java.lang.Void"));
- assertTrue(tunnelIdType.getName().equals("Uri"));
+ assertEquals(tunnelIdType.getName(), "Uri");
}
@Test
public void testContainerResolving() {
- final String filePath = getClass().getResource(
- "/simple-container-demo.yang").getPath();
+ final String filePath = getClass().getResource("/simple-container-demo.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assert (context != null);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(4, genTypes.size());
final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
assertEquals("SimpleContainer", simpleContainer.getName());
assertEquals("NestedContainer", nestedContainer.getName());
- assertEquals(5, simpleContainer.getMethodDefinitions().size());
- assertEquals(4, nestedContainer.getMethodDefinitions().size());
-
- int methodsCount = 0;
- for (final MethodSignature method : simpleContainer
- .getMethodDefinitions()) {
+ assertEquals(3, simpleContainer.getMethodDefinitions().size());
+ assertEquals(2, nestedContainer.getMethodDefinitions().size());
+
+ int setFooMethodCounter = 0;
+ int getFooMethodCounter = 0;
+ int getBarMethodCounter = 0;
+ int getNestedContainerCounter = 0;
+
+ String getFooMethodReturnTypeName = "";
+ String setFooMethodInputParamName = "";
+ String setFooMethodInputParamTypeName = "";
+ String getBarMethodReturnTypeName = "";
+ String getNestedContainerReturnTypeName = "";
+ for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
if (method.getName().equals("getFoo")) {
- method.getReturnType().getName().equals("Integer");
- methodsCount++;
+ getFooMethodCounter++;
+ getFooMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setFoo")) {
- methodsCount++;
- final MethodSignature.Parameter param = method.getParameters()
- .get(0);
- assertEquals("foo", param.getName());
- assertEquals("Integer", param.getType().getName());
+ setFooMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setFooMethodInputParamName = param.getName();
+ setFooMethodInputParamTypeName = param.getType().getName();
}
if (method.getName().equals("getBar")) {
- method.getReturnType().getName().equals("String");
- methodsCount++;
+ getBarMethodCounter++;
+ getBarMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("getNestedContainer")) {
- method.getReturnType().getName().equals("NestedContainer");
- methodsCount++;
+ getNestedContainerCounter++;
+ getNestedContainerReturnTypeName = method.getReturnType().getName();
}
}
- assertEquals(4, methodsCount);
- methodsCount = 0;
- for (final MethodSignature method : nestedContainer
- .getMethodDefinitions()) {
+ assertEquals(getFooMethodCounter, 1);
+ assertEquals(getFooMethodReturnTypeName, "Integer");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(setFooMethodCounter, 1);
+ // assertEquals(setFooMethodInputParamName, "foo");
+ // assertEquals(setFooMethodInputParamTypeName, "Integer");
+
+ assertEquals(getBarMethodCounter, 1);
+ assertEquals(getBarMethodReturnTypeName, "String");
+
+ assertEquals(getNestedContainerCounter, 1);
+ assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
+
+ setFooMethodCounter = 0;
+ getFooMethodCounter = 0;
+ getBarMethodCounter = 0;
+ int setBarMethodCounter = 0;
+
+ getFooMethodReturnTypeName = "";
+ setFooMethodInputParamName = "";
+ setFooMethodInputParamTypeName = "";
+ getBarMethodReturnTypeName = "";
+ String setBarMethodInputParamName = "";
+ String setBarMethodInputParamTypeName = "";
+
+ for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
+
if (method.getName().equals("getFoo")) {
- method.getReturnType().getName().equals("Short");
- methodsCount++;
+ getFooMethodCounter++;
+ getFooMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setFoo")) {
- methodsCount++;
- final MethodSignature.Parameter param = method.getParameters()
- .get(0);
- assertEquals("foo", param.getName());
- assertEquals("Short", param.getType().getName());
+ setFooMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setFooMethodInputParamName = param.getName();
+ setFooMethodInputParamTypeName = param.getType().getName();
}
if (method.getName().equals("getBar")) {
- method.getReturnType().getName().equals("String");
- methodsCount++;
+ getBarMethodCounter++;
+ getBarMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setBar")) {
- method.getReturnType().getName().equals("String");
- methodsCount++;
+ setBarMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setBarMethodInputParamName = param.getName();
+ setBarMethodInputParamTypeName = param.getType().getName();
}
}
- assertEquals(4, methodsCount);
+
+ assertEquals(1, getFooMethodCounter);
+ assertEquals(getFooMethodReturnTypeName, "Short");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(1, setFooMethodCounter);
+ // assertEquals(setFooMethodInputParamName, "foo");
+ // assertEquals(setFooMethodInputParamTypeName, "Short");
+
+ assertEquals(1, getBarMethodCounter);
+ assertEquals(getBarMethodReturnTypeName, "String");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(1, setBarMethodCounter);
+ // assertEquals(setBarMethodInputParamName, "bar");
+ // assertEquals(setBarMethodInputParamTypeName, "String");
}
@Test
public void testLeafListResolving() {
- final String filePath = getClass().getResource(
- "/simple-leaf-list-demo.yang").getPath();
+ final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(4, genTypes.size());
final GeneratedType simpleContainer = (GeneratedType) genTypes.get(1);
assertEquals("SimpleContainer", simpleContainer.getName());
assertEquals("NestedContainer", nestedContainer.getName());
- assertEquals(5, simpleContainer.getMethodDefinitions().size());
- assertEquals(3, nestedContainer.getMethodDefinitions().size());
-
- int methodsCount = 0;
- for (final MethodSignature method : simpleContainer
- .getMethodDefinitions()) {
+ assertEquals(3, simpleContainer.getMethodDefinitions().size());
+ assertEquals(2, nestedContainer.getMethodDefinitions().size());
+
+ int setFooMethodCounter = 0;
+ int getFooMethodCounter = 0;
+ int getBarMethodCounter = 0;
+ int getNestedContainerCounter = 0;
+
+ String getFooMethodReturnTypeName = "";
+ String setFooMethodInputParamName = "";
+ String setFooMethodInputParamTypeName = "";
+ String getBarMethodReturnTypeName = "";
+ String getNestedContainerReturnTypeName = "";
+ for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
if (method.getName().equals("getFoo")) {
- method.getReturnType().getName().equals("List");
- methodsCount++;
+ getFooMethodCounter++;
+ getFooMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setFoo")) {
- methodsCount++;
- final MethodSignature.Parameter param = method.getParameters()
- .get(0);
- assertEquals("foo", param.getName());
- assertEquals("List", param.getType().getName());
+ setFooMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setFooMethodInputParamName = param.getName();
+ setFooMethodInputParamTypeName = param.getType().getName();
}
if (method.getName().equals("getBar")) {
- method.getReturnType().getName().equals("String");
- methodsCount++;
+ getBarMethodCounter++;
+ getBarMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("getNestedContainer")) {
- method.getReturnType().getName().equals("NestedContainer");
- methodsCount++;
+ getNestedContainerCounter++;
+ getNestedContainerReturnTypeName = method.getReturnType().getName();
}
}
- assertEquals(4, methodsCount);
- methodsCount = 0;
- for (final MethodSignature method : nestedContainer
- .getMethodDefinitions()) {
+ assertEquals(1, getFooMethodCounter);
+ assertEquals(getFooMethodReturnTypeName, "List");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(1, setFooMethodCounter);
+ // assertEquals(setFooMethodInputParamName, "foo");
+ // assertEquals(setFooMethodInputParamTypeName, "List");
+
+ assertEquals(1, getBarMethodCounter);
+ assertEquals(getBarMethodReturnTypeName, "String");
+
+ assertEquals(1, getNestedContainerCounter);
+ assertEquals(getNestedContainerReturnTypeName, "NestedContainer");
+
+ setFooMethodCounter = 0;
+ getFooMethodCounter = 0;
+ getBarMethodCounter = 0;
+
+ getFooMethodReturnTypeName = "";
+ setFooMethodInputParamName = "";
+ setFooMethodInputParamTypeName = "";
+ getBarMethodReturnTypeName = "";
+
+ for (final MethodSignature method : nestedContainer.getMethodDefinitions()) {
if (method.getName().equals("getFoo")) {
- method.getReturnType().getName().equals("Short");
- methodsCount++;
+ getFooMethodCounter++;
+ getFooMethodReturnTypeName = method.getReturnType().getName();
}
if (method.getName().equals("setFoo")) {
- methodsCount++;
- final MethodSignature.Parameter param = method.getParameters()
- .get(0);
- assertEquals("foo", param.getName());
- assertEquals("Short", param.getType().getName());
+ setFooMethodCounter++;
+ final MethodSignature.Parameter param = method.getParameters().get(0);
+ setFooMethodInputParamName = param.getName();
+ setFooMethodInputParamTypeName = param.getType().getName();
}
if (method.getName().equals("getBar")) {
- method.getReturnType().getName().equals("List");
- methodsCount++;
+ getBarMethodCounter++;
+ getBarMethodReturnTypeName = method.getReturnType().getName();
}
}
- assertEquals(3, methodsCount);
+
+ assertEquals(1, getFooMethodCounter);
+ assertEquals(getFooMethodReturnTypeName, "Short");
+
+ // TODO no setter methods, because 'config' is default true
+ // assertEquals(1, setFooMethodCounter);
+ // assertEquals(setFooMethodInputParamName, "foo");
+ // assertEquals(setFooMethodInputParamTypeName, "Short");
+
+ assertEquals(1, getBarMethodCounter);
+ assertEquals(getBarMethodReturnTypeName, "List");
}
@Test
public void testListResolving() {
- final String filePath = getClass()
- .getResource("/simple-list-demo.yang").getPath();
+ final String filePath = getClass().getResource("/simple-list-demo.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(6, genTypes.size());
int genTypesCount = 0;
int genTOsCount = 0;
+
+ int listParentContainerMethodsCount = 0;
+ int simpleListMethodsCount = 0;
+ int listChildContainerMethodsCount = 0;
+ int listKeyClassCount = 0;
+
+ int getSimpleListKeyMethodCount = 0;
+ int getListChildContainerMethodCount = 0;
+ int getFooMethodCount = 0;
+ int setFooMethodCount = 0;
+ int getSimpleLeafListMethodCount = 0;
+ int setSimpleLeafListMethodCount = 0;
+ int getBarMethodCount = 0;
+
+ String getSimpleListKeyMethodReturnTypeName = "";
+ String getListChildContainerMethodReturnTypeName = "";
+
+ int listKeyClassPropertyCount = 0;
+ String listKeyClassPropertyName = "";
+ String listKeyClassPropertyTypeName = "";
+ boolean listKeyClassPropertyReadOnly = false;
+
+ int hashMethodParameterCount = 0;
+ String hashMethodParameterName = "";
+ String hashMethodParameterReturnTypeName = "";
+
+ int equalMethodParameterCount = 0;
+ String equalMethodParameterName = "";
+ String equalMethodParameterReturnTypeName = "";
+
for (final Type type : genTypes) {
- if (type instanceof GeneratedType
- && !(type instanceof GeneratedTransferObject)) {
+ if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
final GeneratedType genType = (GeneratedType) type;
if (genType.getName().equals("ListParentContainer")) {
- assertEquals(2, genType.getMethodDefinitions().size());
+ listParentContainerMethodsCount = genType.getMethodDefinitions().size();
genTypesCount++;
} else if (genType.getName().equals("SimpleList")) {
- assertEquals(8, genType.getMethodDefinitions().size());
- final List<MethodSignature> methods = genType
- .getMethodDefinitions();
- int methodsCount = 0;
+ simpleListMethodsCount = genType.getMethodDefinitions().size();
+ final List<MethodSignature> methods = genType.getMethodDefinitions();
for (final MethodSignature method : methods) {
if (method.getName().equals("getSimpleListKey")) {
- assertEquals("SimpleListKey", method
- .getReturnType().getName());
- methodsCount++;
- } else if (method.getName().equals(
- "getListChildContainer")) {
- assertEquals("ListChildContainer", method
- .getReturnType().getName());
- methodsCount++;
+ getSimpleListKeyMethodCount++;
+ getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
+ } else if (method.getName().equals("getListChildContainer")) {
+ getListChildContainerMethodCount++;
+ getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
} else if (method.getName().equals("getFoo")) {
- methodsCount++;
+ getFooMethodCount++;
} else if (method.getName().equals("setFoo")) {
- methodsCount++;
+ setFooMethodCount++;
} else if (method.getName().equals("getSimpleLeafList")) {
- methodsCount++;
+ getSimpleLeafListMethodCount++;
} else if (method.getName().equals("setSimpleLeafList")) {
- methodsCount++;
+ setSimpleLeafListMethodCount++;
} else if (method.getName().equals("getBar")) {
- methodsCount++;
+ getBarMethodCount++;
}
}
- assertEquals(7, methodsCount);
genTypesCount++;
} else if (genType.getName().equals("ListChildContainer")) {
- assertEquals(2, genType.getMethodDefinitions().size());
+ listChildContainerMethodsCount = genType.getMethodDefinitions().size();
genTypesCount++;
}
} else if (type instanceof GeneratedTransferObject) {
genTOsCount++;
final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
- final List<GeneratedProperty> properties = genTO
- .getProperties();
- final List<GeneratedProperty> hashProps = genTO
- .getHashCodeIdentifiers();
- final List<GeneratedProperty> equalProps = genTO
- .getEqualsIdentifiers();
-
- assertEquals(1, properties.size());
- assertEquals("ListKey", properties.get(0).getName());
- assertEquals("Byte", properties.get(0).getReturnType()
- .getName());
- assertEquals(true, properties.get(0).isReadOnly());
- assertEquals(1, hashProps.size());
- assertEquals("ListKey", hashProps.get(0).getName());
- assertEquals("Byte", hashProps.get(0).getReturnType().getName());
- assertEquals(1, equalProps.size());
- assertEquals("ListKey", equalProps.get(0).getName());
- assertEquals("Byte", equalProps.get(0).getReturnType()
- .getName());
+ final List<GeneratedProperty> properties = genTO.getProperties();
+ final List<GeneratedProperty> hashProps = genTO.getHashCodeIdentifiers();
+ final List<GeneratedProperty> equalProps = genTO.getEqualsIdentifiers();
+
+ listKeyClassCount++;
+ listKeyClassPropertyCount = properties.size();
+ listKeyClassPropertyName = properties.get(0).getName();
+ listKeyClassPropertyTypeName = properties.get(0).getReturnType().getName();
+ listKeyClassPropertyReadOnly = properties.get(0).isReadOnly();
+
+ hashMethodParameterCount = hashProps.size();
+ hashMethodParameterName = hashProps.get(0).getName();
+ hashMethodParameterReturnTypeName = hashProps.get(0).getReturnType().getName();
+
+ equalMethodParameterCount = equalProps.size();
+ equalMethodParameterName = equalProps.get(0).getName();
+ equalMethodParameterReturnTypeName = equalProps.get(0).getReturnType().getName();
+
}
}
- assertEquals(3, genTypesCount);
- assertEquals(1, genTOsCount);
+
+ assertEquals(1, listParentContainerMethodsCount);
+ assertEquals(1, listChildContainerMethodsCount);
+ assertEquals(1, getSimpleListKeyMethodCount);
+ assertEquals(1, listKeyClassCount);
+
+ assertEquals(1, listKeyClassPropertyCount);
+ assertEquals("ListKey", listKeyClassPropertyName);
+ assertEquals("Byte", listKeyClassPropertyTypeName);
+ assertEquals(true, listKeyClassPropertyReadOnly);
+ assertEquals(1, hashMethodParameterCount);
+ assertEquals("ListKey", hashMethodParameterName);
+ assertEquals("Byte", hashMethodParameterReturnTypeName);
+ assertEquals(1, equalMethodParameterCount);
+ assertEquals("ListKey", equalMethodParameterName);
+ assertEquals("Byte", equalMethodParameterReturnTypeName);
+
+ assertEquals("SimpleListKey", getSimpleListKeyMethodReturnTypeName);
+
+ assertEquals(1, getListChildContainerMethodCount);
+ assertEquals("ListChildContainer", getListChildContainerMethodReturnTypeName);
+ assertEquals(1, getFooMethodCount);
+ assertEquals(0, setFooMethodCount);
+ assertEquals(1, getSimpleLeafListMethodCount);
+ assertEquals(0, setSimpleLeafListMethodCount);
+ assertEquals(1, getBarMethodCount);
+
+ assertEquals(5, simpleListMethodsCount);
}
@Test
public void testListCompositeKeyResolving() {
- final String filePath = getClass().getResource(
- "/list-composite-key.yang").getPath();
+ final String filePath = getClass().getResource("/list-composite-key.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(8, genTypes.size());
int genTypesCount = 0;
int genTOsCount = 0;
+
+ int compositeKeyListKeyPropertyCount = 0;
+ int compositeKeyListKeyCount = 0;
+ int innerListKeyPropertyCount = 0;
+
for (final Type type : genTypes) {
- if (type instanceof GeneratedType
- && !(type instanceof GeneratedTransferObject)) {
+ if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
genTypesCount++;
} else if (type instanceof GeneratedTransferObject) {
final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
if (genTO.getName().equals("CompositeKeyListKey")) {
- final List<GeneratedProperty> properties = genTO
- .getProperties();
- int propertyCount = 0;
+ compositeKeyListKeyCount++;
+ final List<GeneratedProperty> properties = genTO.getProperties();
for (final GeneratedProperty prop : properties) {
if (prop.getName().equals("Key1")) {
- propertyCount++;
+ compositeKeyListKeyPropertyCount++;
} else if (prop.getName().equals("Key2")) {
- propertyCount++;
+ compositeKeyListKeyPropertyCount++;
}
}
- assertEquals(2, propertyCount);
genTOsCount++;
} else if (genTO.getName().equals("InnerListKey")) {
- final List<GeneratedProperty> properties = genTO
- .getProperties();
- assertEquals(1, properties.size());
+ final List<GeneratedProperty> properties = genTO.getProperties();
+ innerListKeyPropertyCount = properties.size();
genTOsCount++;
}
}
}
+ assertEquals(1, compositeKeyListKeyCount);
+ assertEquals(2, compositeKeyListKeyPropertyCount);
+
+ assertEquals(1, innerListKeyPropertyCount);
assertEquals(6, genTypesCount);
assertEquals(2, genTOsCount);
@Test
public void testGeneratedTypes() {
- final String filePath = getClass().getResource("/demo-topology.yang")
- .getPath();
+ final String filePath = getClass().getResource("/demo-topology.yang").getPath();
final SchemaContext context = resolveSchemaContextFromFiles(filePath);
- assertTrue(context != null);
+ assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
- assertTrue(genTypes != null);
+ assertNotNull(genTypes);
assertEquals(15, genTypes.size());
int genTypesCount = 0;
int genTOsCount = 0;
for (final Type type : genTypes) {
- if (type instanceof GeneratedType
- && !(type instanceof GeneratedTransferObject)) {
+ if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
genTypesCount++;
} else if (type instanceof GeneratedTransferObject) {
genTOsCount++;
--- /dev/null
+module augment-monitoring {
+ yang-version 1;
+ namespace "urn:ietf:params:xml:ns:yang:augment-monitoring";
+ prefix "amon";
+
+ import ietf-netconf-monitoring { prefix nm; }
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision "2013-07-01" {
+ reference "NO REF";
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type" {
+ case autonomous-lock {
+ container autonomous-def {
+ leaf lock-id {
+ type int32;
+ }
+
+ leaf lock-time {
+ type uint32;
+ }
+ }
+ }
+
+ case anonymous-lock {
+ leaf lock-time {
+ type uint32;
+ }
+ }
+
+ leaf leaf-aug-case {
+ type string;
+ }
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore/nm:locks/nm:lock-type/nm:partial-lock" {
+ choice aug-case-by-choice {
+ case foo {
+ leaf foo {
+ type string;
+ }
+ }
+
+ case bar {
+ leaf bar {
+ type boolean;
+ }
+ }
+ }
+ }
+
+ augment "/nm:netconf-state/nm:datastores/nm:datastore" {
+ choice storage-format {
+ case xml {
+ container xml-def {
+ leaf file-name {
+ type string;
+ }
+ }
+ }
+
+ case yang {
+ leaf yang-file-name {
+ type string;
+ }
+ }
+
+ case unknown-files {
+ list files {
+ key "file-name";
+
+ leaf file-name {
+ type string;
+ }
+
+ container file-data {
+ leaf utf8-data {
+ type string;
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+ module ietf-inet-types {
+
+ namespace "urn:ietf:params:xml:ns:yang:ietf-inet-types";
+ prefix "inet";
+
+ organization
+ "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netmod/>
+ WG List: <mailto:netmod@ietf.org>
+
+ WG Chair: David Partain
+ <mailto:david.partain@ericsson.com>
+
+ WG Chair: David Kessens
+ <mailto:david.kessens@nsn.com>
+
+ Editor: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>";
+
+ description
+ "This module contains a collection of generally useful derived
+ YANG data types for Internet addresses and related things.
+
+ Copyright (c) 2010 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, is permitted pursuant to, and subject to the license
+ terms contained in, the Simplified BSD License set forth in Section
+ 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+
+ This version of this YANG module is part of RFC 6021; see
+ the RFC itself for full legal notices.";
+
+ revision 2010-09-24 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 6021: Common YANG Data Types";
+ }
+
+ /*** collection of protocol field related types ***/
+
+ typedef ip-version {
+ type enumeration {
+ enum unknown {
+ value "0";
+ description
+ "An unknown or unspecified version of the Internet protocol.";
+ }
+ enum ipv4 {
+ value "1";
+ description
+ "The IPv4 protocol as defined in RFC 791.";
+ }
+ enum ipv6 {
+ value "2";
+ description
+ "The IPv6 protocol as defined in RFC 2460.";
+ }
+ }
+ description
+ "This value represents the version of the IP protocol.
+
+ In the value set and its semantics, this type is equivalent
+ to the InetVersion textual convention of the SMIv2.";
+ reference
+ "RFC 791: Internet Protocol
+ RFC 2460: Internet Protocol, Version 6 (IPv6) Specification
+ RFC 4001: Textual Conventions for Internet Network Addresses";
+ }
+
+ typedef dscp {
+ type uint8 {
+ range "0..63";
+ }
+ description
+ "The dscp type represents a Differentiated Services Code-Point
+ that may be used for marking packets in a traffic stream.
+
+ In the value set and its semantics, this type is equivalent
+ to the Dscp textual convention of the SMIv2.";
+ reference
+ "RFC 3289: Management Information Base for the Differentiated
+ Services Architecture
+ RFC 2474: Definition of the Differentiated Services Field
+ (DS Field) in the IPv4 and IPv6 Headers
+ RFC 2780: IANA Allocation Guidelines For Values In
+ the Internet Protocol and Related Headers";
+ }
+
+ typedef ipv6-flow-label {
+ type uint32 {
+ range "0..1048575";
+ }
+ description
+ "The flow-label type represents flow identifier or Flow Label
+ in an IPv6 packet header that may be used to discriminate
+ traffic flows.
+
+ In the value set and its semantics, this type is equivalent
+ to the IPv6FlowLabel textual convention of the SMIv2.";
+ reference
+ "RFC 3595: Textual Conventions for IPv6 Flow Label
+ RFC 2460: Internet Protocol, Version 6 (IPv6) Specification";
+ }
+
+ typedef port-number {
+ type uint16 {
+ range "0..65535";
+ }
+ description
+ "The port-number type represents a 16-bit port number of an
+ Internet transport layer protocol such as UDP, TCP, DCCP, or
+ SCTP. Port numbers are assigned by IANA. A current list of
+ all assignments is available from <http://www.iana.org/>.
+
+ Note that the port number value zero is reserved by IANA. In
+ situations where the value zero does not make sense, it can
+ be excluded by subtyping the port-number type.
+
+ In the value set and its semantics, this type is equivalent
+ to the InetPortNumber textual convention of the SMIv2.";
+ reference
+ "RFC 768: User Datagram Protocol
+ RFC 793: Transmission Control Protocol
+ RFC 4960: Stream Control Transmission Protocol
+ RFC 4340: Datagram Congestion Control Protocol (DCCP)
+ RFC 4001: Textual Conventions for Internet Network Addresses";
+ }
+
+ /*** collection of autonomous system related types ***/
+
+ typedef as-number {
+ type uint32;
+ description
+ "The as-number type represents autonomous system numbers
+ which identify an Autonomous System (AS). An AS is a set
+ of routers under a single technical administration, using
+ an interior gateway protocol and common metrics to route
+ packets within the AS, and using an exterior gateway
+ protocol to route packets to other ASs'. IANA maintains
+ the AS number space and has delegated large parts to the
+ regional registries.
+
+ Autonomous system numbers were originally limited to 16
+ bits. BGP extensions have enlarged the autonomous system
+ number space to 32 bits. This type therefore uses an uint32
+ base type without a range restriction in order to support
+ a larger autonomous system number space.
+
+ In the value set and its semantics, this type is equivalent
+ to the InetAutonomousSystemNumber textual convention of
+ the SMIv2.";
+ reference
+ "RFC 1930: Guidelines for creation, selection, and registration
+ of an Autonomous System (AS)
+ RFC 4271: A Border Gateway Protocol 4 (BGP-4)
+ RFC 4893: BGP Support for Four-octet AS Number Space
+ RFC 4001: Textual Conventions for Internet Network Addresses";
+ }
+
+ /*** collection of IP address and hostname related types ***/
+
+ typedef ip-address {
+ type union {
+ type inet:ipv4-address;
+ type inet:ipv6-address;
+ }
+ description
+ "The ip-address type represents an IP address and is IP
+ version neutral. The format of the textual representations
+ implies the IP version.";
+ }
+
+ typedef ipv4-address {
+ type string {
+ pattern
+ '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+ + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+ + '(%[\p{N}\p{L}]+)?';
+ }
+ description
+ "The ipv4-address type represents an IPv4 address in
+ dotted-quad notation. The IPv4 address may include a zone
+ index, separated by a % sign.
+
+ The zone index is used to disambiguate identical address
+ values. For link-local addresses, the zone index will
+ typically be the interface index number or the name of an
+ interface. If the zone index is not present, the default
+ zone of the device will be used.
+
+ The canonical format for the zone index is the numerical
+ format";
+ }
+
+ typedef ipv6-address {
+ type string {
+ pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+ + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+ + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+ + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+ + '(%[\p{N}\p{L}]+)?';
+ pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+ + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+ + '(%.+)?';
+ }
+ description
+ "The ipv6-address type represents an IPv6 address in full,
+ mixed, shortened, and shortened-mixed notation. The IPv6
+ address may include a zone index, separated by a % sign.
+
+ The zone index is used to disambiguate identical address
+ values. For link-local addresses, the zone index will
+ typically be the interface index number or the name of an
+ interface. If the zone index is not present, the default
+ zone of the device will be used.
+
+ The canonical format of IPv6 addresses uses the compressed
+ format described in RFC 4291, Section 2.2, item 2 with the
+ following additional rules: the :: substitution must be
+ applied to the longest sequence of all-zero 16-bit chunks
+ in an IPv6 address. If there is a tie, the first sequence
+ of all-zero 16-bit chunks is replaced by ::. Single
+ all-zero 16-bit chunks are not compressed. The canonical
+ format uses lowercase characters and leading zeros are
+ not allowed. The canonical format for the zone index is
+ the numerical format as described in RFC 4007, Section
+ 11.2.";
+ reference
+ "RFC 4291: IP Version 6 Addressing Architecture
+ RFC 4007: IPv6 Scoped Address Architecture
+ RFC 5952: A Recommendation for IPv6 Address Text Representation";
+ }
+
+ typedef ip-prefix {
+ type union {
+ type inet:ipv4-prefix;
+ type inet:ipv6-prefix;
+ }
+ description
+ "The ip-prefix type represents an IP prefix and is IP
+ version neutral. The format of the textual representations
+ implies the IP version.";
+ }
+
+ typedef ipv4-prefix {
+ type string {
+ pattern
+ '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}'
+ + '([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'
+ + '/(([0-9])|([1-2][0-9])|(3[0-2]))';
+ }
+ description
+ "The ipv4-prefix type represents an IPv4 address prefix.
+ The prefix length is given by the number following the
+ slash character and must be less than or equal to 32.
+
+ A prefix length value of n corresponds to an IP address
+ mask that has n contiguous 1-bits from the most
+ significant bit (MSB) and all other bits set to 0.
+
+ The canonical format of an IPv4 prefix has all bits of
+ the IPv4 address set to zero that are not part of the
+ IPv4 prefix.";
+ }
+
+ typedef ipv6-prefix {
+ type string {
+ pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}'
+ + '((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|'
+ + '(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}'
+ + '(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))'
+ + '(/(([0-9])|([0-9]{2})|(1[0-1][0-9])|(12[0-8])))';
+ pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|'
+ + '((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)'
+ + '(/.+)';
+ }
+ description
+ "The ipv6-prefix type represents an IPv6 address prefix.
+ The prefix length is given by the number following the
+ slash character and must be less than or equal 128.
+
+ A prefix length value of n corresponds to an IP address
+ mask that has n contiguous 1-bits from the most
+ significant bit (MSB) and all other bits set to 0.
+
+ The IPv6 address should have all bits that do not belong
+ to the prefix set to zero.
+
+ The canonical format of an IPv6 prefix has all bits of
+ the IPv6 address set to zero that are not part of the
+ IPv6 prefix. Furthermore, IPv6 address is represented
+ in the compressed format described in RFC 4291, Section
+ 2.2, item 2 with the following additional rules: the ::
+ substitution must be applied to the longest sequence of
+ all-zero 16-bit chunks in an IPv6 address. If there is
+ a tie, the first sequence of all-zero 16-bit chunks is
+ replaced by ::. Single all-zero 16-bit chunks are not
+ compressed. The canonical format uses lowercase
+ characters and leading zeros are not allowed.";
+ reference
+ "RFC 4291: IP Version 6 Addressing Architecture";
+ }
+
+ /*** collection of domain name and URI types ***/
+
+ typedef domain-name {
+ type string {
+ pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*'
+ + '([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)'
+ + '|\.';
+ length "1..253";
+ }
+ description
+ "The domain-name type represents a DNS domain name. The
+ name SHOULD be fully qualified whenever possible.
+
+ Internet domain names are only loosely specified. Section
+ 3.5 of RFC 1034 recommends a syntax (modified in Section
+ 2.1 of RFC 1123). The pattern above is intended to allow
+ for current practice in domain name use, and some possible
+ future expansion. It is designed to hold various types of
+ domain names, including names used for A or AAAA records
+ (host names) and other records, such as SRV records. Note
+ that Internet host names have a stricter syntax (described
+ in RFC 952) than the DNS recommendations in RFCs 1034 and
+ 1123, and that systems that want to store host names in
+ schema nodes using the domain-name type are recommended to
+ adhere to this stricter standard to ensure interoperability.
+
+ The encoding of DNS names in the DNS protocol is limited
+ to 255 characters. Since the encoding consists of labels
+ prefixed by a length bytes and there is a trailing NULL
+ byte, only 253 characters can appear in the textual dotted
+ notation.
+
+ The description clause of schema nodes using the domain-name
+ type MUST describe when and how these names are resolved to
+ IP addresses. Note that the resolution of a domain-name value
+ may require to query multiple DNS records (e.g., A for IPv4
+ and AAAA for IPv6). The order of the resolution process and
+ which DNS record takes precedence can either be defined
+ explicitely or it may depend on the configuration of the
+ resolver.
+
+ Domain-name values use the US-ASCII encoding. Their canonical
+ format uses lowercase US-ASCII characters. Internationalized
+ domain names MUST be encoded in punycode as described in RFC
+ 3492";
+ reference
+ "RFC 952: DoD Internet Host Table Specification
+ RFC 1034: Domain Names - Concepts and Facilities
+ RFC 1123: Requirements for Internet Hosts -- Application
+ and Support
+ RFC 2782: A DNS RR for specifying the location of services
+ (DNS SRV)
+ RFC 3492: Punycode: A Bootstring encoding of Unicode for
+ Internationalized Domain Names in Applications
+ (IDNA)
+ RFC 5891: Internationalizing Domain Names in Applications
+ (IDNA): Protocol";
+ }
+
+ typedef host {
+ type union {
+ type inet:ip-address;
+ type inet:domain-name;
+ }
+ description
+ "The host type represents either an IP address or a DNS
+ domain name.";
+ }
+
+ typedef uri {
+ type string;
+ description
+ "The uri type represents a Uniform Resource Identifier
+ (URI) as defined by STD 66.
+
+ Objects using the uri type MUST be in US-ASCII encoding,
+ and MUST be normalized as described by RFC 3986 Sections
+ 6.2.1, 6.2.2.1, and 6.2.2.2. All unnecessary
+ percent-encoding is removed, and all case-insensitive
+ characters are set to lowercase except for hexadecimal
+ digits, which are normalized to uppercase as described in
+ Section 6.2.2.1.
+
+ The purpose of this normalization is to help provide
+ unique URIs. Note that this normalization is not
+ sufficient to provide uniqueness. Two URIs that are
+ textually distinct after this normalization may still be
+ equivalent.
+
+ Objects using the uri type may restrict the schemes that
+ they permit. For example, 'data:' and 'urn:' schemes
+ might not be appropriate.
+
+ A zero-length URI is not a valid URI. This can be used to
+ express 'URI absent' where required.
+
+ In the value set and its semantics, this type is equivalent
+ to the Uri SMIv2 textual convention defined in RFC 5017.";
+ reference
+ "RFC 3986: Uniform Resource Identifier (URI): Generic Syntax
+ RFC 3305: Report from the Joint W3C/IETF URI Planning Interest
+ Group: Uniform Resource Identifiers (URIs), URLs,
+ and Uniform Resource Names (URNs): Clarifications
+ and Recommendations
+ RFC 5017: MIB Textual Conventions for Uniform Resource
+ Identifiers (URIs)";
+ }
+
+ }
--- /dev/null
+module ietf-netconf-monitoring {
+
+ namespace "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring";
+ prefix "ncm";
+
+ import ietf-yang-types { prefix yang; }
+ import ietf-inet-types { prefix inet; }
+
+ organization
+ "IETF NETCONF (Network Configuration) Working Group";
+
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netconf/>
+ WG List: <mailto:netconf@ietf.org>
+
+ WG Chair: Mehmet Ersue
+ <mailto:mehmet.ersue@nsn.com>
+
+ WG Chair: Bert Wijnen
+ <mailto:bertietf@bwijnen.net>
+
+ Editor: Mark Scott
+ <mailto:mark.scott@ericsson.com>
+
+ Editor: Martin Bjorklund
+ <mailto:mbj@tail-f.com>";
+
+ description
+ "NETCONF Monitoring Module.
+ All elements in this module are read-only.
+
+ Copyright (c) 2010 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or
+ without modification, is permitted pursuant to, and subject
+ to the license terms contained in, the Simplified BSD
+ License set forth in Section 4.c of the IETF Trust's
+ Legal Provisions Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+
+ This version of this YANG module is part of RFC 6022; see
+ the RFC itself for full legal notices.";
+
+ revision 2010-10-04 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 6022: YANG Module for NETCONF Monitoring";
+ }
+
+ typedef tls-fingerprint-type {
+ type string {
+ pattern '([0-9a-fA-F]){2}(:([0-9a-fA-F]){2})*';
+ }
+ description
+ "A cryptographic signature (fingerprint) value that can be used to
+ uniquely reference other data of potentially arbitrary length.";
+ }
+
+ typedef netconf-datastore-type {
+ type enumeration {
+ enum running;
+ enum candidate;
+ enum startup;
+ }
+ description
+ "Enumeration of possible NETCONF datastore types.";
+ reference
+ "RFC 4741: NETCONF Configuration Protocol";
+ }
+
+ container netconf-state {
+ config false;
+ description
+ "The netconf-state container is the root of the monitoring
+ data model.";
+
+ container datastores {
+ description
+ "Contains the list of NETCONF configuration datastores.";
+
+ list datastore {
+ key name;
+ description
+ "List of NETCONF configuration datastores supported by
+ the NETCONF server and related information.";
+
+ leaf name {
+ type netconf-datastore-type;
+ description
+ "Name of the datastore associated with this list entry.";
+ }
+ container locks {
+ presence
+ "This container is present only if the datastore
+ is locked.";
+ description
+ "The NETCONF <lock> and <partial-lock> operations allow
+ a client to lock specific resources in a datastore. The
+ NETCONF server will prevent changes to the locked
+ resources by all sessions except the one that acquired
+ the lock(s).
+
+ Monitoring information is provided for each datastore
+ entry including details such as the session that acquired
+ the lock, the type of lock (global or partial) and the
+ list of locked resources. Multiple locks per datastore
+ are supported.";
+
+ choice lock-type {
+ description
+ "Indicates if a global lock or a set of partial locks
+ are set.";
+
+ case global-lock {
+ container global-lock {
+ description
+ "Present if the global lock is set.";
+
+ leaf locked-by-session {
+ type uint32;
+ mandatory true;
+ description
+ "The session ID of the session that has locked
+ this resource. Both a global lock and a partial
+ lock MUST contain the NETCONF session-id.
+
+ If the lock is held by a session that is not managed
+ by the NETCONF server (e.g., a CLI session), a session
+ id of 0 (zero) is reported.";
+ reference
+ "RFC 4741: NETCONF Configuration Protocol";
+ }
+ leaf locked-time {
+ type yang:date-and-time;
+ mandatory true;
+ description
+ "The date and time of when the resource was
+ locked.";
+ }
+
+ container capabilities {
+ description
+ "Contains the list of NETCONF capabilities supported by the
+ server.";
+
+ leaf-list capability {
+ type inet:uri;
+ description
+ "List of NETCONF capabilities supported by the server.";
+ }
+ }
+ }
+ }
+
+ case partial-lock {
+ list partial-lock {
+ key lock-id;
+ description
+ "List of partial locks.";
+ reference
+ "RFC 5717: Partial Lock Remote Procedure Call (RPC) for
+ NETCONF";
+
+ leaf lock-id {
+ type uint32;
+ description
+ "This is the lock id returned in the <partial-lock>
+ response.";
+ }
+ leaf-list select {
+ type yang:xpath1.0;
+ min-elements 1;
+ description
+ "The xpath expression that was used to request
+ the lock. The select expression indicates the
+ original intended scope of the lock.";
+ }
+ leaf-list locked-node {
+ type string;
+ description
+ "The list of instance-identifiers (i.e., the
+ locked nodes). The scope of the partial lock is defined by the list
+ of locked nodes.";
+ }
+ }
+ }
+
+ case fingerprint {
+ choice algorithm-and-hash {
+ mandatory true;
+ case md5 {
+ leaf md5 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha1 {
+ leaf sha1 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha224 {
+ leaf sha224 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha256 {
+ leaf sha256 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha384 {
+ leaf sha384 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ case sha512 {
+ leaf sha512 {
+ type tls-fingerprint-type;
+ }
+ }
+
+ description
+ "Specifies the signature algorithm and cryptographic
+ signature (fingerprint) used to identify an X.509
+ certificate.
+
+ Implementations of this YANG module MAY, but are not
+ required to, implement all of these cryptographic signature
+ algorithms. Implementations of this YANG module MUST
+ implement at least one of these cryptographic signature
+ algorithms.
+
+ The available choices may be extended in the future as
+ stronger cryptographic signature algorithms become
+ available and are deemed necessary.";
+
+ reference
+ "RFC 5246: The Transport Layer Security (TLS) Protocol
+ Version 1.2; Section 7.4.1.4.1, Signature Algorithms";
+ } // choice algorithm-and-hash
+ }
+ }
+ }
+ }
+ }
+ }
+}
--- /dev/null
+ module ietf-yang-types {
+
+ namespace "urn:ietf:params:xml:ns:yang:ietf-yang-types";
+ prefix "yang";
+
+ organization
+ "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
+
+ contact
+ "WG Web: <http://tools.ietf.org/wg/netmod/>
+ WG List: <mailto:netmod@ietf.org>
+
+ WG Chair: David Partain
+ <mailto:david.partain@ericsson.com>
+
+ WG Chair: David Kessens
+ <mailto:david.kessens@nsn.com>
+
+ Editor: Juergen Schoenwaelder
+ <mailto:j.schoenwaelder@jacobs-university.de>";
+
+ description
+ "This module contains a collection of generally useful derived
+ YANG data types.
+
+ Copyright (c) 2010 IETF Trust and the persons identified as
+ authors of the code. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, is permitted pursuant to, and subject to the license
+ terms contained in, the Simplified BSD License set forth in Section
+ 4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
+ (http://trustee.ietf.org/license-info).
+
+ This version of this YANG module is part of RFC 6021; see
+ the RFC itself for full legal notices.";
+
+ revision 2010-09-24 {
+ description
+ "Initial revision.";
+ reference
+ "RFC 6021: Common YANG Data Types";
+ }
+
+ /*** collection of counter and gauge types ***/
+
+ typedef counter32 {
+ type uint32;
+ description
+ "The counter32 type represents a non-negative integer
+ that monotonically increases until it reaches a
+ maximum value of 2^32-1 (4294967295 decimal), when it
+ wraps around and starts increasing again from zero.
+
+ Counters have no defined 'initial' value, and thus, a
+ single value of a counter has (in general) no information
+ content. Discontinuities in the monotonically increasing
+ value normally occur at re-initialization of the
+ management system, and at other times as specified in the
+ description of a schema node using this type. If such
+ other times can occur, for example, the creation of
+ a schema node of type counter32 at times other than
+ re-initialization, then a corresponding schema node
+ should be defined, with an appropriate type, to indicate
+ the last discontinuity.
+
+ The counter32 type should not be used for configuration
+ schema nodes. A default statement SHOULD NOT be used in
+ combination with the type counter32.
+
+ In the value set and its semantics, this type is equivalent
+ to the Counter32 type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef zero-based-counter32 {
+ type yang:counter32;
+ default "0";
+ description
+ "The zero-based-counter32 type represents a counter32
+ that has the defined 'initial' value zero.
+
+ A schema node of this type will be set to zero (0) on creation
+ and will thereafter increase monotonically until it reaches
+ a maximum value of 2^32-1 (4294967295 decimal), when it
+ wraps around and starts increasing again from zero.
+
+ Provided that an application discovers a new schema node
+ of this type within the minimum time to wrap, it can use the
+ 'initial' value as a delta. It is important for a management
+ station to be aware of this minimum time and the actual time
+ between polls, and to discard data if the actual time is too
+ long or there is no defined minimum time.
+
+ In the value set and its semantics, this type is equivalent
+ to the ZeroBasedCounter32 textual convention of the SMIv2.";
+ reference
+ "RFC 4502: Remote Network Monitoring Management Information
+ Base Version 2";
+ }
+
+ typedef counter64 {
+ type uint64;
+ description
+ "The counter64 type represents a non-negative integer
+ that monotonically increases until it reaches a
+ maximum value of 2^64-1 (18446744073709551615 decimal),
+ when it wraps around and starts increasing again from zero.
+
+ Counters have no defined 'initial' value, and thus, a
+ single value of a counter has (in general) no information
+ content. Discontinuities in the monotonically increasing
+ value normally occur at re-initialization of the
+ management system, and at other times as specified in the
+ description of a schema node using this type. If such
+ other times can occur, for example, the creation of
+ a schema node of type counter64 at times other than
+ re-initialization, then a corresponding schema node
+ should be defined, with an appropriate type, to indicate
+ the last discontinuity.
+
+ The counter64 type should not be used for configuration
+ schema nodes. A default statement SHOULD NOT be used in
+ combination with the type counter64.
+
+ In the value set and its semantics, this type is equivalent
+ to the Counter64 type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef zero-based-counter64 {
+ type yang:counter64;
+ default "0";
+ description
+ "The zero-based-counter64 type represents a counter64 that
+ has the defined 'initial' value zero.
+
+ A schema node of this type will be set to zero (0) on creation
+ and will thereafter increase monotonically until it reaches
+ a maximum value of 2^64-1 (18446744073709551615 decimal),
+ when it wraps around and starts increasing again from zero.
+
+ Provided that an application discovers a new schema node
+ of this type within the minimum time to wrap, it can use the
+ 'initial' value as a delta. It is important for a management
+ station to be aware of this minimum time and the actual time
+ between polls, and to discard data if the actual time is too
+ long or there is no defined minimum time.
+
+ In the value set and its semantics, this type is equivalent
+ to the ZeroBasedCounter64 textual convention of the SMIv2.";
+ reference
+ "RFC 2856: Textual Conventions for Additional High Capacity
+ Data Types";
+ }
+
+ typedef gauge32 {
+ type uint32;
+ description
+ "The gauge32 type represents a non-negative integer, which
+ may increase or decrease, but shall never exceed a maximum
+ value, nor fall below a minimum value. The maximum value
+ cannot be greater than 2^32-1 (4294967295 decimal), and
+ the minimum value cannot be smaller than 0. The value of
+ a gauge32 has its maximum value whenever the information
+ being modeled is greater than or equal to its maximum
+ value, and has its minimum value whenever the information
+ being modeled is smaller than or equal to its minimum value.
+ If the information being modeled subsequently decreases
+ below (increases above) the maximum (minimum) value, the
+ gauge32 also decreases (increases).
+
+ In the value set and its semantics, this type is equivalent
+ to the Gauge32 type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef gauge64 {
+ type uint64;
+ description
+ "The gauge64 type represents a non-negative integer, which
+ may increase or decrease, but shall never exceed a maximum
+ value, nor fall below a minimum value. The maximum value
+ cannot be greater than 2^64-1 (18446744073709551615), and
+ the minimum value cannot be smaller than 0. The value of
+ a gauge64 has its maximum value whenever the information
+ being modeled is greater than or equal to its maximum
+ value, and has its minimum value whenever the information
+ being modeled is smaller than or equal to its minimum value.
+ If the information being modeled subsequently decreases
+ below (increases above) the maximum (minimum) value, the
+ gauge64 also decreases (increases).
+
+ In the value set and its semantics, this type is equivalent
+ to the CounterBasedGauge64 SMIv2 textual convention defined
+ in RFC 2856";
+ reference
+ "RFC 2856: Textual Conventions for Additional High Capacity
+ Data Types";
+ }
+
+ /*** collection of identifier related types ***/
+
+ typedef object-identifier {
+ type string {
+ pattern '(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))'
+ + '(\.(0|([1-9]\d*)))*';
+ }
+ description
+ "The object-identifier type represents administratively
+ assigned names in a registration-hierarchical-name tree.
+
+ Values of this type are denoted as a sequence of numerical
+ non-negative sub-identifier values. Each sub-identifier
+ value MUST NOT exceed 2^32-1 (4294967295). Sub-identifiers
+ are separated by single dots and without any intermediate
+ whitespace.
+
+ The ASN.1 standard restricts the value space of the first
+ sub-identifier to 0, 1, or 2. Furthermore, the value space
+ of the second sub-identifier is restricted to the range
+ 0 to 39 if the first sub-identifier is 0 or 1. Finally,
+ the ASN.1 standard requires that an object identifier
+ has always at least two sub-identifier. The pattern
+ captures these restrictions.
+
+ Although the number of sub-identifiers is not limited,
+ module designers should realize that there may be
+ implementations that stick with the SMIv2 limit of 128
+ sub-identifiers.
+
+ This type is a superset of the SMIv2 OBJECT IDENTIFIER type
+ since it is not restricted to 128 sub-identifiers. Hence,
+ this type SHOULD NOT be used to represent the SMIv2 OBJECT
+ IDENTIFIER type, the object-identifier-128 type SHOULD be
+ used instead.";
+ reference
+ "ISO9834-1: Information technology -- Open Systems
+ Interconnection -- Procedures for the operation of OSI
+ Registration Authorities: General procedures and top
+ arcs of the ASN.1 Object Identifier tree";
+ }
+
+
+
+
+ typedef object-identifier-128 {
+ type object-identifier {
+ pattern '\d*(\.\d*){1,127}';
+ }
+ description
+ "This type represents object-identifiers restricted to 128
+ sub-identifiers.
+
+ In the value set and its semantics, this type is equivalent
+ to the OBJECT IDENTIFIER type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ /*** collection of date and time related types ***/
+
+ typedef date-and-time {
+ type string {
+ pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?'
+ + '(Z|[\+\-]\d{2}:\d{2})';
+ }
+ description
+ "The date-and-time type is a profile of the ISO 8601
+ standard for representation of dates and times using the
+ Gregorian calendar. The profile is defined by the
+ date-time production in Section 5.6 of RFC 3339.
+
+ The date-and-time type is compatible with the dateTime XML
+ schema type with the following notable exceptions:
+
+ (a) The date-and-time type does not allow negative years.
+
+ (b) The date-and-time time-offset -00:00 indicates an unknown
+ time zone (see RFC 3339) while -00:00 and +00:00 and Z all
+ represent the same time zone in dateTime.
+
+ (c) The canonical format (see below) of data-and-time values
+ differs from the canonical format used by the dateTime XML
+ schema type, which requires all times to be in UTC using the
+ time-offset 'Z'.
+
+ This type is not equivalent to the DateAndTime textual
+ convention of the SMIv2 since RFC 3339 uses a different
+ separator between full-date and full-time and provides
+ higher resolution of time-secfrac.
+
+ The canonical format for date-and-time values with a known time
+ zone uses a numeric time zone offset that is calculated using
+ the device's configured known offset to UTC time. A change of
+ the device's offset to UTC time will cause date-and-time values
+ to change accordingly. Such changes might happen periodically
+ in case a server follows automatically daylight saving time
+ (DST) time zone offset changes. The canonical format for
+ date-and-time values with an unknown time zone (usually referring
+ to the notion of local time) uses the time-offset -00:00.";
+ reference
+ "RFC 3339: Date and Time on the Internet: Timestamps
+ RFC 2579: Textual Conventions for SMIv2
+ XSD-TYPES: XML Schema Part 2: Datatypes Second Edition";
+ }
+
+ typedef timeticks {
+ type uint32;
+ description
+ "The timeticks type represents a non-negative integer that
+ represents the time, modulo 2^32 (4294967296 decimal), in
+ hundredths of a second between two epochs. When a schema
+ node is defined that uses this type, the description of
+ the schema node identifies both of the reference epochs.
+
+ In the value set and its semantics, this type is equivalent
+ to the TimeTicks type of the SMIv2.";
+ reference
+ "RFC 2578: Structure of Management Information Version 2 (SMIv2)";
+ }
+
+ typedef timestamp {
+ type yang:timeticks;
+ description
+ "The timestamp type represents the value of an associated
+ timeticks schema node at which a specific occurrence happened.
+ The specific occurrence must be defined in the description
+ of any schema node defined using this type. When the specific
+ occurrence occurred prior to the last time the associated
+ timeticks attribute was zero, then the timestamp value is
+ zero. Note that this requires all timestamp values to be
+ reset to zero when the value of the associated timeticks
+ attribute reaches 497+ days and wraps around to zero.
+
+ The associated timeticks schema node must be specified
+ in the description of any schema node using this type.
+
+ In the value set and its semantics, this type is equivalent
+ to the TimeStamp textual convention of the SMIv2.";
+ reference
+ "RFC 2579: Textual Conventions for SMIv2";
+ }
+
+ /*** collection of generic address types ***/
+
+ typedef phys-address {
+ type string {
+ pattern '([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?';
+ }
+ description
+ "Represents media- or physical-level addresses represented
+ as a sequence octets, each octet represented by two hexadecimal
+ numbers. Octets are separated by colons. The canonical
+ representation uses lowercase characters.
+
+ In the value set and its semantics, this type is equivalent
+ to the PhysAddress textual convention of the SMIv2.";
+ reference
+ "RFC 2579: Textual Conventions for SMIv2";
+ }
+
+ typedef mac-address {
+ type string {
+ pattern '[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}';
+ }
+ description
+ "The mac-address type represents an IEEE 802 MAC address.
+ The canonical representation uses lowercase characters.
+
+ In the value set and its semantics, this type is equivalent
+ to the MacAddress textual convention of the SMIv2.";
+ reference
+ "IEEE 802: IEEE Standard for Local and Metropolitan Area
+ Networks: Overview and Architecture
+ RFC 2579: Textual Conventions for SMIv2";
+ }
+
+ /*** collection of XML specific types ***/
+
+ typedef xpath1.0 {
+ type string;
+ description
+ "This type represents an XPATH 1.0 expression.
+
+ When a schema node is defined that uses this type, the
+ description of the schema node MUST specify the XPath
+ context in which the XPath expression is evaluated.";
+ reference
+ "XPATH: XML Path Language (XPath) Version 1.0";
+ }
+
+ }
\ No newline at end of file
--- /dev/null
+module simple-string-demo {
+
+ namespace "urn:simple:string:demo";
+ prefix "sbd";
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision 2013-06-18 {
+
+ }
+
+
+ typedef typedef-string {
+ type string {
+ length "40";
+ pattern "[0-9A-F]*";
+ pattern "[B-D]*";
+ pattern "[4-7]*";
+ }
+ }
+
+}
return validateParameterName(correctStr);
}
+ public static String convertToCapitalLetters(final String token) {
+ String convertedStr = token.replace(" ", "_");
+ convertedStr = convertedStr.replace(".", "_");
+ convertedStr = convertedStr.toUpperCase();
+ return convertedStr;
+ }
+
private static String parseToCamelCase(String token) {
if (token == null) {
throw new NullPointerException("Name can not be null");
--- /dev/null
+package org.opendaylight.controller.binding.generator.util;
+
+public final class TypeConstants {
+
+ public static final String PATTERN_CONSTANT_NAME = "PATTERN_CONSTANTS";
+
+ private TypeConstants() {
+ }
+}
*/
package org.opendaylight.controller.binding.generator.util.generated.type.builder;
-
import org.opendaylight.controller.binding.generator.util.AbstractBaseType;
import org.opendaylight.controller.sal.binding.model.api.*;
import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
private final List<GeneratedType> enclosedTypes;
private final boolean isAbstract;
- public AbstractGeneratedType(final Type parent, final String packageName,
- final String name, final String comment,
- final List<AnnotationTypeBuilder> annotationBuilders,
- final boolean isAbstract,
- final List<Type> implementsTypes,
- final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
- final List<GeneratedTOBuilder> enclosedGenTOBuilders,
- final List<EnumBuilder> enumBuilders,
- final List<Constant> constants,
- final List<MethodSignatureBuilder> methodBuilders) {
+ public AbstractGeneratedType(final Type parent, final String packageName, final String name, final String comment,
+ final List<AnnotationTypeBuilder> annotationBuilders, final boolean isAbstract,
+ final List<Type> implementsTypes, final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
+ final List<GeneratedTOBuilder> enclosedGenTOBuilders, final List<EnumBuilder> enumBuilders,
+ final List<Constant> constants, final List<MethodSignatureBuilder> methodBuilders) {
super(packageName, name);
this.parent = parent;
this.comment = comment;
}
private List<GeneratedType> toUnmodifiableEnclosedTypes(final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
- final List<GeneratedTOBuilder> enclosedGenTOBuilders) {
+ final List<GeneratedTOBuilder> enclosedGenTOBuilders) {
final List<GeneratedType> enclosedTypes = new ArrayList<>();
for (final GeneratedTypeBuilder builder : enclosedGenTypeBuilders) {
if (builder != null) {
return enclosedTypes;
}
- protected List<AnnotationType> toUnmodifiableAnnotations(
- final List<AnnotationTypeBuilder> annotationBuilders) {
+ protected List<AnnotationType> toUnmodifiableAnnotations(final List<AnnotationTypeBuilder> annotationBuilders) {
final List<AnnotationType> annotations = new ArrayList<>();
for (final AnnotationTypeBuilder builder : annotationBuilders) {
annotations.add(builder.toInstance());
return Collections.unmodifiableList(annotations);
}
- protected List<MethodSignature> toUnmodifiableMethods(
- List<MethodSignatureBuilder> methodBuilders) {
+ protected List<MethodSignature> toUnmodifiableMethods(List<MethodSignatureBuilder> methodBuilders) {
final List<MethodSignature> methods = new ArrayList<>();
for (final MethodSignatureBuilder methodBuilder : methodBuilders) {
methods.add(methodBuilder.toInstance(this));
return Collections.unmodifiableList(methods);
}
- protected List<Enumeration> toUnmodifiableEnumerations(
- List<EnumBuilder> enumBuilders) {
+ protected List<Enumeration> toUnmodifiableEnumerations(List<EnumBuilder> enumBuilders) {
final List<Enumeration> enums = new ArrayList<>();
for (final EnumBuilder enumBuilder : enumBuilders) {
enums.add(enumBuilder.toInstance(this));
@Override
public boolean isAbstract() {
- return isAbstract;
+ return isAbstract;
}
- @Override
+ @Override
public List<Type> getImplements() {
return implementsTypes;
}
@Override
public void setComment(String comment) {
if (comment == null) {
- throw new IllegalArgumentException("Comment string cannot be null!");
+ this.comment = "";
}
this.comment = comment;
}
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferIdentityObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.binding.generator.util.TypeConstants;
+import org.opendaylight.controller.sal.binding.model.api.*;
public final class ClassCodeGenerator implements CodeGenerator {
- private Map<String, LinkedHashMap<String, Integer>> imports;
+ private Map<String, String> imports;
@Override
public Writer generate(Type type) throws IOException {
final Writer writer = new StringWriter();
if (type instanceof GeneratedTransferObject) {
- GeneratedTransferObject genTO = (GeneratedTransferObject) type;
+ GeneratedTransferObject genTO = (GeneratedTransferObject) type;
imports = GeneratorUtil.createImports(genTO);
-
+
final String currentPkg = genTO.getPackageName();
final List<GeneratedProperty> fields = genTO.getProperties();
final List<Enumeration> enums = genTO.getEnumerations();
+ final List<Constant> consts = genTO.getConstantDefinitions();
writer.write(GeneratorUtil.createPackageDeclaration(currentPkg));
writer.write(NL);
}
writer.write(NL);
- writer.write(GeneratorUtil.createClassDeclaration(genTO, "",
- imports, genTO.isAbstract()));
+ writer.write(GeneratorUtil.createClassDeclaration(genTO, "", imports, genTO.isAbstract()));
writer.write(NL);
writer.write(NL);
-
- if (enums != null) {
- EnumGenerator enumGenerator = new EnumGenerator();
- for ( Enumeration e : enums ) {
- writer.write(enumGenerator.generateInnerEnumeration(e, TAB).toString());
- writer.write(NL);
- }
+
+ if (consts != null) {
+ for (Constant con : consts) {
+ writer.write(GeneratorUtil.createConstant(con, TAB, imports, currentPkg));
+ writer.write(NL);
+ }
}
- if (fields != null) {
- for (GeneratedProperty field : fields) {
- writer.write(GeneratorUtil.createField(field, TAB, imports,
- currentPkg) + NL);
+ if (enums != null) {
+ EnumGenerator enumGenerator = new EnumGenerator();
+ for (Enumeration e : enums) {
+ writer.write(enumGenerator.generateInnerEnumeration(e, TAB).toString());
+ writer.write(NL);
}
- writer.write(NL);
- writer.write(GeneratorUtil.createConstructor(genTO, TAB,
- imports, genTO.isAbstract()) + NL);
- writer.write(NL);
- for (GeneratedProperty field : fields) {
- writer.write(GeneratorUtil.createGetter(field, TAB,
- imports, currentPkg) + NL);
- if (!field.isReadOnly()) {
- writer.write(GeneratorUtil.createSetter(field, TAB,
- imports, currentPkg) + NL);
+ }
+
+ boolean memberPatternListCodeRequired = false;
+ memberPatternListCodeRequired = (GeneratorUtil.isConstantInTO(TypeConstants.PATTERN_CONSTANT_NAME, genTO));
+ if (fields != null || memberPatternListCodeRequired) {
+ if (fields != null) {
+ for (GeneratedProperty field : fields) {
+ writer.write(GeneratorUtil.createField(field, TAB, imports, currentPkg) + NL);
}
}
- writer.write(NL);
+ if (memberPatternListCodeRequired) {
+ writer.write(TAB + PRIVATE + GAP + "List<Pattern>" + GAP + MEMBER_PATTERN_LIST + GAP + ASSIGN + GAP
+ + "new ArrayList<Pattern>()" + GAP + SC + NL);
- if (!genTO.getHashCodeIdentifiers().isEmpty()) {
- writer.write(GeneratorUtil.createHashCode(
- genTO.getHashCodeIdentifiers(), TAB)
- + NL);
}
+ writer.write(NL);
+ writer.write(GeneratorUtil.createConstructor(genTO, TAB, imports, genTO.isAbstract()) + NL);
+ writer.write(NL);
+ if (fields != null) {
+ for (GeneratedProperty field : fields) {
+ writer.write(GeneratorUtil.createGetter(field, TAB, imports, currentPkg) + NL);
+ if (!field.isReadOnly()) {
+ writer.write(GeneratorUtil.createSetter(field, TAB, imports, currentPkg) + NL);
+ }
+ }
+ writer.write(NL);
- if (!genTO.getEqualsIdentifiers().isEmpty()) {
- writer.write(GeneratorUtil.createEquals(genTO,
- genTO.getEqualsIdentifiers(), TAB)
- + NL);
- }
+ if (!genTO.getHashCodeIdentifiers().isEmpty()) {
+ writer.write(GeneratorUtil.createHashCode(genTO.getHashCodeIdentifiers(), TAB) + NL);
+ }
- if (!genTO.getToStringIdentifiers().isEmpty()) {
- writer.write(GeneratorUtil.createToString(genTO,
- genTO.getToStringIdentifiers(), TAB)
- + NL);
+ if (!genTO.getEqualsIdentifiers().isEmpty()) {
+ writer.write(GeneratorUtil.createEquals(genTO, genTO.getEqualsIdentifiers(), TAB) + NL);
+ }
- }
+ if (!genTO.getToStringIdentifiers().isEmpty()) {
+ writer.write(GeneratorUtil.createToString(genTO, genTO.getToStringIdentifiers(), TAB) + NL);
+ }
- writer.write(RCB);
+ writer.write(RCB);
+ }
}
}
return writer;
}
-
}
public static final String LB = "(";
public static final String RB = ")";
+ public static final String LSB = "[";
+ public static final String RSB = "]";
+
public static final String GAP = " ";
public static final String COMMA = ",";
public static final String NL = "\n";
public static final String SC = ";";
public static final String TAB = " ";
+ public static final String ASSIGN = "=";
+ public static final String DOUBLE_QUOTE = "\"";
public static final String PUBLIC = "public";
public static final String PRIVATE = "private";
public static final String FINAL = "final";
public static final String EXTENDS = "extends";
public static final String IMPLEMENTS = "implements";
-
+
public static final String ENUMERATION_NAME = "value";
- public static final String ENUMERATION_TYPE = "int";
-
- private Constants() {}
+ public static final String ENUMERATION_TYPE = "int";
+
+ public static final String STRING_PATTERN_LIST = "STRING_PATTERNS";
+ public static final String MEMBER_PATTERN_LIST = "patterns";
+
+ private Constants() {
+ }
}
*/
package org.opendaylight.controller.sal.java.api.generator;
-import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
+import static org.opendaylight.controller.sal.java.api.generator.Constants.NL;
import java.io.IOException;
import java.io.StringWriter;
public class EnumGenerator implements CodeGenerator {
- @Override
- public Writer generate(Type type) throws IOException {
- final Writer writer = new StringWriter();
+ @Override
+ public Writer generate(Type type) throws IOException {
+ final Writer writer = new StringWriter();
- if (type instanceof Enumeration) {
- Enumeration enums = (Enumeration) type;
- writer.write(GeneratorUtil.createPackageDeclaration(enums
- .getPackageName()));
- writer.write(NL + NL);
- writer.write(GeneratorUtil.createEnum(enums, ""));
- }
+ if (type instanceof Enumeration) {
+ Enumeration enums = (Enumeration) type;
+ writer.write(GeneratorUtil.createPackageDeclaration(enums.getPackageName()));
+ writer.write(NL + NL);
+ writer.write(GeneratorUtil.createEnum(enums, ""));
+ }
- return writer;
- }
+ return writer;
+ }
- public Writer generateInnerEnumeration(Type type, String indent) throws IOException {
- final Writer writer = new StringWriter();
+ public Writer generateInnerEnumeration(Type type, String indent) throws IOException {
+ final Writer writer = new StringWriter();
- if (type instanceof Enumeration) {
- Enumeration enums = (Enumeration) type;
- writer.write(GeneratorUtil.createEnum(enums, indent));
- }
+ if (type instanceof Enumeration) {
+ Enumeration enums = (Enumeration) type;
+ writer.write(GeneratorUtil.createEnum(enums, indent));
+ }
- return writer;
- }
+ return writer;
+ }
}
*/
package org.opendaylight.controller.sal.java.api.generator;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
+import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class GeneratorJavaFile {
- private static final Logger log = LoggerFactory
- .getLogger(GeneratorJavaFile.class);
+ private static final Logger log = LoggerFactory.getLogger(GeneratorJavaFile.class);
private final CodeGenerator interfaceGenerator;
private final ClassCodeGenerator classGenerator;
private final EnumGenerator enumGenerator;
-
+
private final Set<GeneratedType> genTypes;
private final Set<GeneratedTransferObject> genTransferObjects;
- private final Set<Enumeration> enumerations;
+ private final Set<Enumeration> enumerations;
- public GeneratorJavaFile(final CodeGenerator codeGenerator,
- final Set<GeneratedType> types) {
+ public GeneratorJavaFile(final CodeGenerator codeGenerator, final Set<GeneratedType> types) {
this.interfaceGenerator = codeGenerator;
this.genTypes = types;
this.genTransferObjects = new HashSet<>();
this.enumGenerator = new EnumGenerator();
}
- public GeneratorJavaFile(final Set<GeneratedType> types,
- final Set<GeneratedTransferObject> genTransferObjects,
+ public GeneratorJavaFile(final Set<GeneratedType> types, final Set<GeneratedTransferObject> genTransferObjects,
final Set<Enumeration> enumerations) {
this.interfaceGenerator = new InterfaceGenerator();
this.classGenerator = new ClassCodeGenerator();
this.enumGenerator = new EnumGenerator();
-
+
this.genTypes = types;
this.genTransferObjects = genTransferObjects;
this.enumerations = enumerations;
public List<File> generateToFile(final File parentDirectory) throws IOException {
final List<File> result = new ArrayList<>();
for (GeneratedType type : genTypes) {
- final File genFile = generateTypeToJavaFile(parentDirectory, type,
- interfaceGenerator);
+ final File genFile = generateTypeToJavaFile(parentDirectory, type, interfaceGenerator);
if (genFile != null) {
result.add(genFile);
}
}
for (GeneratedTransferObject transferObject : genTransferObjects) {
- final File genFile = generateTypeToJavaFile(parentDirectory,
- transferObject, classGenerator);
+ final File genFile = generateTypeToJavaFile(parentDirectory, transferObject, classGenerator);
if (genFile != null) {
result.add(genFile);
}
}
-
+
for (Enumeration enumeration : enumerations) {
- final File genFile = generateTypeToJavaFile(parentDirectory,
- enumeration, enumGenerator);
+ final File genFile = generateTypeToJavaFile(parentDirectory, enumeration, enumGenerator);
if (genFile != null) {
result.add(genFile);
}
}
-
+
return result;
}
- private File generateTypeToJavaFile(final File parentDir, final Type type,
- final CodeGenerator generator) throws IOException {
+ private File generateTypeToJavaFile(final File parentDir, final Type type, final CodeGenerator generator)
+ throws IOException {
if (parentDir == null) {
log.warn("Parent Directory not specified, files will be generated "
+ "accordingly to generated Type package path.");
}
if (type == null) {
- log.error("Cannot generate Type into Java File because " +
- "Generated Type is NULL!");
+ log.error("Cannot generate Type into Java File because " + "Generated Type is NULL!");
throw new IllegalArgumentException("Generated Type Cannot be NULL!");
}
if (generator == null) {
- log.error("Cannot generate Type into Java File because " +
- "Code Generator instance is NULL!");
+ log.error("Cannot generate Type into Java File because " + "Code Generator instance is NULL!");
throw new IllegalArgumentException("Code Generator Cannot be NULL!");
}
- final File packageDir = packageToDirectory(parentDir,
- type.getPackageName());
+ final File packageDir = packageToDirectory(parentDir, type.getPackageName());
if (!packageDir.exists()) {
packageDir.mkdirs();
return file;
}
- private File packageToDirectory(final File parentDirectory,
- final String packageName) {
+ private File packageToDirectory(final File parentDirectory, final String packageName) {
if (packageName == null) {
throw new IllegalArgumentException("Package Name cannot be NULL!");
}
import static org.opendaylight.controller.sal.java.api.generator.Constants.*;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
-import org.opendaylight.controller.sal.binding.model.api.Constant;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
+import org.opendaylight.controller.binding.generator.util.TypeConstants;
+import org.opendaylight.controller.sal.binding.model.api.*;
+import org.opendaylight.controller.binding.generator.util.Types;
import org.opendaylight.controller.sal.binding.model.api.Enumeration.Pair;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Parameter;
-import org.opendaylight.controller.sal.binding.model.api.ParameterizedType;
-import org.opendaylight.controller.sal.binding.model.api.Type;
-import org.opendaylight.controller.sal.binding.model.api.WildcardType;
public final class GeneratorUtil {
private GeneratorUtil() {
}
- public static String createIfcDeclaration(final GeneratedType genType,
- final String indent,
- final Map<String, LinkedHashMap<String, Integer>> availableImports) {
- return createFileDeclaration(IFC, genType, indent, availableImports,
- false);
+ public static String createIfcDeclaration(final GeneratedType genType, final String indent,
+ final Map<String, String> availableImports) {
+ return createFileDeclaration(IFC, genType, indent, availableImports, false);
}
- public static String createClassDeclaration(
- final GeneratedTransferObject genTransferObject,
- final String indent,
- final Map<String, LinkedHashMap<String, Integer>> availableImports,
- boolean isIdentity) {
- return createFileDeclaration(CLASS, genTransferObject, indent,
- availableImports, isIdentity);
+ public static String createClassDeclaration(final GeneratedTransferObject genTransferObject, final String indent,
+ final Map<String, String> availableImports, boolean isIdentity) {
+ return createFileDeclaration(CLASS, genTransferObject, indent, availableImports, isIdentity);
}
public static String createPackageDeclaration(final String packageName) {
return PKG + GAP + packageName + SC;
}
- private static String createFileDeclaration(final String type,
- final GeneratedType genType, final String indent,
- final Map<String, LinkedHashMap<String, Integer>> availableImports,
- boolean isIdentity) {
+ private static String createFileDeclaration(final String type, final GeneratedType genType, final String indent,
+ final Map<String, String> availableImports, boolean isIdentity) {
final StringBuilder builder = new StringBuilder();
final String currentPkg = genType.getPackageName();
if (isIdentity) {
if (!(CLASS.equals(type))) {
- throw new IllegalArgumentException(
- "'identity' has to be generated as a class");
+ throw new IllegalArgumentException("'identity' has to be generated as a class");
}
- builder.append(PUBLIC + GAP + ABSTRACT + GAP + type + GAP
- + genType.getName() + GAP);
+ builder.append(PUBLIC + GAP + ABSTRACT + GAP + type + GAP + genType.getName() + GAP);
} else {
builder.append(PUBLIC + GAP + type + GAP + genType.getName() + GAP);
}
} else {
builder.append(EXTENDS + GAP);
}
- builder.append(getExplicitType(genImplements.get(0),
- availableImports, currentPkg));
+ builder.append(getExplicitType(genImplements.get(0), availableImports, currentPkg));
for (int i = 1; i < genImplements.size(); ++i) {
builder.append(", ");
- builder.append(getExplicitType(genImplements.get(i),
- availableImports, currentPkg));
+ builder.append(getExplicitType(genImplements.get(i), availableImports, currentPkg));
}
}
-
builder.append(GAP + LCB);
return builder.toString();
}
- private static StringBuilder appendAnnotations(final StringBuilder builder,
- final List<AnnotationType> annotations) {
+ private static StringBuilder appendAnnotations(final StringBuilder builder, final List<AnnotationType> annotations) {
if ((builder != null) && (annotations != null)) {
for (final AnnotationType annotation : annotations) {
builder.append("@");
if (annotation.containsParameters()) {
builder.append("(");
- final List<AnnotationType.Parameter> parameters = annotation
- .getParameters();
+ final List<AnnotationType.Parameter> parameters = annotation.getParameters();
appendAnnotationParams(builder, parameters);
builder.append(")");
}
return builder;
}
- private static StringBuilder appendAnnotationParams(
- final StringBuilder builder,
+ private static StringBuilder appendAnnotationParams(final StringBuilder builder,
final List<AnnotationType.Parameter> parameters) {
if (parameters != null) {
int i = 0;
return builder;
}
- public static String createConstant(final Constant constant,
- final String indent,
- final Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ public static String createConstant(final Constant constant, final String indent,
+ final Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
+ if (constant == null)
+ throw new IllegalArgumentException();
builder.append(indent + PUBLIC + GAP + STATIC + GAP + FINAL + GAP);
- builder.append(getExplicitType(constant.getType(), availableImports,
- currentPkg) + GAP + constant.getName());
+ builder.append(getExplicitType(constant.getType(), availableImports, currentPkg) + GAP + constant.getName());
builder.append(GAP + "=" + GAP);
- builder.append(constant.getValue() + SC);
+ final Object constValue = constant.getValue();
+
+ if (constant.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
+ if (constant.getName() == null || constant.getType() == null || constant.getValue() == null)
+ throw new IllegalArgumentException();
+ if (constValue instanceof List) {
+ builder.append("Arrays.asList" + LB);
+ final List<?> constantValues = (List<?>) constValue;
+ int stringsCount = 0;
+ for (Object value : constantValues) {
+ if (value instanceof String) {
+ if (stringsCount > 0) {
+ builder.append(COMMA);
+ }
+ stringsCount++;
+ builder.append(DOUBLE_QUOTE + (String) value + DOUBLE_QUOTE);
+ }
+ }
+ builder.append(RB);
+ }
+ } else {
+ builder.append(constant.getValue());
+ }
+ builder.append(SC);
+
return builder.toString();
}
- public static String createField(final GeneratedProperty property,
- final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ public static String createField(final GeneratedProperty property, final String indent,
+ final Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
if (!property.getAnnotations().isEmpty()) {
final List<AnnotationType> annotations = property.getAnnotations();
builder.append(NL);
}
builder.append(indent + PRIVATE + GAP);
- builder.append(getExplicitType(property.getReturnType(),
- availableImports, currentPkg) + GAP + property.getName());
+ builder.append(getExplicitType(property.getReturnType(), availableImports, currentPkg) + GAP
+ + property.getName());
builder.append(SC);
return builder.toString();
}
* @param indent
* @return
*/
- public static String createMethodDeclaration(final MethodSignature method,
- final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ public static String createMethodDeclaration(final MethodSignature method, final String indent,
+ Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
if (method == null) {
- throw new IllegalArgumentException(
- "Method Signature parameter MUST be specified and cannot be NULL!");
+ throw new IllegalArgumentException("Method Signature parameter MUST be specified and cannot be NULL!");
}
final String comment = method.getComment();
final Type type = method.getReturnType();
if (type == null) {
- throw new IllegalStateException(
- "Method Return type cannot be NULL!");
+ throw new IllegalStateException("Method Return type cannot be NULL!");
}
final List<Parameter> parameters = method.getParameters();
builder.append(NL);
}
- builder.append(indent
- + getExplicitType(type, availableImports, currentPkg) + GAP
- + name);
+ builder.append(indent + getExplicitType(type, availableImports, currentPkg) + GAP + name);
builder.append(LB);
for (int i = 0; i < parameters.size(); i++) {
Parameter p = parameters.get(i);
if (i + 1 == parameters.size()) {
separator = "";
}
- builder.append(getExplicitType(p.getType(), availableImports,
- currentPkg) + GAP + p.getName() + separator);
+ builder.append(getExplicitType(p.getType(), availableImports, currentPkg) + GAP + p.getName() + separator);
}
builder.append(RB);
builder.append(SC);
return builder.toString();
}
- public static String createConstructor(
- GeneratedTransferObject genTransferObject, final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- boolean isIdentity) {
+ public static String createConstructor(GeneratedTransferObject genTransferObject, final String indent,
+ final Map<String, String> availableImports, boolean isIdentity) {
final StringBuilder builder = new StringBuilder();
final String currentPkg = genTransferObject.getPackageName();
- final List<GeneratedProperty> properties = genTransferObject
- .getProperties();
+ final List<GeneratedProperty> properties = genTransferObject.getProperties();
final List<GeneratedProperty> ctorParams = new ArrayList<GeneratedProperty>();
- for (final GeneratedProperty property : properties) {
- if (property.isReadOnly()) {
- ctorParams.add(property);
+ if (properties != null) {
+ for (final GeneratedProperty property : properties) {
+ if (property.isReadOnly()) {
+ ctorParams.add(property);
+ }
}
}
builder.append(LB);
if (!ctorParams.isEmpty()) {
- builder.append(getExplicitType(ctorParams.get(0).getReturnType(),
- availableImports, currentPkg));
+ builder.append(getExplicitType(ctorParams.get(0).getReturnType(), availableImports, currentPkg));
builder.append(" ");
builder.append(ctorParams.get(0).getName());
for (int i = 1; i < ctorParams.size(); ++i) {
final GeneratedProperty param = ctorParams.get(i);
builder.append(", ");
- builder.append(getExplicitType(param.getReturnType(),
- availableImports, currentPkg));
+ builder.append(getExplicitType(param.getReturnType(), availableImports, currentPkg));
builder.append(GAP);
builder.append(param.getName());
}
builder.append(NL);
}
}
+ List<Constant> consts = genTransferObject.getConstantDefinitions();
+ for (Constant con : consts) {
+ if (con.getName() == null || con.getType() == null || con.getValue() == null)
+ continue;
+ if (con.getName().equals(TypeConstants.PATTERN_CONSTANT_NAME)) {
+ Object values = con.getValue();
+ if (values instanceof List) {
+ for (Object regEx : (List<?>) values) {
+ if (regEx instanceof String) {
+ builder.append(indent + TAB + "for (String regEx : " + TypeConstants.PATTERN_CONSTANT_NAME
+ + ") {" + NL);
+ builder.append(indent + TAB + TAB + "this." + MEMBER_PATTERN_LIST
+ + ".add(Pattern.compile(regEx))" + SC + NL);
+ builder.append(indent + TAB + RCB + NL);
+
+ break;
+ }
+ }
+
+ }
+ }
+
+ }
+
builder.append(indent);
builder.append(RCB);
return builder.toString();
}
- public static String createGetter(final GeneratedProperty property,
- final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ public static String createGetter(final GeneratedProperty property, final String indent,
+ final Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
final Type type = property.getReturnType();
final char first = Character.toUpperCase(varName.charAt(0));
final String methodName = "get" + first + varName.substring(1);
- builder.append(indent + PUBLIC + GAP
- + getExplicitType(type, availableImports, currentPkg) + GAP
- + methodName);
+ builder.append(indent + PUBLIC + GAP + getExplicitType(type, availableImports, currentPkg) + GAP + methodName);
builder.append(LB + RB + LCB + NL);
String currentIndent = indent + TAB;
return builder.toString();
}
- public static String createSetter(final GeneratedProperty property,
- final String indent,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- String currentPkg) {
+ public static String createSetter(final GeneratedProperty property, final String indent,
+ final Map<String, String> availableImports, final String currentPkg) {
final StringBuilder builder = new StringBuilder();
final Type type = property.getReturnType();
final String methodName = "set" + first + varName.substring(1);
builder.append(indent + PUBLIC + GAP + "void" + GAP + methodName);
- builder.append(LB + getExplicitType(type, availableImports, currentPkg)
- + GAP + varName + RB + LCB + NL);
+ builder.append(LB + getExplicitType(type, availableImports, currentPkg) + GAP + varName + RB + LCB + NL);
String currentIndent = indent + TAB;
- builder.append(currentIndent + "this." + varName + " = " + varName + SC
- + NL);
+ builder.append(currentIndent + "this." + varName + " = " + varName + SC + NL);
builder.append(indent + RCB);
return builder.toString();
}
- public static String createHashCode(
- final List<GeneratedProperty> properties, final String indent) {
+ public static String createHashCode(final List<GeneratedProperty> properties, final String indent) {
StringBuilder builder = new StringBuilder();
builder.append(indent + "public int hashCode() {" + NL);
builder.append(indent + TAB + "final int prime = 31;" + NL);
for (GeneratedProperty property : properties) {
String fieldName = property.getName();
- builder.append(indent + TAB + "result = prime * result + (("
- + fieldName + " == null) ? 0 : " + fieldName
+ builder.append(indent + TAB + "result = prime * result + ((" + fieldName + " == null) ? 0 : " + fieldName
+ ".hashCode());" + NL);
}
return builder.toString();
}
- public static String createEquals(final GeneratedTransferObject type,
- final List<GeneratedProperty> properties, final String indent) {
- StringBuilder builder = new StringBuilder();
+ public static String createEquals(final GeneratedTransferObject type, final List<GeneratedProperty> properties,
+ final String indent) {
+ final StringBuilder builder = new StringBuilder();
final String indent1 = indent + TAB;
final String indent2 = indent1 + TAB;
final String indent3 = indent2 + TAB;
builder.append(indent1 + "}" + NL);
String typeStr = type.getName();
- builder.append(indent1 + typeStr + " other = (" + typeStr + ") obj;"
- + NL);
+ builder.append(indent1 + typeStr + " other = (" + typeStr + ") obj;" + NL);
- for (GeneratedProperty property : properties) {
+ for (final GeneratedProperty property : properties) {
String fieldName = property.getName();
builder.append(indent1 + "if (" + fieldName + " == null) {" + NL);
- builder.append(indent2 + "if (other." + fieldName + " != null) {"
- + NL);
+ builder.append(indent2 + "if (other." + fieldName + " != null) {" + NL);
builder.append(indent3 + "return false;" + NL);
builder.append(indent2 + "}" + NL);
- builder.append(indent1 + "} else if (!" + fieldName
- + ".equals(other." + fieldName + ")) {" + NL);
+ builder.append(indent1 + "} else if (!" + fieldName + ".equals(other." + fieldName + ")) {" + NL);
builder.append(indent2 + "return false;" + NL);
builder.append(indent1 + "}" + NL);
}
builder.append(indent1 + "return true;" + NL);
-
builder.append(indent + RCB + NL);
return builder.toString();
}
- public static String createToString(final GeneratedTransferObject type,
- final List<GeneratedProperty> properties, final String indent) {
+ public static String createToString(final GeneratedTransferObject type, final List<GeneratedProperty> properties,
+ final String indent) {
StringBuilder builder = new StringBuilder();
builder.append(indent);
builder.append("public String toString() {");
builder.append(" [");
boolean first = true;
- for (GeneratedProperty property : properties) {
+ for (final GeneratedProperty property : properties) {
if (first) {
builder.append(property.getName());
builder.append("=\");");
return builder.toString();
}
- public static String createEnum(final Enumeration enumeration,
- final String indent) {
+ public static String createEnum(final Enumeration enumeration, final String indent) {
if (enumeration == null || indent == null)
throw new IllegalArgumentException();
- final StringBuilder builder = new StringBuilder(indent + PUBLIC + GAP
- + ENUM + GAP + enumeration.getName() + GAP + LCB + NL);
+ final StringBuilder builder = new StringBuilder(indent + PUBLIC + GAP + ENUM + GAP + enumeration.getName()
+ + GAP + LCB + NL);
String separator = COMMA + NL;
final List<Pair> values = enumeration.getValues();
if (i + 1 == values.size()) {
separator = SC;
}
- builder.append(indent + TAB + values.get(i).getName() + LB
- + values.get(i).getValue() + RB + separator);
+ builder.append(indent + TAB + values.get(i).getName() + LB + values.get(i).getValue() + RB + separator);
}
builder.append(NL);
builder.append(NL);
final String ENUMERATION_NAME = "value";
final String ENUMERATION_TYPE = "int";
- builder.append(indent + TAB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME
- + SC);
+ builder.append(indent + TAB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME + SC);
builder.append(NL);
- builder.append(indent + TAB + PRIVATE + GAP + enumeration.getName()
- + LB + ENUMERATION_TYPE + GAP + ENUMERATION_NAME + RB + GAP
- + LCB + NL);
- builder.append(indent + TAB + TAB + "this." + ENUMERATION_NAME + GAP
- + "=" + GAP + ENUMERATION_NAME + SC + NL);
+ builder.append(indent + TAB + PRIVATE + GAP + enumeration.getName() + LB + ENUMERATION_TYPE + GAP
+ + ENUMERATION_NAME + RB + GAP + LCB + NL);
+ builder.append(indent + TAB + TAB + "this." + ENUMERATION_NAME + GAP + "=" + GAP + ENUMERATION_NAME + SC + NL);
builder.append(indent + TAB + RCB + NL);
builder.append(indent + RCB);
return builder.toString();
}
- private static String getExplicitType(final Type type,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- final String currentPkg) {
+ private static String getExplicitType(final Type type, final Map<String, String> imports, final String currentPkg) {
if (type == null) {
- throw new IllegalArgumentException(
- "Type parameter MUST be specified and cannot be NULL!");
+ throw new IllegalArgumentException("Type parameter MUST be specified and cannot be NULL!");
+ }
+ if (type.getName() == null) {
+ throw new IllegalArgumentException("Type name cannot be NULL!");
+ }
+ if (type.getPackageName() == null) {
+ throw new IllegalArgumentException("Type cannot have Package Name referenced as NULL!");
+ }
+ if (imports == null) {
+ throw new IllegalArgumentException("Imports Map cannot be NULL!");
}
- String packageName = type.getPackageName();
-
- LinkedHashMap<String, Integer> imports = availableImports.get(type
- .getName());
- if ((imports != null && packageName
- .equals(findMaxValue(imports).get(0)))
- || packageName.equals(currentPkg)) {
+ final String typePackageName = type.getPackageName();
+ final String typeName = type.getName();
+ final String importedPackageName = imports.get(typeName);
+ if (typePackageName.equals(importedPackageName) || typePackageName.equals(currentPkg)) {
final StringBuilder builder = new StringBuilder(type.getName());
if (type instanceof ParameterizedType) {
- ParameterizedType pType = (ParameterizedType) type;
- Type[] pTypes = pType.getActualTypeArguments();
+ final ParameterizedType pType = (ParameterizedType) type;
+ final Type[] pTypes = pType.getActualTypeArguments();
builder.append("<");
- builder.append(getParameters(pTypes, availableImports,
- currentPkg));
+ builder.append(getParameters(pTypes, imports, currentPkg));
builder.append(">");
}
if (builder.toString().equals("Void")) {
return builder.toString();
} else {
final StringBuilder builder = new StringBuilder();
- if (packageName.startsWith("java.lang")) {
+ if (typePackageName.startsWith("java.lang")) {
builder.append(type.getName());
} else {
- if (!packageName.isEmpty()) {
- builder.append(packageName + "." + type.getName());
+ if (!typePackageName.isEmpty()) {
+ builder.append(typePackageName + "." + type.getName());
} else {
builder.append(type.getName());
}
-
}
if (type instanceof ParameterizedType) {
- ParameterizedType pType = (ParameterizedType) type;
- Type[] pTypes = pType.getActualTypeArguments();
+ final ParameterizedType pType = (ParameterizedType) type;
+ final Type[] pTypes = pType.getActualTypeArguments();
builder.append("<");
- builder.append(getParameters(pTypes, availableImports,
- currentPkg));
+ builder.append(getParameters(pTypes, imports, currentPkg));
builder.append(">");
}
if (builder.toString().equals("Void")) {
}
}
- private static String getParameters(final Type[] pTypes,
- Map<String, LinkedHashMap<String, Integer>> availableImports,
- String currentPkg) {
+ private static String getParameters(final Type[] pTypes, Map<String, String> availableImports, String currentPkg) {
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < pTypes.length; i++) {
- Type t = pTypes[i];
+ final Type t = pTypes[i];
String separator = COMMA;
- if (i + 1 == pTypes.length) {
+ if (i == (pTypes.length - 1)) {
separator = "";
}
-
+
String wildcardParam = "";
- if(t instanceof WildcardType) {
+ if (t instanceof WildcardType) {
wildcardParam = "? extends ";
}
-
- builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg)
- + separator);
+ builder.append(wildcardParam + getExplicitType(t, availableImports, currentPkg) + separator);
}
return builder.toString();
}
- private static List<String> findMaxValue(
- LinkedHashMap<String, Integer> imports) {
- final List<String> result = new ArrayList<String>();
-
- int maxValue = 0;
- int currentValue = 0;
- for (Map.Entry<String, Integer> entry : imports.entrySet()) {
- currentValue = entry.getValue();
- if (currentValue > maxValue) {
- result.clear();
- result.add(entry.getKey());
- maxValue = currentValue;
- } else if (currentValue == maxValue) {
- result.add(entry.getKey());
- }
- }
- return result;
- }
-
- private static void createComment(final StringBuilder builder,
- final String comment, final String indent) {
+ private static void createComment(final StringBuilder builder, final String comment, final String indent) {
if (comment != null && comment.length() > 0) {
builder.append(indent + "/*" + NL);
builder.append(indent + comment + NL);
}
}
- public static Map<String, LinkedHashMap<String, Integer>> createImports(
- GeneratedType genType) {
- final Map<String, LinkedHashMap<String, Integer>> imports = new HashMap<String, LinkedHashMap<String, Integer>>();
- final String genTypePkg = genType.getPackageName();
+ public static Map<String, String> createImports(final GeneratedType genType) {
+ if (genType == null) {
+ throw new IllegalArgumentException("Generated Type cannot be NULL!");
+ }
+ final Map<String, String> imports = new LinkedHashMap<>();
final List<Constant> constants = genType.getConstantDefinitions();
- final List<MethodSignature> methods = genType.getMethodDefinitions();
- List<Type> impl = genType.getImplements();
+ final List<MethodSignature> methods = genType.getMethodDefinitions();
+ final List<Type> impl = genType.getImplements();
// IMPLEMENTATIONS
if (impl != null) {
- for (Type t : impl) {
- addTypeToImports(t, imports, genTypePkg);
+ for (final Type type : impl) {
+ putTypeIntoImports(genType, type, imports);
}
}
// CONSTANTS
if (constants != null) {
- for (Constant c : constants) {
- Type ct = c.getType();
- addTypeToImports(ct, imports, genTypePkg);
+ for (final Constant constant : constants) {
+ final Type constantType = constant.getType();
+ putTypeIntoImports(genType, constantType, imports);
+ }
+ }
+
+ // REGULAR EXPRESSION
+ if (genType instanceof GeneratedTransferObject) {
+ if (isConstantInTO(TypeConstants.PATTERN_CONSTANT_NAME, (GeneratedTransferObject) genType)) {
+ putTypeIntoImports(genType, Types.typeForClass(java.util.regex.Pattern.class), imports);
+ putTypeIntoImports(genType, Types.typeForClass(java.util.Arrays.class), imports);
+ putTypeIntoImports(genType, Types.typeForClass(java.util.ArrayList.class), imports);
}
}
// METHODS
if (methods != null) {
- for (MethodSignature m : methods) {
- Type ct = m.getReturnType();
- addTypeToImports(ct, imports, genTypePkg);
- for (MethodSignature.Parameter p : m.getParameters()) {
- addTypeToImports(p.getType(), imports, genTypePkg);
+ for (final MethodSignature method : methods) {
+ final Type methodReturnType = method.getReturnType();
+ putTypeIntoImports(genType, methodReturnType, imports);
+ for (final MethodSignature.Parameter methodParam : method.getParameters()) {
+ putTypeIntoImports(genType, methodParam.getType(), imports);
}
}
}
// PROPERTIES
if (genType instanceof GeneratedTransferObject) {
- GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
-
- List<GeneratedProperty> props = genTO.getProperties();
- if (props != null) {
- for (GeneratedProperty prop : props) {
- Type pt = prop.getReturnType();
- addTypeToImports(pt, imports, genTypePkg);
+ final GeneratedTransferObject genTO = (GeneratedTransferObject) genType;
+ final List<GeneratedProperty> properties = genTO.getProperties();
+ if (properties != null) {
+ for (GeneratedProperty property : properties) {
+ final Type propertyType = property.getReturnType();
+ putTypeIntoImports(genType, propertyType, imports);
}
}
}
return imports;
}
- private static void addTypeToImports(Type type,
- Map<String, LinkedHashMap<String, Integer>> importedTypes,
- String genTypePkg) {
- String typeName = type.getName();
- String typePkg = type.getPackageName();
- if (typePkg.startsWith("java.lang") || typePkg.equals(genTypePkg) ||
- typePkg.isEmpty()) {
- return;
+ private static void putTypeIntoImports(final GeneratedType parentGenType, final Type type,
+ final Map<String, String> imports) {
+ if (parentGenType == null) {
+ throw new IllegalArgumentException("Parent Generated Type parameter MUST be specified and cannot be "
+ + "NULL!");
}
- LinkedHashMap<String, Integer> packages = importedTypes.get(typeName);
- if (packages == null) {
- packages = new LinkedHashMap<String, Integer>();
- packages.put(typePkg, 1);
- importedTypes.put(typeName, packages);
- } else {
- Integer occurrence = packages.get(typePkg);
- if (occurrence == null) {
- packages.put(typePkg, 1);
- } else {
- occurrence++;
- packages.put(typePkg, occurrence);
- }
+ if (parentGenType.getName() == null) {
+ throw new IllegalArgumentException("Parent Generated Type name cannot be NULL!");
+ }
+ if (parentGenType.getPackageName() == null) {
+ throw new IllegalArgumentException("Parent Generated Type cannot have Package Name referenced as NULL!");
+ }
+ if (type == null) {
+ throw new IllegalArgumentException("Type parameter MUST be specified and cannot be NULL!");
+ }
+ if (type.getName() == null) {
+ throw new IllegalArgumentException("Type name cannot be NULL!");
+ }
+ if (type.getPackageName() == null) {
+ throw new IllegalArgumentException("Type cannot have Package Name referenced as NULL!");
}
+ final String typeName = type.getName();
+ final String typePackageName = type.getPackageName();
+ final String parentTypeName = parentGenType.getName();
+ final String parentTypePackageName = parentGenType.getPackageName();
+ if (typeName.equals(parentTypeName) || typePackageName.startsWith("java.lang")
+ || typePackageName.equals(parentTypePackageName) || typePackageName.isEmpty()) {
+ return;
+ }
+ if (!imports.containsKey(typeName)) {
+ imports.put(typeName, typePackageName);
+ }
if (type instanceof ParameterizedType) {
- ParameterizedType pt = (ParameterizedType) type;
- Type[] params = pt.getActualTypeArguments();
+ final ParameterizedType paramType = (ParameterizedType) type;
+ final Type[] params = paramType.getActualTypeArguments();
for (Type param : params) {
- addTypeToImports(param, importedTypes, genTypePkg);
+ putTypeIntoImports(parentGenType, param, imports);
}
}
}
- public static List<String> createImportLines(
- Map<String, LinkedHashMap<String, Integer>> imports) {
- List<String> importLines = new ArrayList<String>();
+ public static List<String> createImportLines(final Map<String, String> imports) {
+ final List<String> importLines = new ArrayList<>();
- for (Map.Entry<String, LinkedHashMap<String, Integer>> entry : imports
- .entrySet()) {
- String typeName = entry.getKey();
- LinkedHashMap<String, Integer> typePkgMap = entry.getValue();
- String typePkg = typePkgMap.keySet().iterator().next();
- importLines.add("import " + typePkg + "." + typeName + SC);
+ for (Map.Entry<String, String> entry : imports.entrySet()) {
+ final String typeName = entry.getKey();
+ final String packageName = entry.getValue();
+ importLines.add("import " + packageName + "." + typeName + SC);
}
return importLines;
}
+ public static boolean isConstantInTO(String constName, GeneratedTransferObject genTO) {
+ if (constName == null || genTO == null)
+ throw new IllegalArgumentException();
+ List<Constant> consts = genTO.getConstantDefinitions();
+ for (Constant cons : consts) {
+ if (cons.getName().equals(constName)) {
+ return true;
+ }
+
+ }
+ return false;
+ }
}
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.opendaylight.controller.sal.binding.model.api.CodeGenerator;
-import org.opendaylight.controller.sal.binding.model.api.Constant;
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
-import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.*;
public final class InterfaceGenerator implements CodeGenerator {
- private Map<String, LinkedHashMap<String, Integer>> imports;
+ private Map<String, String> imports;
- private String generateEnums(List<Enumeration> enums) {
- String result = "";
- if (enums != null) {
- EnumGenerator enumGenerator = new EnumGenerator();
- for (Enumeration en : enums) {
- try {
- result = result
- + (enumGenerator.generateInnerEnumeration(en, TAB).toString() + NL);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return result;
- }
+ private String generateEnums(List<Enumeration> enums) {
+ String result = "";
+ if (enums != null) {
+ EnumGenerator enumGenerator = new EnumGenerator();
+ for (Enumeration en : enums) {
+ try {
+ result = result + (enumGenerator.generateInnerEnumeration(en, TAB).toString() + NL);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return result;
+ }
- private String generateConstants(List<Constant> constants, String pkgName) {
- String result = "";
- if (constants != null) {
- for (Constant c : constants) {
- result = result
- + GeneratorUtil
- .createConstant(c, TAB, imports, pkgName) + NL;
- }
- result.concat(NL);
- }
- return result;
- }
+ private String generateConstants(List<Constant> constants, String pkgName) {
+ String result = "";
+ if (constants != null) {
+ for (Constant c : constants) {
+ result = result + GeneratorUtil.createConstant(c, TAB, imports, pkgName) + NL;
+ }
+ result.concat(NL);
+ }
+ return result;
+ }
- public String generateMethods(List<MethodSignature> methods, String pkgName) {
- String result = "";
+ public String generateMethods(List<MethodSignature> methods, String pkgName) {
+ String result = "";
- if (methods != null) {
- for (MethodSignature m : methods) {
- result = result
- + GeneratorUtil.createMethodDeclaration(m, TAB,
- imports, pkgName) + NL;
- }
- result = result + NL;
- }
- return result;
- }
+ if (methods != null) {
+ for (MethodSignature m : methods) {
+ result = result + GeneratorUtil.createMethodDeclaration(m, TAB, imports, pkgName) + NL;
+ }
+ result = result + NL;
+ }
+ return result;
+ }
- public Writer generate(Type type) throws IOException {
- Writer writer = new StringWriter();
- if (type instanceof GeneratedType
- && !(type instanceof GeneratedTransferObject)) {
- GeneratedType genType = (GeneratedType) type;
- imports = GeneratorUtil.createImports(genType);
+ public Writer generate(Type type) throws IOException {
+ Writer writer = new StringWriter();
+ if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
+ final GeneratedType genType = (GeneratedType) type;
+ imports = GeneratorUtil.createImports(genType);
- final String currentPkg = genType.getPackageName();
- final List<Constant> constants = genType.getConstantDefinitions();
- final List<MethodSignature> methods = genType
- .getMethodDefinitions();
- final List<Enumeration> enums = genType.getEnumerations();
+ final String currentPkg = genType.getPackageName();
+ final List<Constant> constants = genType.getConstantDefinitions();
+ final List<MethodSignature> methods = genType.getMethodDefinitions();
+ final List<Enumeration> enums = genType.getEnumerations();
- writer.write(GeneratorUtil.createPackageDeclaration(genType
- .getPackageName()));
- writer.write(NL);
+ writer.write(GeneratorUtil.createPackageDeclaration(genType.getPackageName()));
+ writer.write(NL);
- List<String> importLines = GeneratorUtil.createImportLines(imports);
- for (String line : importLines) {
- writer.write(line + NL);
- }
- writer.write(NL);
- writer.write(GeneratorUtil.createIfcDeclaration(genType, "",
- imports));
- writer.write(NL);
+ final List<String> importLines = GeneratorUtil.createImportLines(imports);
+ for (String line : importLines) {
+ writer.write(line + NL);
+ }
+ writer.write(NL);
+ writer.write(GeneratorUtil.createIfcDeclaration(genType, "", imports));
+ writer.write(NL);
- writer.write(generateEnums(enums));
- writer.write(generateConstants(constants, currentPkg));
- writer.write(generateMethods(methods, currentPkg));
+ writer.write(generateEnums(enums));
+ writer.write(generateConstants(constants, currentPkg));
+ writer.write(generateMethods(methods, currentPkg));
- writer.write(RCB);
- }
- return writer;
- }
+ writer.write(RCB);
+ }
+ return writer;
+ }
}
module controller-openflow-ne {
- yang-version 1;
- namespace "urn:opendaylight:controller:network:openflow";
- prefix "of";
-
- import controller-network {
- prefix cn;
- }
- import ietf-inet-types { prefix "inet"; }
-
- revision 2013-06-07 {
- description "Initial demo";
- }
+ yang-version 1;
+ namespace "urn:opendaylight:controller:network:openflow";
+ prefix "of";
+
+ import controller-network {
+ prefix cn;
+ }
+ import ietf-inet-types { prefix "inet"; }
+
+ revision 2013-06-07 {
+ description "Initial demo";
+ }
- augment "/cn:network/cn:network-elements/cn:network-element" {
+ augment "/cn:network/cn:network-elements/cn:network-element" {
- container flow-tables {
- list flow-table {
+ container flow-tables {
+ list flow-table {
- key "id";
- leaf id {
- type int32;
- }
+ key "id";
+ leaf id {
+ type int32;
+ }
- container flows {
- list flow {
- key "name";
- leaf name {
- type string;
- }
- container match {
- leaf input-port {
- type cn:tp-ref;
- }
- leaf nl-src {
- type inet:ipv4-address;
- }
- leaf nl-dst {
- type inet:ipv4-address;
- }
- }
- container actions {
- list action {
- leaf type {
- type string;
- }
- }
- }
- }
- }
- }
- }
- }
+ container flows {
+ list flow {
+ key "name";
+ leaf name {
+ type string;
+ }
+ container match {
+ leaf input-port {
+ type cn:tp-ref;
+ }
+ leaf nl-src {
+ type inet:ipv4-address;
+ }
+ leaf nl-dst {
+ type inet:ipv4-address;
+ }
+ }
+ container actions {
+ list action {
+ leaf type {
+ type string;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
\ No newline at end of file
module controller-network {
- yang-version 1;
- namespace "urn:opendaylight:controller:network";
- prefix "topos";
-
- import ietf-inet-types { prefix "inet"; }
-
- revision 2013-05-20 {
- description "Initial demo";
- }
-
+ yang-version 1;
+ namespace "urn:opendaylight:controller:network";
+ prefix "topos";
+
+ import ietf-inet-types { prefix "inet"; }
+
+ revision 2013-05-20 {
+ description "Initial demo";
+ }
-
- typedef topology-id {
- type string;
- }
+ typedef topology-id {
+ type string;
+ }
- typedef node-id {
- type string;
- }
+ typedef node-id {
+ type string;
+ }
- typedef link-id {
- type string;
- }
+ typedef link-id {
+ type string;
+ }
- typedef tp-id {
- type string;
- description "identifier for termination points on a port";
- }
+ typedef tp-id {
+ type string;
+ description "identifier for termination points on a port";
+ }
- typedef tp-ref {
- type leafref {
- path "/network/topologies/topology/nodes/node/termination-points/termination-point/tp-id";
- }
- }
- typedef topology-ref {
- type leafref {
- path "/network/topologies/topology/topology-id";
- }
- description "This type is used for leafs that reference topology identifier instance.";
- // currently not used
- }
+ typedef tp-ref {
+ type leafref {
+ path "/network/topologies/topology/nodes/node/termination-points/termination-point/tp-id";
+ }
+ }
+ typedef topology-ref {
+ type leafref {
+ path "/network/topologies/topology/topology-id";
+ }
+ description "This type is used for leafs that reference topology identifier instance.";
+ // currently not used
+ }
- typedef node-ref {
- type leafref {
- path "/network/topologies/topology/nodes/node/node-id";
- }
- description "This type is used for leafs that reference a node instance.";
- }
+ typedef node-ref {
+ type leafref {
+ path "/network/topologies/topology/nodes/node/node-id";
+ }
+ description "This type is used for leafs that reference a node instance.";
+ }
- typedef link-ref {
- type leafref {
- path "/network/topologies/topology/links/link/link-id";
- }
- description "This type is used for leafs that reference a link instance.";
- // currently not used
- }
-
- typedef network-element-ref {
- type leafref {
- path "/network/network-elements/network-element/element-id";
- }
- }
+ typedef link-ref {
+ type leafref {
+ path "/network/topologies/topology/links/link/link-id";
+ }
+ description "This type is used for leafs that reference a link instance.";
+ // currently not used
+ }
+
+ typedef network-element-ref {
+ type leafref {
+ path "/network/network-elements/network-element/element-id";
+ }
+ }
+ typedef element-id {
+ type string;
+ }
+
+ container network {
+ container topologies {
+ list topology {
+ description "
+ This is the model of abstract topology which contains only Network
+ Nodes and Network Links. Each topology MUST be identified by
+ unique topology-id for reason that the store could contain many
+ topologies.
+ ";
+ key "topology-id";
+ leaf topology-id {
+ type topology-id;
+ description "
+ It is presumed that datastore will contain many topologies. To
+ distinguish between topologies it is vital to have UNIQUE
+ topology identifier.
+ ";
+ }
- typedef element-id {
- type string;
- }
-
- container network {
- container topologies {
- list topology {
- description "
- This is the model of abstract topology which contains only Network
- Nodes and Network Links. Each topology MUST be identified by
- unique topology-id for reason that the store could contain many
- topologies.
- ";
- key "topology-id";
- leaf topology-id {
- type topology-id;
- description "
- It is presumed that datastore will contain many topologies. To
- distinguish between topologies it is vital to have UNIQUE
- topology identifier.
- ";
- }
+ container types {
+ description "
+ The container for definition of topology types.
+ The augmenting modules should add empty optional leaf
+ to this container to signalize topology type.";
+ }
- container types {
- description "
- The container for definition of topology types.
- The augmenting modules should add empty optional leaf
- to this container to signalize topology type.
- ";
- }
+ container nodes {
+ list node {
+ description "The list of network nodes defined for topology.";
- container nodes {
- list node {
- description "The list of network nodes defined for topology.";
+ key "node-id";
+ leaf node-id {
+ type node-id;
+ description "The Topology identifier of network-node.";
+ }
- key "node-id";
- leaf node-id {
- type node-id;
- description "The Topology identifier of network-node.";
- }
-
- leaf supporting-ne {
- type network-element-ref;
- }
-
- container termination-points {
- list termination-point {
- key "tp-id";
- leaf tp-id {
- type tp-id;
- }
- }
- }
- }
- }
-
- container links {
- list link {
- description "
- The Network Link which is defined by Local (Source) and
- Remote (Destination) Network Nodes. Every link MUST be
- defined either by identifier and his local and remote
- Network Nodes (in real applications it is common that many
- links are originated from one node and end up in same
- remote node). To ensure that we would always know to
- distinguish between links, every link SHOULD have
- identifier.
- ";
- key "link-id";
-
- leaf link-id {
- type link-id;
- }
- container source {
- leaf source-node {
- type node-ref;
- description "Source node identifier.";
- }
- leaf source-tp {
- type tp-ref;
- }
- }
- container destination {
- leaf dest-node {
- type node-ref;
- description "Destination node identifier.";
- }
- leaf dest-tp {
- type tp-ref;
- }
- }
- }
- }
- }
- }
- container network-elements {
- config true;
- list network-element {
- key "element-id";
- leaf element-id {
- type element-id;
- }
- }
- }
- }
+ leaf supporting-ne {
+ type network-element-ref;
+ }
+
+ container termination-points {
+ list termination-point {
+ key "tp-id";
+ leaf tp-id {
+ type tp-id;
+ }
+ }
+ }
+ }
+ }
+
+ container links {
+ list link {
+ description "
+ The Network Link which is defined by Local (Source) and
+ Remote (Destination) Network Nodes. Every link MUST be
+ defined either by identifier and his local and remote
+ Network Nodes (in real applications it is common that many
+ links are originated from one node and end up in same
+ remote node). To ensure that we would always know to
+ distinguish between links, every link SHOULD have
+ identifier.
+ ";
+ key "link-id";
+
+ leaf link-id {
+ type link-id;
+ }
+ container source {
+ leaf source-node {
+ type node-ref;
+ description "Source node identifier.";
+ }
+ leaf source-tp {
+ type tp-ref;
+ }
+ }
+ container destination {
+ leaf dest-node {
+ type node-ref;
+ description "Destination node identifier.";
+ }
+ leaf dest-tp {
+ type tp-ref;
+ }
+ }
+ }
+ }
+ }
+ }
+ container network-elements {
+ config true;
+ list network-element {
+ key "element-id";
+ leaf element-id {
+ type element-id;
+ }
+ }
+ }
+ }
}
revision 2013-06-07 {
description "Initial demo";
}
-
-
-
- augment "/cn:network/cn:network-elements/cn:network-element/of:flow-tables/of:flow-table/of:flows/of:flow/of:match" {
-
- leaf nl-src {
- type inet:ipv6-prefix;
- }
-
- leaf nl-dst {
- type inet:ipv6-prefix;
- }
- }
-
}
\ No newline at end of file
namespace "urn:opendaylight:controller:openflow";
prefix "of";
import controller-network {prefix cn;}
-
-
+
revision 2013-05-20 {
description "Initial demo";
}
-
-
-
-
typedef datapath-id {
type string {
length 16;
--- /dev/null
+module simple-string-demo {
+
+ namespace "urn:simple:string:demo";
+ prefix "sbd";
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision 2013-06-18 {
+
+ }
+
+ typedef typedef-string {
+ type string {
+ length "40";
+ pattern "[0-9A-F]\.*";
+ pattern "[B-D]*";
+ pattern "[4-7]*";
+ }
+ }
+
+}
import org.opendaylight.controller.yang.model.api.GroupingDefinition;
public abstract class AbstractDataNodeContainerBuilder implements DataNodeContainerBuilder {
-
private final QName qname;
protected Set<DataSchemaNode> childNodes;
}
@Override
- public Set<DataSchemaNodeBuilder> getChildNodes() {
+ public Set<DataSchemaNode> getChildNodes() {
+ return childNodes;
+ }
+
+ @Override
+ public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
return addedChildNodes;
}
this.childNodes = childNodes;
}
- public Set<GroupingBuilder> getGroupings() {
+ @Override
+ public Set<GroupingDefinition> getGroupings() {
+ return groupings;
+ }
+
+ public Set<GroupingBuilder> getGroupingBuilders() {
return addedGroupings;
}
--- /dev/null
+/*\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.controller.yang.parser.builder.api;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.opendaylight.controller.yang.common.QName;\r
+import org.opendaylight.controller.yang.model.api.SchemaPath;\r
+import org.opendaylight.controller.yang.model.api.Status;\r
+import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;\r
+\r
+/**\r
+ * Basic implementation of SchemaNodeBuilder.\r
+ */\r
+public abstract class AbstractSchemaNodeBuilder implements SchemaNodeBuilder {\r
+ protected final int line;\r
+ protected final QName qname;\r
+ protected SchemaPath path;\r
+ protected String description;\r
+ protected String reference;\r
+ protected Status status = Status.CURRENT;\r
+ protected final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();\r
+\r
+ protected AbstractSchemaNodeBuilder(final QName qname, final int line) {\r
+ this.qname = qname;\r
+ this.line = line;\r
+ }\r
+\r
+ @Override\r
+ public int getLine() {\r
+ return line;\r
+ }\r
+\r
+ public QName getQName() {\r
+ return qname;\r
+ }\r
+\r
+ public SchemaPath getPath() {\r
+ return path;\r
+ }\r
+\r
+ public void setPath(SchemaPath schemaPath) {\r
+ this.path = schemaPath;\r
+ }\r
+\r
+ public String getDescription() {\r
+ return description;\r
+ }\r
+\r
+ public void setDescription(String description) {\r
+ this.description = description;\r
+ }\r
+\r
+ public String getReference() {\r
+ return reference;\r
+ }\r
+\r
+ public void setReference(String reference) {\r
+ this.reference = reference;\r
+ }\r
+\r
+ public Status getStatus() {\r
+ return status;\r
+ }\r
+\r
+ public void setStatus(Status status) {\r
+ if (status != null) {\r
+ this.status = status;\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {\r
+ addedUnknownNodes.add(unknownNode);\r
+ }\r
+\r
+}\r
*/
package org.opendaylight.controller.yang.parser.builder.api;
-import java.util.Set;
-
import org.opendaylight.controller.yang.model.api.AugmentationSchema;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
*/
public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder {
+ Builder getParent();
+
String getWhenCondition();
void addWhenCondition(String whenCondition);
void setTargetPath(SchemaPath path);
- Set<DataSchemaNodeBuilder> getChildNodes();
-
AugmentationSchema build();
boolean isResolved();
*/
package org.opendaylight.controller.yang.parser.builder.api;
+import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+
/**
* Parent interface for all builder interfaces.
*/
int getLine();
+ void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode);
+
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.builder.api;
+
+/**
+ * Interface for all nodes which can have 'config' statement.
+ * [container, leaf, leaf-list, list, choice, anyxml, deviate]
+ *
+ */
+public interface ConfigNode {
+
+ Boolean isConfiguration();
+
+ void setConfiguration(Boolean config);
+
+}
import java.util.Set;
import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
import org.opendaylight.controller.yang.model.api.SchemaPath;
/**
QName getQName();
- Set<DataSchemaNodeBuilder> getChildNodes();
+ SchemaPath getPath();
+
+ Set<DataSchemaNode> getChildNodes();
+
+ Set<DataSchemaNodeBuilder> getChildNodeBuilders();
void addChildNode(DataSchemaNodeBuilder childNode);
- Set<GroupingBuilder> getGroupings();
+ Set<GroupingDefinition> getGroupings();
+
+ Set<GroupingBuilder> getGroupingBuilders();
void addGrouping(GroupingBuilder groupingBuilder);
void addUsesNode(UsesNodeBuilder usesBuilder);
- Set<TypeDefinitionBuilder> getTypeDefinitions();
+ Set<TypeDefinitionBuilder> getTypeDefinitionBuilders();
void addTypedef(TypeDefinitionBuilder typedefBuilder);
- SchemaPath getPath();
-
}
void setAugmenting(boolean augmenting);
- boolean isConfiguration();
-
- void setConfiguration(boolean configuration);
-
ConstraintsBuilder getConstraints();
}
import java.util.Set;
import org.opendaylight.controller.yang.model.api.GroupingDefinition;
-import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
/**
* Interface for builders of 'grouping' statement.
*/
-public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBuilder,
- TypeDefinitionAwareBuilder {
-
- String getDescription();
-
- String getReference();
-
- Status getStatus();
+public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBuilder, TypeDefinitionAwareBuilder, GroupingMember {
GroupingDefinition build();
List<UnknownSchemaNodeBuilder> getUnknownNodes();
- Set<GroupingBuilder> getGroupings();
-
Set<UsesNodeBuilder> getUses();
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.builder.api;
+
+/**
+ * Marker interface for nodes which can be defined in grouping statement.
+ * [anyxml, choice, container, grouping, leaf, leaf-list, list, typedef, uses]
+ */
+public interface GroupingMember extends Builder {
+
+ boolean isAddedByUses();
+
+ void setAddedByUses(boolean addedByUses);
+
+}
\r
import java.util.List;\r
\r
-import org.opendaylight.controller.yang.model.api.Status;\r
import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
import org.opendaylight.controller.yang.model.api.type.LengthConstraint;\r
import org.opendaylight.controller.yang.model.api.type.PatternConstraint;\r
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;\r
/**\r
* Interface for builders of 'typedef' statement.\r
*/\r
-public interface TypeDefinitionBuilder extends TypeAwareBuilder,\r
- SchemaNodeBuilder {\r
+public interface TypeDefinitionBuilder extends TypeAwareBuilder, SchemaNodeBuilder, GroupingMember {\r
\r
TypeDefinition<?> build();\r
\r
- String getDescription();\r
-\r
- String getReference();\r
-\r
- Status getStatus();\r
-\r
List<RangeConstraint> getRanges();\r
\r
void setRanges(List<RangeConstraint> ranges);\r
\r
void setFractionDigits(Integer fractionDigits);\r
\r
- List<UnknownSchemaNodeBuilder> getUnknownNodes();\r
+ List<UnknownSchemaNode> getUnknownNodes();\r
+\r
+ List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders();\r
\r
Object getDefaultValue();\r
\r
/**
* Interface for builders of 'uses' statement.
*/
-public interface UsesNodeBuilder extends Builder {
+public interface UsesNodeBuilder extends GroupingMember, Builder {
- String getGroupingName();
+ DataNodeContainerBuilder getParent();
- void setGroupingPath(SchemaPath groupingPath);
+ String getGroupingName();
- SchemaPath getPath();
+ SchemaPath getGroupingPath();
- void setPath(SchemaPath path);
+ void setGroupingPath(SchemaPath groupingPath);
Set<AugmentationSchemaBuilder> getAugmentations();
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
-public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
+public final class AnyXmlBuilder extends AbstractSchemaNodeBuilder implements DataSchemaNodeBuilder, GroupingMember,
+ ConfigNode {
private boolean built;
- private final int line;
- private final QName qname;
- private SchemaPath path;
private final AnyXmlSchemaNodeImpl instance;
private final ConstraintsBuilder constraints;
private List<UnknownSchemaNode> unknownNodes;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
- private String description;
- private String reference;
- private Status status = Status.CURRENT;
- private boolean configuration;
+ private Boolean configuration;
private boolean augmenting;
+ private boolean addedByUses;
- public AnyXmlBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ public AnyXmlBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
+ super(qname, line);
+ this.path = schemaPath;
instance = new AnyXmlSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public AnyXmlBuilder(final AnyXmlBuilder builder) {
+ super(builder.qname, builder.line);
+ instance = new AnyXmlSchemaNodeImpl(qname);
+ constraints = builder.constraints;
+ path = builder.path;
+ unknownNodes = builder.unknownNodes;
+ for (UnknownSchemaNodeBuilder un : builder.addedUnknownNodes) {
+ addedUnknownNodes.add(un);
+ }
+ description = builder.description;
+ reference = builder.reference;
+ status = builder.status;
+ configuration = builder.configuration;
+ augmenting = builder.augmenting;
+ addedByUses = builder.addedByUses;
+ }
+
@Override
public AnyXmlSchemaNode build() {
if (!built) {
instance.setStatus(status);
instance.setConfiguration(configuration);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
// UNKNOWN NODES
- if(unknownNodes == null) {
+ if (unknownNodes == null) {
unknownNodes = new ArrayList<UnknownSchemaNode>();
for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
unknownNodes.add(b.build());
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- public SchemaPath getPath() {
- return path;
- }
-
- @Override
- public void setPath(final SchemaPath path) {
- this.path = path;
- }
-
@Override
public ConstraintsBuilder getConstraints() {
return constraints;
}
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
-
public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
return addedUnknownNodes;
}
this.unknownNodes = unknownNodes;
}
- public String getDescription() {
- return description;
- }
-
@Override
- public void setDescription(final String description) {
- this.description = description;
- }
-
- public String getReference() {
- return reference;
+ public boolean isAugmenting() {
+ return augmenting;
}
@Override
- public void setReference(final String reference) {
- this.reference = reference;
- }
-
- public Status getStatus() {
- return status;
+ public void setAugmenting(final boolean augmenting) {
+ this.augmenting = augmenting;
}
@Override
- public void setStatus(final Status status) {
- if (status != null) {
- this.status = status;
- }
+ public boolean isAddedByUses() {
+ return addedByUses;
}
@Override
- public boolean isAugmenting() {
- return augmenting;
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
}
@Override
- public void setAugmenting(final boolean augmenting) {
- this.augmenting = augmenting;
- }
-
- public boolean isConfiguration() {
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(final boolean configuration) {
- instance.setConfiguration(configuration);
+ public void setConfiguration(final Boolean configuration) {
+ this.configuration = configuration;
}
private final class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
private boolean configuration;
private ConstraintDefinition constraintsDef;
private boolean augmenting;
+ private boolean addedByUses;
private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private AnyXmlSchemaNodeImpl(final QName qname) {
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- AnyXmlSchemaNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(AnyXmlSchemaNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append(", path=" + path);
*/
package org.opendaylight.controller.yang.parser.builder.impl;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
private boolean built;
private final AugmentationSchemaImpl instance;
private final int line;
+ private final Builder parent;
+
+ private String whenCondition;
+ private String description;
+ private String reference;
+ private Status status = Status.CURRENT;
+
private final String augmentTargetStr;
- private SchemaPath augmentTarget;
+ private SchemaPath dirtyAugmentTarget;
private SchemaPath finalAugmentTarget;
- private String whenCondition;
+
private final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
private final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
private final Set<UsesNodeBuilder> usesNodes = new HashSet<UsesNodeBuilder>();
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
private boolean resolved;
- AugmentationSchemaBuilderImpl(final String augmentTargetStr, final int line) {
+ AugmentationSchemaBuilderImpl(final String augmentTargetStr, final int line, final Builder parent) {
this.augmentTargetStr = augmentTargetStr;
this.line = line;
+ this.parent = parent;
final SchemaPath targetPath = YangModelBuilderUtil
.parseAugmentPath(augmentTargetStr);
- augmentTarget = targetPath;
+ dirtyAugmentTarget = targetPath;
instance = new AugmentationSchemaImpl(targetPath);
}
return line;
}
+ @Override
+ public Builder getParent() {
+ return parent;
+ }
+
+
@Override
public void addChildNode(DataSchemaNodeBuilder childNode) {
childNodes.add(childNode);
}
@Override
- public Set<DataSchemaNodeBuilder> getChildNodes() {
+ public Set<DataSchemaNode> getChildNodes() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
return childNodes;
}
@Override
- public Set<GroupingBuilder> getGroupings() {
+ public Set<GroupingDefinition> getGroupings() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<GroupingBuilder> getGroupingBuilders() {
return groupings;
}
@Override
public AugmentationSchema build() {
if (!built) {
+ instance.setDescription(description);
+ instance.setReference(reference);
+ instance.setStatus(status);
instance.setTargetPath(finalAugmentTarget);
RevisionAwareXPath whenStmt;
}
instance.setUses(usesNodeDefinitions);
+ // UNKNOWN NODES
+ List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ instance.setUnknownSchemaNodes(unknownNodes);
+
built = true;
}
return instance;
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return Collections.emptySet();
}
@Override
public void addTypedef(TypeDefinitionBuilder type) {
throw new YangParseException(line,
- "Augmentation can not contains type definitions");
+ "Augmentation can not contains typedef statement.");
}
@Override
public void setDescription(String description) {
- instance.setDescription(description);
+ this.description = description;
}
@Override
public void setReference(String reference) {
- instance.setReference(reference);
+ this.reference = reference;
}
@Override
public void setStatus(Status status) {
- instance.setStatus(status);
+ if(status != null) {
+ this.status = status;
+ }
}
@Override
public SchemaPath getTargetPath() {
- return augmentTarget;
+ return dirtyAugmentTarget;
}
@Override
return augmentTargetStr;
}
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return addedUnknownNodes;
+ }
+
+ @Override
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+ addedUnknownNodes.add(unknownNode);
+ }
+
@Override
public int hashCode() {
final int prime = 17;
private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
private Set<GroupingDefinition> groupings = Collections.emptySet();
private Set<UsesNode> uses = Collections.emptySet();
-
private String description;
private String reference;
private Status status;
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private AugmentationSchemaImpl(SchemaPath targetPath) {
this.targetPath = targetPath;
this.status = status;
}
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ private void setUnknownSchemaNodes(
+ List<UnknownSchemaNode> unknownSchemaNodes) {
+ if (unknownSchemaNodes != null) {
+ this.unknownNodes = unknownSchemaNodes;
+ }
+ }
+
@Override
public DataSchemaNode getDataChildByName(QName name) {
return childNodes.get(name);
AugmentationSchemaImpl.class.getSimpleName());
sb.append("[");
sb.append("targetPath=" + targetPath);
- sb.append(", childNodes=" + childNodes.values());
- sb.append(", groupings=" + groupings);
- sb.append(", uses=" + uses);
+ sb.append(", when=" + whenCondition);
sb.append("]");
return sb.toString();
}
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
+import org.opendaylight.controller.yang.parser.util.ParserUtils;
-public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationTargetBuilder {
+public final class ChoiceBuilder extends AbstractSchemaNodeBuilder implements DataSchemaNodeBuilder,
+ AugmentationTargetBuilder, GroupingMember, ConfigNode {
private boolean isBuilt;
private final ChoiceNodeImpl instance;
- private final int line;
// SchemaNode args
- private final QName qname;
- private SchemaPath schemaPath;
- private String description;
- private String reference;
- private Status status = Status.CURRENT;
private List<UnknownSchemaNode> unknownNodes;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
// DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
+ private boolean addedByUses;
+ private Boolean configuration;
private final ConstraintsBuilder constraints;
// AugmentationTarget args
private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
private String defaultCase;
public ChoiceBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ super(qname, line);
instance = new ChoiceNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public ChoiceBuilder(ChoiceBuilder b) {
+ super(b.getQName(), b.getLine());
+ instance = new ChoiceNodeImpl(qname);
+ constraints = b.constraints;
+ path = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ addedAugmentations.addAll(b.getAugmentations());
+ cases = b.cases;
+ addedCases.addAll(b.getCases());
+ defaultCase = b.getDefaultCase();
+ }
+
@Override
public ChoiceNode build() {
if (!isBuilt) {
- instance.setPath(schemaPath);
+ instance.setPath(path);
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
instance.setConfiguration(configuration);
instance.setConstraints(constraints.build());
instance.setDefaultCase(defaultCase);
// CASES
- if(cases == null) {
+ if (cases == null) {
cases = new HashSet<ChoiceCaseNode>();
for (ChoiceCaseBuilder caseBuilder : addedCases) {
cases.add(caseBuilder.build());
instance.setAvailableAugmentations(augmentations);
// UNKNOWN NODES
- if(unknownNodes == null) {
+ if (unknownNodes == null) {
unknownNodes = new ArrayList<UnknownSchemaNode>();
for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
unknownNodes.add(b.build());
build();
}
- @Override
- public int getLine() {
- return line;
- }
-
public Set<ChoiceCaseBuilder> getCases() {
return addedCases;
}
public void addChildNode(DataSchemaNodeBuilder childNode) {
if (!(childNode instanceof ChoiceCaseBuilder)) {
- ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(childNode.getQName(), childNode.getLine());
+ ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(this, childNode.getQName(), childNode.getLine());
+ caseBuilder.setPath(childNode.getPath());
+ SchemaPath newPath = ParserUtils.createSchemaPath(childNode.getPath(), childNode.getQName().getLocalName());
+ childNode.setPath(newPath);
caseBuilder.addChildNode(childNode);
addedCases.add(caseBuilder);
} else {
this.cases = cases;
}
- @Override
- public QName getQName() {
- return qname;
- }
-
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(final SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- public String getDescription() {
- return description;
- }
-
- @Override
- public void setDescription(final String description) {
- this.description = description;
- }
-
- public String getReference() {
- return reference;
+ public boolean isAugmenting() {
+ return augmenting;
}
@Override
- public void setReference(String reference) {
- this.reference = reference;
- }
-
- public Status getStatus() {
- return status;
+ public void setAugmenting(boolean augmenting) {
+ this.augmenting = augmenting;
}
@Override
- public void setStatus(Status status) {
- if (status != null) {
- this.status = status;
- }
- }
-
- public boolean isAugmenting() {
- return augmenting;
+ public boolean isAddedByUses() {
+ return addedByUses;
}
@Override
- public void setAugmenting(boolean augmenting) {
- this.augmenting = augmenting;
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
}
- public boolean isConfiguration() {
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(boolean configuration) {
+ public void setConfiguration(Boolean configuration) {
this.configuration = configuration;
}
return addedUnknownNodes;
}
- @Override
- public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
-
public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
this.unknownNodes = unknownNodes;
}
private String reference;
private Status status = Status.CURRENT;
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraints;
private Set<ChoiceCaseNode> cases = Collections.emptySet();
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
import org.opendaylight.controller.yang.parser.util.YangParseException;
-public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements
- DataSchemaNodeBuilder, AugmentationTargetBuilder {
+public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements DataSchemaNodeBuilder,
+ AugmentationTargetBuilder {
private boolean isBuilt;
private final ChoiceCaseNodeImpl instance;
+ private final ChoiceBuilder parent;
private final int line;
+ // SchemaNode args
private SchemaPath schemaPath;
private String description;
private String reference;
private Status status = Status.CURRENT;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ // DataSchemaNode args
private boolean augmenting;
private final ConstraintsBuilder constraints;
+ // DataNodeContainer args
private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+ // AugmentationTarget args
private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
- ChoiceCaseBuilder(final QName qname, final int line) {
+ ChoiceCaseBuilder(final ChoiceBuilder parent, final QName qname, final int line) {
super(qname);
+ this.parent = parent;
this.line = line;
instance = new ChoiceCaseNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
@Override
public ChoiceCaseNode build() {
- if(!isBuilt) {
+ if (!isBuilt) {
instance.setConstraints(constraints.build());
instance.setPath(schemaPath);
instance.setDescription(description);
return line;
}
+ public ChoiceBuilder getParent() {
+ return parent;
+ }
+
public SchemaPath getPath() {
return schemaPath;
}
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return Collections.emptySet();
}
@Override
public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
- throw new YangParseException(line,
- "Can not add type definition to choice case.");
- }
-
- @Override
- public boolean isConfiguration() {
- return false;
- }
-
- @Override
- public void setConfiguration(boolean configuration) {
- throw new YangParseException(line,
- "Can not add config definition to choice case.");
+ throw new YangParseException(line, "Can not add type definition to choice case.");
}
@Override
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return false;
+ }
+
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return unknownNodes;
return augmentations;
}
- private void setAvailableAugmentations(
- Set<AugmentationSchema> augmentations) {
+ private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
if (augmentations != null) {
this.augmentations = augmentations;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ChoiceCaseNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ChoiceCaseNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append("]");
import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
import org.opendaylight.controller.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
public final class ConstraintsBuilder implements Builder {
private final ConstraintDefinitionImpl instance;
return line;
}
+ @Override
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+ throw new YangParseException(line, "Can not add unknown node to constraints.");
+ }
+
public Integer getMinElements() {
return min;
}
this.mandatory = mandatory;
}
- private final class ConstraintDefinitionImpl implements
- ConstraintDefinition {
+ private final class ConstraintDefinitionImpl implements ConstraintDefinition {
private RevisionAwareXPath whenCondition;
private Set<MustDefinition> mustConstraints;
private boolean mandatory;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((whenCondition == null) ? 0 : whenCondition.hashCode());
- result = prime
- * result
- + ((mustConstraints == null) ? 0 : mustConstraints
- .hashCode());
- result = prime * result
- + ((minElements == null) ? 0 : minElements.hashCode());
- result = prime * result
- + ((maxElements == null) ? 0 : maxElements.hashCode());
+ result = prime * result + ((whenCondition == null) ? 0 : whenCondition.hashCode());
+ result = prime * result + ((mustConstraints == null) ? 0 : mustConstraints.hashCode());
+ result = prime * result + ((minElements == null) ? 0 : minElements.hashCode());
+ result = prime * result + ((maxElements == null) ? 0 : maxElements.hashCode());
result = prime * result + (mandatory ? 1231 : 1237);
return result;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ConstraintDefinitionImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ConstraintDefinitionImpl.class.getSimpleName());
sb.append("[");
sb.append("whenCondition=" + whenCondition);
sb.append(", mustConstraints=" + mustConstraints);
import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
-public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
- implements TypeDefinitionAwareBuilder, AugmentationTargetBuilder,
- DataSchemaNodeBuilder {
+public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder implements
+ TypeDefinitionAwareBuilder, AugmentationTargetBuilder, DataSchemaNodeBuilder, GroupingMember, ConfigNode {
private boolean isBuilt;
private final ContainerSchemaNodeImpl instance;
private final int line;
- private final ConstraintsBuilder constraints;
+
+ // SchemaNode args
private SchemaPath schemaPath;
private String description;
private String reference;
private Status status = Status.CURRENT;
- private boolean presence;
+ private List<UnknownSchemaNode> unknownNodes;
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ // DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
+ private boolean addedByUses;
+ private Boolean configuration;
+ private final ConstraintsBuilder constraints;
+ // DataNodeContainer args
private Set<TypeDefinition<?>> typedefs;
private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
private Set<UsesNode> usesNodes;
private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
+ // AugmentationTarget args
private Set<AugmentationSchema> augmentations;
private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
- private List<UnknownSchemaNode> unknownNodes;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ // ContainerSchemaNode args
+ private boolean presence;
- public ContainerSchemaNodeBuilder(final QName qname, final int line) {
+ public ContainerSchemaNodeBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
super(qname);
+ this.schemaPath = schemaPath;
this.line = line;
instance = new ContainerSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public ContainerSchemaNodeBuilder(final ContainerSchemaNodeBuilder b) {
+ super(b.getQName());
+ line = b.getLine();
+ instance = new ContainerSchemaNodeImpl(b.getQName());
+ constraints = b.getConstraints();
+ schemaPath = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ presence = b.isPresence();
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ childNodes = b.getChildNodes();
+ addedChildNodes.addAll(b.getChildNodeBuilders());
+ groupings = b.getGroupings();
+ addedGroupings.addAll(b.getGroupingBuilders());
+ typedefs = b.typedefs;
+ addedTypedefs.addAll(b.getTypeDefinitionBuilders());
+ usesNodes = b.usesNodes;
+ addedUsesNodes.addAll(b.getUsesNodes());
+ augmentations = b.augmentations;
+ addedAugmentations.addAll(b.getAugmentations());
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+ }
+
@Override
public ContainerSchemaNode build() {
if (!isBuilt) {
instance.setStatus(status);
instance.setPresenceContainer(presence);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
+
+ // if this builder represents rpc input or output, it can has configuration value set to null
+ if(configuration == null) {
+ configuration = false;
+ }
instance.setConfiguration(configuration);
// CHILD NODES
final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
- if(childNodes == null) {
+ if (childNodes == null) {
for (DataSchemaNodeBuilder node : addedChildNodes) {
childs.put(node.getQName(), node.build());
}
} else {
- for(DataSchemaNode node : childNodes) {
+ for (DataSchemaNode node : childNodes) {
childs.put(node.getQName(), node);
}
}
instance.setChildNodes(childs);
// GROUPINGS
- if(groupings == null) {
+ if (groupings == null) {
groupings = new HashSet<GroupingDefinition>();
for (GroupingBuilder builder : addedGroupings) {
groupings.add(builder.build());
instance.setGroupings(groupings);
// TYPEDEFS
- if(typedefs == null) {
+ if (typedefs == null) {
typedefs = new HashSet<TypeDefinition<?>>();
for (TypeDefinitionBuilder entry : addedTypedefs) {
typedefs.add(entry.build());
instance.setTypeDefinitions(typedefs);
// USES
- if(usesNodes == null) {
+ if (usesNodes == null) {
usesNodes = new HashSet<UsesNode>();
for (UsesNodeBuilder builder : addedUsesNodes) {
usesNodes.add(builder.build());
instance.setUses(usesNodes);
// AUGMENTATIONS
- if(augmentations == null) {
+ if (augmentations == null) {
augmentations = new HashSet<AugmentationSchema>();
for (AugmentationSchemaBuilder builder : addedAugmentations) {
augmentations.add(builder.build());
instance.setAvailableAugmentations(augmentations);
// UNKNOWN NODES
- if(unknownNodes == null) {
+ if (unknownNodes == null) {
unknownNodes = new ArrayList<UnknownSchemaNode>();
for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
unknownNodes.add(b.build());
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return addedTypedefs;
}
}
@Override
- public boolean isConfiguration() {
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
+ @Override
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(boolean configuration) {
+ public void setConfiguration(Boolean configuration) {
this.configuration = configuration;
}
private String reference;
private Status status = Status.CURRENT;
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraints;
private Set<AugmentationSchema> augmentations = Collections.emptySet();
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
return augmentations;
}
- private void setAvailableAugmentations(
- Set<AugmentationSchema> augmentations) {
+ private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
if (augmentations != null) {
this.augmentations = augmentations;
}
return unknownNodes;
}
- private void setUnknownSchemaNodes(
- List<UnknownSchemaNode> unknownSchemaNodes) {
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
if (unknownSchemaNodes != null) {
this.unknownNodes = unknownSchemaNodes;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ContainerSchemaNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ContainerSchemaNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append("]");
*/
package org.opendaylight.controller.yang.parser.builder.impl;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
import org.opendaylight.controller.yang.model.api.Deviation;
import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil;
import org.opendaylight.controller.yang.parser.util.YangParseException;
public final class DeviationBuilder implements Builder {
private final DeviationImpl instance;
private final int line;
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
DeviationBuilder(final String targetPathStr, final int line) {
this.line = line;
@Override
public Deviation build() {
+ // UNKNOWN NODES
+ List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
+ instance.setUnknownSchemaNodes(unknownNodes);
+
return instance;
}
return line;
}
+ @Override
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+ addedUnknownNodes.add(unknownNode);
+ }
+
public void setDeviate(final String deviate) {
if ("not-supported".equals(deviate)) {
instance.setDeviate(Deviate.NOT_SUPPORTED);
private final SchemaPath targetPath;
private Deviate deviate;
private String reference;
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private DeviationImpl(final SchemaPath targetPath) {
this.targetPath = targetPath;
this.reference = reference;
}
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {
+ if (unknownSchemaNodes != null) {
+ this.unknownNodes = unknownSchemaNodes;
+ }
+ }
+
@Override
public int hashCode() {
final int prime = 31;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
-public final class ExtensionBuilder implements SchemaNodeBuilder {
+public final class ExtensionBuilder extends AbstractSchemaNodeBuilder {
private boolean isBuilt;
private final ExtensionDefinitionImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
- private String description;
- private String reference;
- private Status status = Status.CURRENT;
private final List<UnknownSchemaNodeBuilder> addedExtensions = new ArrayList<UnknownSchemaNodeBuilder>();
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
ExtensionBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ super(qname, line);
instance = new ExtensionDefinitionImpl(qname);
}
@Override
public ExtensionDefinition build() {
if(!isBuilt) {
- instance.setPath(schemaPath);
+ instance.setPath(path);
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
public void addExtension(UnknownSchemaNodeBuilder extension) {
addedExtensions.add(extension);
instance.setArgument(argument);
}
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public void setDescription(final String description) {
- this.description = description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public void setReference(final String reference) {
- this.reference = reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
- @Override
- public void setStatus(final Status status) {
- instance.setStatus(status);
- }
-
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
private final class ExtensionDefinitionImpl implements ExtensionDefinition {
private final QName qname;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
-public final class FeatureBuilder implements SchemaNodeBuilder {
+public final class FeatureBuilder extends AbstractSchemaNodeBuilder {
private boolean isBuilt;
private final FeatureDefinitionImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
- private String description;
- private String reference;
- private Status status = Status.CURRENT;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
FeatureBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ super(qname, line);
instance = new FeatureDefinitionImpl(qname);
}
@Override
public FeatureDefinitionImpl build() {
- if(!isBuilt) {
- instance.setPath(schemaPath);
+ if (!isBuilt) {
+ instance.setPath(path);
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public void setDescription(final String description) {
- this.description = description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public void setReference(final String reference) {
- this.reference = reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
- @Override
- public void setStatus(final Status status) {
- this.status = status;
- }
-
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
-
private final class FeatureDefinitionImpl implements FeatureDefinition {
private final QName qname;
private SchemaPath path;
return unknownNodes;
}
- private void setUnknownSchemaNodes(
- final List<UnknownSchemaNode> unknownNodes) {
+ private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
if (unknownNodes != null) {
this.unknownNodes = unknownNodes;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- FeatureDefinitionImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(FeatureDefinitionImpl.class.getSimpleName());
sb.append("[name=" + qname + "]");
return sb.toString();
}
private String description;
private String reference;
private Status status = Status.CURRENT;
+ private boolean addedByUses;
private Set<DataSchemaNode> childNodes;
private final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<DataSchemaNodeBuilder>();
public GroupingBuilderImpl(final QName qname, final int line) {
this.qname = qname;
- this.instance = new GroupingDefinitionImpl(qname);
+ instance = new GroupingDefinitionImpl(qname);
this.line = line;
}
+ public GroupingBuilderImpl(GroupingBuilder builder) {
+ qname = builder.getQName();
+ instance = new GroupingDefinitionImpl(qname);
+ line = builder.getLine();
+ schemaPath = builder.getPath();
+ description = builder.getDescription();
+ reference = builder.getReference();
+ status = builder.getStatus();
+ addedByUses = builder.isAddedByUses();
+ childNodes = builder.getChildNodes();
+ addedChildNodes.addAll(builder.getChildNodeBuilders());
+ groupings = builder.getGroupings();
+ addedGroupings.addAll(builder.getGroupingBuilders());
+ addedUsesNodes.addAll(builder.getUses());
+ addedUnknownNodes.addAll(builder.getUnknownNodes());
+ }
+
@Override
public GroupingDefinition build() {
if (!isBuilt) {
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
+ instance.setAddedByUses(addedByUses);
// CHILD NODES
final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
- if(childNodes == null) {
+ if (childNodes == null) {
for (DataSchemaNodeBuilder node : addedChildNodes) {
childs.put(node.getQName(), node.build());
}
} else {
- for(DataSchemaNode node : childNodes) {
+ for (DataSchemaNode node : childNodes) {
childs.put(node.getQName(), node);
}
}
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return addedTypedefs;
}
this.status = status;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public DataSchemaNodeBuilder getChildNode(String name) {
DataSchemaNodeBuilder result = null;
return result;
}
+ @Override
+ public Set<DataSchemaNode> getChildNodes() {
+ return childNodes;
+ }
+
@Override
public void addChildNode(final DataSchemaNodeBuilder childNode) {
addedChildNodes.add(childNode);
}
@Override
- public Set<DataSchemaNodeBuilder> getChildNodes() {
+ public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
return addedChildNodes;
}
}
@Override
- public Set<GroupingBuilder> getGroupings() {
+ public Set<GroupingDefinition> getGroupings() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<GroupingBuilder> getGroupingBuilders() {
return addedGroupings;
}
private String description;
private String reference;
private Status status;
+ private boolean addedByUses;
private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
private Set<GroupingDefinition> groupings = Collections.emptySet();
private Set<TypeDefinition<?>> typeDefinitions = Collections.emptySet();
this.status = status;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public Set<DataSchemaNode> getChildNodes() {
return new HashSet<DataSchemaNode>(childNodes.values());
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
-public final class IdentitySchemaNodeBuilder implements SchemaNodeBuilder {
+public final class IdentitySchemaNodeBuilder extends AbstractSchemaNodeBuilder {
private boolean isBuilt;
private final IdentitySchemaNodeImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
- private String description;
- private String reference;
- private Status status = Status.CURRENT;
private IdentitySchemaNodeBuilder baseIdentityBuilder;
private IdentitySchemaNode baseIdentity;
private String baseIdentityName;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
IdentitySchemaNodeBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ super(qname, line);
instance = new IdentitySchemaNodeImpl(qname);
}
@Override
public IdentitySchemaNode build() {
- if(!isBuilt) {
- instance.setPath(schemaPath);
+ if (!isBuilt) {
+ instance.setPath(path);
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public void setDescription(final String description) {
- this.description = description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public void setReference(final String reference) {
- this.reference = reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
- @Override
- public void setStatus(final Status status) {
- if (status != null) {
- this.status = status;
- }
- }
-
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
-
public String getBaseIdentityName() {
return baseIdentityName;
}
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
* When build is called, types in builder form will be built and add to resolved
* types.
*/
-public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder
- implements TypeDefinitionBuilder {
+public final class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
private static final String NAME = "identityref";
private final int line;
private final SchemaPath schemaPath;
private QName baseQName;
- IdentityrefTypeBuilder(final String baseString,
- final SchemaPath schemaPath, final int line) {
+ IdentityrefTypeBuilder(final String baseString, final SchemaPath schemaPath, final int line) {
this.line = line;
this.baseString = baseString;
this.schemaPath = schemaPath;
throw new YangParseException(line, "Can not set status to " + NAME);
}
+ @Override
+ public boolean isAddedByUses() {
+ return false;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ throw new YangParseException(line, "Identityref type can not be added by uses.");
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownNodes() {
+ return Collections.emptyList();
+ }
+
@Override
public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- throw new YangParseException(line, "Can not add unknown node to "
- + NAME);
+ throw new YangParseException(line, "Can not add unknown node to " + NAME);
}
@Override
@Override
public void setFractionDigits(Integer fractionDigits) {
- throw new YangParseException(line, "Can not set fraction digits to "
- + NAME);
+ throw new YangParseException(line, "Can not set fraction digits to " + NAME);
}
@Override
- public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ public List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders() {
return Collections.emptyList();
}
@Override
public void setDefaultValue(Object defaultValue) {
- throw new YangParseException(line, "Can not set default value to "
- + NAME);
+ throw new YangParseException(line, "Can not set default value to " + NAME);
}
@Override
@Override
public String toString() {
- final StringBuilder result = new StringBuilder(
- IdentityrefTypeBuilder.class.getSimpleName() + "[");
+ final StringBuilder result = new StringBuilder(IdentityrefTypeBuilder.class.getSimpleName() + "[");
result.append(", base=" + baseQName);
result.append("]");
return result.toString();
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
-public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder {
+public final class LeafListSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
+ GroupingMember, ConfigNode {
private boolean isBuilt;
private final LeafListSchemaNodeImpl instance;
private final int line;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
// DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
+ private boolean addedByUses;
+ private Boolean configuration;
private final ConstraintsBuilder constraints;
// LeafListSchemaNode args
private boolean userOrdered;
- public LeafListSchemaNodeBuilder(final QName qname, final int line) {
+ public LeafListSchemaNodeBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
this.qname = qname;
+ this.schemaPath = schemaPath;
this.line = line;
instance = new LeafListSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public LeafListSchemaNodeBuilder(final LeafListSchemaNodeBuilder b) {
+ qname = b.getQName();
+ line = b.getLine();
+ instance = new LeafListSchemaNodeImpl(qname);
+
+ type = b.getType();
+ typedef = b.getTypedef();
+
+ constraints = b.getConstraints();
+ schemaPath = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ userOrdered = b.isUserOrdered();
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+ }
+
@Override
public LeafListSchemaNode build() {
if (!isBuilt) {
instance.setReference(reference);
instance.setStatus(status);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
instance.setConfiguration(configuration);
instance.setUserOrdered(userOrdered);
this.augmenting = augmenting;
}
- public boolean isConfiguration() {
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(boolean configuration) {
+ public void setConfiguration(Boolean configuration) {
this.configuration = configuration;
}
private String reference;
private Status status = Status.CURRENT;
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraintsDef;
private TypeDefinition<?> type;
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
-public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder {
+public final class LeafSchemaNodeBuilder extends AbstractTypeAwareBuilder implements DataSchemaNodeBuilder,
+ GroupingMember, ConfigNode {
private boolean isBuilt;
private final LeafSchemaNodeImpl instance;
private final int line;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
// DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
+ private boolean addedByUses;
+ private Boolean configuration;
private final ConstraintsBuilder constraints;
// leaf args
private String defaultStr;
private String unitsStr;
- public LeafSchemaNodeBuilder(final QName qname, final int line) {
+ public LeafSchemaNodeBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
this.qname = qname;
+ this.path = schemaPath;
this.line = line;
instance = new LeafSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public LeafSchemaNodeBuilder(final LeafSchemaNodeBuilder b) {
+ qname = b.getQName();
+ line = b.getLine();
+ instance = new LeafSchemaNodeImpl(qname);
+ constraints = b.getConstraints();
+ path = b.getPath();
+
+ type = b.getType();
+ typedef = b.getTypedef();
+
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+
+ defaultStr = b.getDefaultStr();
+ unitsStr = b.getUnits();
+ }
+
@Override
public LeafSchemaNode build() {
if (!isBuilt) {
instance.setReference(reference);
instance.setStatus(status);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
instance.setConfiguration(configuration);
instance.setDefault(defaultStr);
instance.setUnits(unitsStr);
this.augmenting = augmenting;
}
- public boolean isConfiguration() {
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(final boolean configuration) {
- instance.setConfiguration(configuration);
+ public void setConfiguration(final Boolean configuration) {
+ this.configuration = configuration;
}
public String getDefaultStr() {
private String reference;
private Status status = Status.CURRENT;
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraintsDef;
private TypeDefinition<?> type;
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
-public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
- implements DataSchemaNodeBuilder, AugmentationTargetBuilder,
- TypeDefinitionAwareBuilder {
+public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder implements DataSchemaNodeBuilder,
+ AugmentationTargetBuilder, TypeDefinitionAwareBuilder, GroupingMember, ConfigNode {
private boolean isBuilt;
private final ListSchemaNodeImpl instance;
private final int line;
private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
// DataSchemaNode args
private boolean augmenting;
- private boolean configuration;
+ private boolean addedByUses;
+ private Boolean configuration;
private final ConstraintsBuilder constraints;
// DataNodeContainer args
private Set<TypeDefinition<?>> typedefs;
private List<QName> keyDefinition = Collections.emptyList();
private boolean userOrdered;
- public ListSchemaNodeBuilder(final QName qname, final int line) {
+ public ListSchemaNodeBuilder(final QName qname, final SchemaPath schemaPath, final int line) {
super(qname);
+ this.schemaPath = schemaPath;
this.line = line;
instance = new ListSchemaNodeImpl(qname);
constraints = new ConstraintsBuilder(line);
}
+ public ListSchemaNodeBuilder(final ListSchemaNodeBuilder b) {
+ super(b.getQName());
+ line = b.getLine();
+ instance = new ListSchemaNodeImpl(b.getQName());
+ constraints = b.getConstraints();
+ schemaPath = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ augmenting = b.isAugmenting();
+ addedByUses = b.isAddedByUses();
+ configuration = b.isConfiguration();
+ keyDefinition = b.getKeyDefinition();
+ userOrdered = b.isUserOrdered();
+ childNodes = b.getChildNodes();
+ addedChildNodes.addAll(b.getChildNodeBuilders());
+ groupings = b.getGroupings();
+ addedGroupings.addAll(b.getGroupingBuilders());
+ typedefs = b.typedefs;
+ addedTypedefs.addAll(b.getTypeDefinitionBuilders());
+ usesNodes = b.usesNodes;
+ addedUsesNodes.addAll(b.getUsesNodes());
+ augmentations = b.augmentations;
+ addedAugmentations.addAll(b.getAugmentations());
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.getUnknownNodes());
+ }
+
@Override
public ListSchemaNode build() {
if (!isBuilt) {
instance.setReference(reference);
instance.setStatus(status);
instance.setAugmenting(augmenting);
+ instance.setAddedByUses(addedByUses);
instance.setConfiguration(configuration);
instance.setUserOrdered(userOrdered);
// CHILD NODES
final Map<QName, DataSchemaNode> childs = new HashMap<QName, DataSchemaNode>();
- if(childNodes == null) {
+ if (childNodes == null) {
for (DataSchemaNodeBuilder node : addedChildNodes) {
childs.put(node.getQName(), node.build());
}
} else {
- for(DataSchemaNode node : childNodes) {
+ for (DataSchemaNode node : childNodes) {
childs.put(node.getQName(), node);
}
}
instance.setChildNodes(childs);
// TYPEDEFS
- if(typedefs == null) {
+ if (typedefs == null) {
typedefs = new HashSet<TypeDefinition<?>>();
for (TypeDefinitionBuilder entry : addedTypedefs) {
typedefs.add(entry.build());
instance.setTypeDefinitions(typedefs);
// USES
- if(usesNodes == null) {
+ if (usesNodes == null) {
usesNodes = new HashSet<UsesNode>();
for (UsesNodeBuilder builder : addedUsesNodes) {
usesNodes.add(builder.build());
instance.setUses(usesNodes);
// GROUPINGS
- if(groupings == null) {
+ if (groupings == null) {
groupings = new HashSet<GroupingDefinition>();
for (GroupingBuilder builder : addedGroupings) {
groupings.add(builder.build());
instance.setGroupings(groupings);
// AUGMENTATIONS
- if(augmentations == null) {
+ if (augmentations == null) {
augmentations = new HashSet<AugmentationSchema>();
for (AugmentationSchemaBuilder builder : addedAugmentations) {
augmentations.add(builder.build());
instance.setAvailableAugmentations(augmentations);
// UNKNOWN NODES
- if(unknownNodes == null) {
+ if (unknownNodes == null) {
unknownNodes = new ArrayList<UnknownSchemaNode>();
for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
unknownNodes.add(b.build());
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return addedTypedefs;
}
this.augmenting = augmenting;
}
- public boolean isConfiguration() {
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
+ public Boolean isConfiguration() {
return configuration;
}
@Override
- public void setConfiguration(boolean configuration) {
+ public void setConfiguration(Boolean configuration) {
this.configuration = configuration;
}
this.unknownNodes = unknownNodes;
}
-
public final class ListSchemaNodeImpl implements ListSchemaNode {
private final QName qname;
private SchemaPath path;
private Status status = Status.CURRENT;
private List<QName> keyDefinition = Collections.emptyList();
private boolean augmenting;
+ private boolean addedByUses;
private boolean configuration;
private ConstraintDefinition constraints;
private Set<AugmentationSchema> augmentations = Collections.emptySet();
this.augmenting = augmenting;
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public boolean isConfiguration() {
return configuration;
return augmentations;
}
- private void setAvailableAugmentations(
- Set<AugmentationSchema> augmentations) {
+ private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
if (augmentations != null) {
this.augmentations = augmentations;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- ListSchemaNodeImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(ListSchemaNodeImpl.class.getSimpleName());
sb.append("[");
sb.append("qname=" + qname);
sb.append(", path=" + path);
* module/modules, these dependencies must be resolved before module is built,
* otherwise result may not be valid.
*/
-public class ModuleBuilder implements Builder {
+public class ModuleBuilder implements DataNodeContainerBuilder {
private final ModuleImpl instance;
private final String name;
private URI namespace;
private final Map<List<String>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
private final Map<List<String>, UnionTypeBuilder> addedUnionTypes = new HashMap<List<String>, UnionTypeBuilder>();
private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
- private final Map<List<String>, UnknownSchemaNodeBuilder> addedUnknownNodes = new HashMap<List<String>, UnknownSchemaNodeBuilder>();
+ private final Map<List<String>, List<UnknownSchemaNodeBuilder>> addedUnknownNodes = new HashMap<List<String>, List<UnknownSchemaNodeBuilder>>();
private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
return 0;
}
+ @Override
+ public QName getQName() {
+ return new QName(namespace, revision, prefix, name);
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return null;
+ }
+
+ @Override
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
+ final Set<TypeDefinitionBuilder> typeDefinitions = new HashSet<TypeDefinitionBuilder>();
+ for (final Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) {
+ final List<String> key = entry.getKey();
+ final TypeDefinitionBuilder typedefBuilder = entry.getValue();
+ if (key.size() == 2) {
+ typeDefinitions.add(typedefBuilder);
+
+ }
+ }
+ return typeDefinitions;
+ }
+
public void enterNode(final Builder node) {
actualPath.push(node);
}
}
}
+ public Builder getActualParent() {
+ if (actualPath.size() < 2) {
+ return null;
+ } else {
+ return actualPath.get(1);
+ }
+ }
+
public Builder getModuleNode(final List<String> path) {
return childNodes.get(path);
}
return addedGroupings.get(path);
}
+ @Override
+ public Set<GroupingDefinition> getGroupings() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<GroupingBuilder> getGroupingBuilders() {
+ final Set<GroupingBuilder> result = new HashSet<GroupingBuilder>();
+ for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings.entrySet()) {
+ if (entry.getKey().size() == 2) {
+ result.add(entry.getValue());
+ }
+ }
+ return result;
+ }
+
public Builder getModuleTypedef(final List<String> path) {
return addedTypedefs.get(path);
}
- public Set<DataSchemaNodeBuilder> getChildNodes() {
+ @Override
+ public Set<DataSchemaNode> getChildNodes() {
+ return Collections.emptySet();
+ }
+
+ public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
final Set<DataSchemaNodeBuilder> children = new HashSet<DataSchemaNodeBuilder>();
for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : childNodes.entrySet()) {
final List<String> path = entry.getKey();
return addedUsesNodes;
}
- public Set<UnknownSchemaNodeBuilder> getUnknownNodes() {
- return new HashSet<UnknownSchemaNodeBuilder>(addedUnknownNodes.values());
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ List<UnknownSchemaNodeBuilder> result = new ArrayList<UnknownSchemaNodeBuilder>();
+ for (List<UnknownSchemaNodeBuilder> entry : addedUnknownNodes.values()) {
+ result.addAll(entry);
+ }
+ return result;
}
public Set<TypeDefinitionBuilder> getModuleTypedefs() {
return builder;
}
- public ContainerSchemaNodeBuilder addContainerNode(final QName containerName, final List<String> parentPath,
- final int line) {
+ @Override
+ public void addChildNode(DataSchemaNodeBuilder child) {
+ final List<String> pathToChild = new ArrayList<String>();
+ for (QName qname : child.getPath().getPath()) {
+ pathToChild.add(qname.getLocalName());
+ }
+ if (childNodes.containsKey(pathToChild)) {
+ throw new YangParseException(this.name, child.getLine(), "Failed to add child node "
+ + child.getQName().getLocalName() + ": node already exists in context.");
+ }
+ childNodes.put(pathToChild, child);
+ }
+
+ public ContainerSchemaNodeBuilder addContainerNode(final SchemaPath schemaPath, final QName containerName,
+ final List<String> parentPath, final int line) {
final List<String> pathToNode = new ArrayList<String>(parentPath);
- final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(containerName, line);
+ final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(containerName, schemaPath, line);
updateParent(containerBuilder, line, "container");
pathToNode.add(containerName.getLocalName());
return containerBuilder;
}
- public ListSchemaNodeBuilder addListNode(final QName listName, final List<String> parentPath, final int line) {
+ public ListSchemaNodeBuilder addListNode(final SchemaPath schemaPath, final QName listName, final List<String> parentPath, final int line) {
final List<String> pathToNode = new ArrayList<String>(parentPath);
- final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName, line);
+ final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(listName, schemaPath, line);
updateParent(listBuilder, line, "list");
pathToNode.add(listName.getLocalName());
return listBuilder;
}
- public LeafSchemaNodeBuilder addLeafNode(final QName leafName, final List<String> parentPath, final int line) {
+ public LeafSchemaNodeBuilder addLeafNode(final SchemaPath schemaPath, final QName leafName, final List<String> parentPath, final int line) {
final List<String> pathToNode = new ArrayList<String>(parentPath);
- final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName, line);
+ final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(leafName, schemaPath, line);
updateParent(leafBuilder, line, "leaf");
pathToNode.add(leafName.getLocalName());
return leafBuilder;
}
- public LeafListSchemaNodeBuilder addLeafListNode(final QName qname, final List<String> parentPath, final int line) {
+ public LeafListSchemaNodeBuilder addLeafListNode(final SchemaPath schemaPath, final QName qname, final List<String> parentPath, final int line) {
final List<String> pathToNode = new ArrayList<String>(parentPath);
- final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(qname, line);
+ final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(qname, schemaPath, line);
updateParent(leafListBuilder, line, "leaf-list");
pathToNode.add(qname.getLocalName());
return leafListBuilder;
}
+ @Override
+ public void addGrouping(GroupingBuilder groupingBuilder) {
+ final List<String> pathToGroup = new ArrayList<String>();
+ for (QName qname : groupingBuilder.getPath().getPath()) {
+ pathToGroup.add(qname.getLocalName());
+ }
+ if (addedGroupings.containsKey(pathToGroup)) {
+ throw new YangParseException(this.name, groupingBuilder.getLine(), "Failed to add grouping "
+ + groupingBuilder.getQName().getLocalName() + ": grouping already exists in context.");
+ }
+ addedGroupings.put(pathToGroup, groupingBuilder);
+ }
+
public GroupingBuilder addGrouping(final QName qname, final List<String> parentPath, final int line) {
final List<String> pathToGroup = new ArrayList<String>(parentPath);
final GroupingBuilder builder = new GroupingBuilderImpl(qname, line);
public AugmentationSchemaBuilder addAugment(final String name, final List<String> parentPath, final int line) {
final List<String> pathToAugment = new ArrayList<String>(parentPath);
- final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line);
+ Builder parent = null;
+ if (!(actualPath.isEmpty())) {
+ parent = actualPath.getFirst();
+ }
+ final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, parent);
// augment can only be in 'module' or 'uses' statement
- if (!(actualPath.isEmpty())) {
- final Builder parent = actualPath.getFirst();
+ if (parent != null) {
if (parent instanceof UsesNodeBuilder) {
((UsesNodeBuilder) parent).addAugment(builder);
} else {
return builder;
}
+ @Override
+ public void addUsesNode(UsesNodeBuilder usesBuilder) {
+ final List<String> pathToTypedef = new ArrayList<String>();
+ for (QName qname : usesBuilder.getParent().getPath().getPath()) {
+ pathToTypedef.add(qname.getLocalName());
+ }
+ if (addedUsesNodes.containsKey(pathToTypedef)) {
+ throw new YangParseException(this.name, usesBuilder.getLine(), "Failed to add uses node "
+ + usesBuilder.getGroupingName() + ": uses already exists in context.");
+ }
+ addedUsesNodes.put(pathToTypedef, usesBuilder);
+ }
+
public UsesNodeBuilder addUsesNode(final String groupingPathStr, final List<String> parentPath, final int line) {
final List<String> pathToUses = new ArrayList<String>(parentPath);
- final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr, line);
-
- if (!(actualPath.isEmpty())) {
- final Builder parent = actualPath.getFirst();
- if (parent instanceof DataNodeContainerBuilder) {
- if (parent instanceof AugmentationSchemaBuilder) {
- usesBuilder.setAugmenting(true);
- }
- ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
- } else {
- throw new YangParseException(name, line, "Unresolved parent of uses " + groupingPathStr);
+ Builder parent = null;
+ if (!actualPath.isEmpty()) {
+ parent = actualPath.getFirst();
+ }
+ if (parent != null && !(parent instanceof DataNodeContainerBuilder)) {
+ throw new YangParseException(name, line, "Unresolved parent of uses " + groupingPathStr);
+ }
+ final UsesNodeBuilder usesBuilder;
+ if (parent == null) {
+ usesBuilder = new UsesNodeBuilderImpl(groupingPathStr, line, this);
+ } else {
+ usesBuilder = new UsesNodeBuilderImpl(groupingPathStr, line, (DataNodeContainerBuilder) parent);
+ if (parent instanceof AugmentationSchemaBuilder) {
+ usesBuilder.setAugmenting(true);
}
+ ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
}
pathToUses.add(groupingPathStr);
return rpcBuilder;
}
- public ContainerSchemaNodeBuilder addRpcInput(final QName inputQName, final int line) {
+ public ContainerSchemaNodeBuilder addRpcInput(final SchemaPath schemaPath, final QName inputQName, final int line) {
final Builder parent = actualPath.getFirst();
if (!(parent instanceof RpcDefinitionBuilder)) {
throw new YangParseException(name, line, "input can be defined only in rpc statement");
}
final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
- final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName, line);
+ final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(inputQName, schemaPath, line);
rpc.setInput(inputBuilder);
return inputBuilder;
}
- public ContainerSchemaNodeBuilder addRpcOutput(final QName outputQName, final int line) {
+ public ContainerSchemaNodeBuilder addRpcOutput(final SchemaPath schemaPath, final QName outputQName, final int line) {
final Builder parent = actualPath.getFirst();
if (!(parent instanceof RpcDefinitionBuilder)) {
throw new YangParseException(name, line, "output can be defined only in rpc statement");
}
final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
- final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName, line);
+ final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(outputQName, schemaPath, line);
rpc.setOutput(outputBuilder);
return outputBuilder;
}
}
public ChoiceCaseBuilder addCase(final QName caseName, final List<String> parentPath, final int line) {
+ Builder parent = getActualNode();
+
final List<String> pathToCase = new ArrayList<String>(parentPath);
- final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line);
+ ChoiceCaseBuilder builder = null;
+ if (parent instanceof ChoiceBuilder) {
+ builder = new ChoiceCaseBuilder((ChoiceBuilder) parent, caseName, line);
+ } else {
+ builder = new ChoiceCaseBuilder(null, caseName, line);
+ }
if (actualPath.isEmpty()) {
throw new YangParseException(name, line, "'case' parent not found");
} else {
- final Builder parent = actualPath.getFirst();
if (parent instanceof ChoiceBuilder) {
((ChoiceBuilder) parent).addChildNode(builder);
} else if (parent instanceof AugmentationSchemaBuilder) {
return builder;
}
- public AnyXmlBuilder addAnyXml(final QName anyXmlName, final List<String> parentPath, final int line) {
+ public AnyXmlBuilder addAnyXml(final SchemaPath schemaPath, final QName anyXmlName, final List<String> parentPath, final int line) {
final List<String> pathToAnyXml = new ArrayList<String>(parentPath);
- final AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
+ final AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, schemaPath, line);
updateParent(builder, line, "anyxml");
pathToAnyXml.add(anyXmlName.getLocalName());
return builder;
}
+ @Override
+ public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
+ final List<String> pathToTypedef = new ArrayList<String>();
+ for (QName qname : typedefBuilder.getPath().getPath()) {
+ pathToTypedef.add(qname.getLocalName());
+ }
+ if (addedTypedefs.containsKey(pathToTypedef)) {
+ throw new YangParseException(this.name, typedefBuilder.getLine(), "Failed to add typedef "
+ + typedefBuilder.getQName().getLocalName() + ": typedef already exists in context.");
+ }
+ addedTypedefs.put(pathToTypedef, typedefBuilder);
+ }
+
public TypeDefinitionBuilderImpl addTypedef(final QName typeDefName, final List<String> parentPath, final int line) {
final List<String> pathToType = new ArrayList<String>(parentPath);
final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(typeDefName, line);
return builder;
}
- public void addConfiguration(final boolean configuration, final List<String> parentPath, final int line) {
- if (actualPath.isEmpty()) {
- throw new YangParseException(name, line, "Parent node of config statement not found.");
+ @Override
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+ final List<String> unPath = new ArrayList<String>();
+ for (QName qname : unknownNode.getPath().getPath()) {
+ unPath.add(qname.getLocalName());
+ }
+
+ if (addedUnknownNodes.containsKey(unPath)) {
+ addedUnknownNodes.get(unPath).add(unknownNode);
} else {
- final Builder parent = actualPath.getFirst();
- if (parent instanceof DataSchemaNodeBuilder) {
- ((DataSchemaNodeBuilder) parent).setConfiguration(configuration);
- } else if (parent instanceof RefineHolder) {
- ((RefineHolder) parent).setConfig(configuration);
- } else if (parent instanceof DeviationBuilder) {
- // skip: set config to deviation (deviate stmt) not supported by
- // current api
- return;
- } else {
- throw new YangParseException(name, line, "Unresolved parent of config statement.");
- }
+ List<UnknownSchemaNodeBuilder> nodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ nodes.add(unknownNode);
+ addedUnknownNodes.put(unPath, nodes);
}
}
}
final List<String> unPath = new ArrayList<String>(parentPath);
unPath.add(qname.getLocalName());
- addedUnknownNodes.put(unPath, builder);
+
+ if (addedUnknownNodes.containsKey(unPath)) {
+ addedUnknownNodes.get(unPath).add(builder);
+ } else {
+ List<UnknownSchemaNodeBuilder> nodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ nodes.add(builder);
+ addedUnknownNodes.put(unPath, nodes);
+ }
return builder;
}
}
private List<UnknownSchemaNode> buildModuleUnknownNodes(
- final Map<List<String>, UnknownSchemaNodeBuilder> addedUnknownNodes) {
+ final Map<List<String>, List<UnknownSchemaNodeBuilder>> addedUnknownNodes) {
final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (Map.Entry<List<String>, UnknownSchemaNodeBuilder> entry : addedUnknownNodes.entrySet()) {
+ for (Map.Entry<List<String>, List<UnknownSchemaNodeBuilder>> entry : addedUnknownNodes.entrySet()) {
final List<String> path = entry.getKey();
- final UnknownSchemaNodeBuilder child = entry.getValue();
- if (path.size() == 2) {
- final UnknownSchemaNode node = child.build();
- unknownNodes.add(node);
+ final List<UnknownSchemaNodeBuilder> child = entry.getValue();
+ for (UnknownSchemaNodeBuilder un : child) {
+ if (path.size() == 2) {
+ final UnknownSchemaNode node = un.build();
+ unknownNodes.add(node);
+ }
}
}
return unknownNodes;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
-public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
- implements TypeDefinitionAwareBuilder, SchemaNodeBuilder, AugmentationTargetBuilder {
+public final class NotificationBuilder extends AbstractDataNodeContainerBuilder implements TypeDefinitionAwareBuilder,
+ SchemaNodeBuilder, AugmentationTargetBuilder {
private boolean isBuilt;
private final NotificationDefinitionImpl instance;
private final int line;
instance.setUses(uses);
// AUGMENTATIONS
- if(augmentations == null) {
+ if (augmentations == null) {
augmentations = new HashSet<AugmentationSchema>();
for (AugmentationSchemaBuilder builder : addedAugmentations) {
augmentations.add(builder.build());
}
@Override
- public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitionBuilders() {
return addedTypedefs;
}
@Override
public void setStatus(final Status status) {
- if(status != null) {
+ if (status != null) {
this.status = status;
}
}
return typeDefinitions;
}
- private void setTypeDefinitions(
- final Set<TypeDefinition<?>> typeDefinitions) {
+ private void setTypeDefinitions(final Set<TypeDefinition<?>> typeDefinitions) {
if (typeDefinitions != null) {
this.typeDefinitions = typeDefinitions;
}
return augmentations;
}
- private void setAvailableAugmentations(
- Set<AugmentationSchema> augmentations) {
+ private void setAvailableAugmentations(Set<AugmentationSchema> augmentations) {
if (augmentations != null) {
this.augmentations = augmentations;
}
return unknownNodes;
}
- private void setUnknownSchemaNodes(
- final List<UnknownSchemaNode> unknownNodes) {
+ private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
if (unknownNodes != null) {
this.unknownNodes = unknownNodes;
}
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- NotificationDefinitionImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(NotificationDefinitionImpl.class.getSimpleName());
sb.append("[qname=" + qname + ", path=" + path + "]");
return sb.toString();
}
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
-public final class RpcDefinitionBuilder implements SchemaNodeBuilder, TypeDefinitionAwareBuilder {
+public final class RpcDefinitionBuilder extends AbstractSchemaNodeBuilder implements TypeDefinitionAwareBuilder {
private boolean isBuilt;
private final RpcDefinitionImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
- private String description;
- private String reference;
- private Status status = Status.CURRENT;
private ContainerSchemaNodeBuilder inputBuilder;
private ContainerSchemaNodeBuilder outputBuilder;
private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
private final Set<GroupingBuilder> addedGroupings = new HashSet<GroupingBuilder>();
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
RpcDefinitionBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ super(qname, line);
this.instance = new RpcDefinitionImpl(qname);
}
instance.setInput(input);
instance.setOutput(output);
- instance.setPath(schemaPath);
+ instance.setPath(path);
// TYPEDEFS
final Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
void setInput(final ContainerSchemaNodeBuilder inputBuilder) {
this.inputBuilder = inputBuilder;
}
addedGroupings.add(grouping);
}
- @Override
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public void setDescription(final String description) {
- this.description = description;
- }
-
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public void setReference(String reference) {
- this.reference = reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
- @Override
- public void setStatus(final Status status) {
- if (status != null) {
- this.status = status;
- }
- }
-
- @Override
- public QName getQName() {
- return null;
- }
-
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
- }
-
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((qname == null) ? 0 : qname.hashCode());
- result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
return result;
}
} else if (!other.qname.equals(this.qname)) {
return false;
}
- if (other.schemaPath == null) {
- if (this.schemaPath != null) {
+ if (other.path == null) {
+ if (this.path != null) {
return false;
}
- } else if (!other.schemaPath.equals(this.schemaPath)) {
+ } else if (!other.path.equals(this.path)) {
return false;
}
return true;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.util.YangParseException;
-public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
- implements TypeDefinitionBuilder {
+public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
private final int line;
private final QName qname;
private SchemaPath schemaPath;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
private List<UnknownSchemaNode> unknownNodes;
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
private List<RangeConstraint> ranges = Collections.emptyList();
private List<LengthConstraint> lengths = Collections.emptyList();
private List<PatternConstraint> patterns = Collections.emptyList();
private Status status = Status.CURRENT;
private String units;
private Object defaultValue;
+ private boolean addedByUses;
public TypeDefinitionBuilderImpl(final QName qname, final int line) {
this.qname = qname;
this.line = line;
}
+ public TypeDefinitionBuilderImpl(TypeDefinitionBuilder tdb) {
+ qname = tdb.getQName();
+ line = tdb.getLine();
+ schemaPath = tdb.getPath();
+
+ type = tdb.getType();
+ typedef = tdb.getTypedef();
+
+ unknownNodes = tdb.getUnknownNodes();
+ for (UnknownSchemaNodeBuilder usnb : tdb.getUnknownNodeBuilders()) {
+ addedUnknownNodes.add(usnb);
+ }
+ ranges = tdb.getRanges();
+ lengths = tdb.getLengths();
+ patterns = tdb.getPatterns();
+ fractionDigits = tdb.getFractionDigits();
+
+ description = tdb.getDescription();
+ reference = tdb.getReference();
+ status = tdb.getStatus();
+ units = tdb.getUnits();
+ defaultValue = tdb.getDefaultValue();
+ addedByUses = tdb.isAddedByUses();
+ }
+
@Override
public TypeDefinition<? extends TypeDefinition<?>> build() {
TypeDefinition<?> result = null;
ExtendedType.Builder typeBuilder = null;
if ((type == null || type instanceof UnknownType) && typedef == null) {
- throw new YangParseException("Unresolved type: '"
- + qname.getLocalName() + "'.");
+ throw new YangParseException("Unresolved type: '" + qname.getLocalName() + "'.");
}
if (type == null || type instanceof UnknownType) {
type = typedef.build();
}
- typeBuilder = new ExtendedType.Builder(qname, type, description,
- reference, schemaPath);
+ typeBuilder = new ExtendedType.Builder(qname, type, description, reference, schemaPath);
typeBuilder.status(status);
typeBuilder.units(units);
typeBuilder.defaultValue(defaultValue);
+ typeBuilder.addedByUses(addedByUses);
typeBuilder.ranges(ranges);
typeBuilder.lengths(lengths);
}
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public String getUnits() {
return units;
}
@Override
- public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ public List<UnknownSchemaNode> getUnknownNodes() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders() {
return addedUnknownNodes;
}
@Override
public String toString() {
- final StringBuilder result = new StringBuilder("TypedefBuilder["
- + qname.getLocalName());
+ final StringBuilder result = new StringBuilder("TypedefBuilder[" + qname.getLocalName());
result.append(", type=");
if (type == null) {
result.append(typedef);
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
* When build is called, types in builder form will be built and add to resolved
* types.
*/
-public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
- TypeDefinitionBuilder {
+public final class UnionTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder {
private final static String NAME = "union";
private final int line;
throw new YangParseException(line, "Can not set status to " + NAME);
}
+ @Override
+ public boolean isAddedByUses() {
+ return false;
+ }
+
+ @Override
+ public void setAddedByUses(final boolean addedByUses) {
+ throw new YangParseException(line, "Union type can not be added by uses.");
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownNodes() {
+ return Collections.emptyList();
+ }
+
@Override
public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- throw new YangParseException(line, "Can not add unknown node to "
- + NAME);
+ // not supported
}
@Override
@Override
public void setFractionDigits(Integer fractionDigits) {
- throw new YangParseException(line, "Can not set fraction digits to "
- + NAME);
+ throw new YangParseException(line, "Can not set fraction digits to " + NAME);
}
@Override
- public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ public List<UnknownSchemaNodeBuilder> getUnknownNodeBuilders() {
return Collections.emptyList();
}
@Override
public void setDefaultValue(Object defaultValue) {
- throw new YangParseException(line, "Can not set default value to "
- + NAME);
+ throw new YangParseException(line, "Can not set default value to " + NAME);
}
@Override
@Override
public String toString() {
- final StringBuilder result = new StringBuilder(
- UnionTypeBuilder.class.getSimpleName() + "[");
+ final StringBuilder result = new StringBuilder(UnionTypeBuilder.class.getSimpleName() + "[");
result.append(", types=" + types);
result.append(", typedefs=" + typedefs);
result.append("]");
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
-public final class UnknownSchemaNodeBuilder implements SchemaNodeBuilder {
+public final class UnknownSchemaNodeBuilder extends AbstractSchemaNodeBuilder {
private boolean isBuilt;
private final UnknownSchemaNodeImpl instance;
- private final int line;
- private final QName qname;
- private SchemaPath schemaPath;
- private String description;
- private String reference;
- private Status status = Status.CURRENT;
- private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
+ private boolean addedByUses;
+ private List<UnknownSchemaNode> unknownNodes;
private QName nodeType;
private String nodeParameter;
- UnknownSchemaNodeBuilder(final QName qname, final int line) {
- this.qname = qname;
- this.line = line;
+ public UnknownSchemaNodeBuilder(final QName qname, final int line) {
+ super(qname, line);
instance = new UnknownSchemaNodeImpl(qname);
}
+ public UnknownSchemaNodeBuilder(UnknownSchemaNodeBuilder b) {
+ super(b.getQName(), b.getLine());
+ instance = new UnknownSchemaNodeImpl(qname);
+ path = b.getPath();
+ description = b.getDescription();
+ reference = b.getReference();
+ status = b.getStatus();
+ addedByUses = b.isAddedByUses();
+ unknownNodes = b.unknownNodes;
+ addedUnknownNodes.addAll(b.addedUnknownNodes);
+ nodeType = b.getNodeType();
+ nodeParameter = b.getNodeParameter();
+ }
+
@Override
public UnknownSchemaNode build() {
if (!isBuilt) {
- instance.setPath(schemaPath);
+ instance.setPath(path);
instance.setNodeType(nodeType);
instance.setNodeParameter(nodeParameter);
instance.setDescription(description);
instance.setReference(reference);
instance.setStatus(status);
+ instance.setAddedByUses(addedByUses);
// UNKNOWN NODES
- final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
- for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
- unknownNodes.add(b.build());
+ if (unknownNodes == null) {
+ unknownNodes = new ArrayList<UnknownSchemaNode>();
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+ unknownNodes.add(b.build());
+ }
}
instance.setUnknownSchemaNodes(unknownNodes);
return instance;
}
- @Override
- public int getLine() {
- return line;
- }
-
- @Override
- public QName getQName() {
- return qname;
- }
-
- @Override
- public SchemaPath getPath() {
- return schemaPath;
- }
-
- @Override
- public void setPath(SchemaPath schemaPath) {
- this.schemaPath = schemaPath;
- }
-
- @Override
- public String getDescription() {
- return description;
+ public boolean isAddedByUses() {
+ return addedByUses;
}
- @Override
- public void setDescription(final String description) {
- this.description = description;
+ public void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
}
- @Override
- public String getReference() {
- return reference;
- }
-
- @Override
- public void setReference(String reference) {
- this.reference = reference;
- }
-
- @Override
- public Status getStatus() {
- return status;
- }
-
- @Override
- public void setStatus(Status status) {
- if (status != null) {
- this.status = status;
- }
- }
-
- @Override
- public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- addedUnknownNodes.add(unknownNode);
+ public void setUnknownNodes(final List<UnknownSchemaNode> unknownNodes) {
+ this.unknownNodes = unknownNodes;
}
public QName getNodeType() {
private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private QName nodeType;
private String nodeParameter;
+ private boolean addedByUses;
private UnknownSchemaNodeImpl(final QName qname) {
this.qname = qname;
}
}
+ @Override
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
+ private void setAddedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ }
+
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return unknownNodes;
private void setNodeParameter(final String nodeParameter) {
this.nodeParameter = nodeParameter;
}
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(UnknownSchemaNodeImpl.class.getSimpleName());
+ sb.append("[");
+ sb.append(qname);
+ sb.append("]");
+ return sb.toString();
+ }
}
}
import org.opendaylight.controller.yang.model.api.AugmentationSchema;\r
import org.opendaylight.controller.yang.model.api.SchemaNode;\r
import org.opendaylight.controller.yang.model.api.SchemaPath;\r
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
import org.opendaylight.controller.yang.model.api.UsesNode;\r
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;\r
+import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;\r
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;\r
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;\r
import org.opendaylight.controller.yang.parser.util.RefineHolder;\r
private boolean isBuilt;\r
private UsesNodeImpl instance;\r
private final int line;\r
- private SchemaPath schemaPath;\r
+ private final DataNodeContainerBuilder parent;\r
private final String groupingName;\r
private SchemaPath groupingPath;\r
private boolean augmenting;\r
+ private boolean addedByUses;\r
private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();\r
- private List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
- private List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
+ private final List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
+ private final List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();\r
\r
- public UsesNodeBuilderImpl(final String groupingName, final int line) {\r
+ public UsesNodeBuilderImpl(final String groupingName, final int line, final DataNodeContainerBuilder parent) {\r
this.groupingName = groupingName;\r
this.line = line;\r
+ this.parent = parent;\r
+ }\r
+\r
+ public UsesNodeBuilderImpl(UsesNodeBuilder b) {\r
+ groupingName = b.getGroupingName();\r
+ line = b.getLine();\r
+ parent = b.getParent();\r
+ groupingPath = b.getGroupingPath();\r
+ augmenting = b.isAugmenting();\r
+ addedByUses = b.isAddedByUses();\r
+ addedAugments.addAll(b.getAugmentations());\r
+ refineBuilders.addAll(b.getRefineNodes());\r
+ refines.addAll(b.getRefines());\r
}\r
\r
@Override\r
if (!isBuilt) {\r
instance = new UsesNodeImpl(groupingPath);\r
instance.setAugmenting(augmenting);\r
+ instance.setAddedByUses(addedByUses);\r
\r
// AUGMENTATIONS\r
final Set<AugmentationSchema> augments = new HashSet<AugmentationSchema>();\r
}\r
instance.setRefines(refineNodes);\r
\r
+ // UNKNOWN NODES\r
+ List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();\r
+ for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {\r
+ unknownNodes.add(b.build());\r
+ }\r
+ instance.setUnknownSchemaNodes(unknownNodes);\r
+\r
isBuilt = true;\r
}\r
return instance;\r
}\r
\r
@Override\r
- public void setGroupingPath(SchemaPath groupingPath) {\r
- this.groupingPath = groupingPath;\r
+ public DataNodeContainerBuilder getParent() {\r
+ return parent;\r
}\r
\r
@Override\r
- public SchemaPath getPath() {\r
- return schemaPath;\r
+ public SchemaPath getGroupingPath() {\r
+ return groupingPath;\r
}\r
\r
@Override\r
- public void setPath(SchemaPath path) {\r
- this.schemaPath = path;\r
+ public void setGroupingPath(SchemaPath groupingPath) {\r
+ this.groupingPath = groupingPath;\r
}\r
\r
@Override\r
this.augmenting = augmenting;\r
}\r
\r
+ @Override\r
+ public boolean isAddedByUses() {\r
+ return addedByUses;\r
+ }\r
+\r
+ @Override\r
+ public void setAddedByUses(final boolean addedByUses) {\r
+ this.addedByUses = addedByUses;\r
+ }\r
+\r
@Override\r
public List<SchemaNodeBuilder> getRefineNodes() {\r
return refineBuilders;\r
refines.add(refine);\r
}\r
\r
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {\r
+ return addedUnknownNodes;\r
+ }\r
+\r
+ @Override\r
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {\r
+ addedUnknownNodes.add(unknownNode);\r
+ }\r
\r
- private final class UsesNodeImpl implements UsesNode {\r
+ public final class UsesNodeImpl implements UsesNode {\r
private final SchemaPath groupingPath;\r
private Set<AugmentationSchema> augmentations = Collections.emptySet();\r
private boolean augmenting;\r
+ private boolean addedByUses;\r
private Map<SchemaPath, SchemaNode> refines = Collections.emptyMap();\r
+ private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();\r
\r
private UsesNodeImpl(final SchemaPath groupingPath) {\r
this.groupingPath = groupingPath;\r
return augmentations;\r
}\r
\r
- private void setAugmentations(\r
- final Set<AugmentationSchema> augmentations) {\r
+ private void setAugmentations(final Set<AugmentationSchema> augmentations) {\r
if (augmentations != null) {\r
this.augmentations = augmentations;\r
}\r
this.augmenting = augmenting;\r
}\r
\r
+ @Override\r
+ public boolean isAddedByUses() {\r
+ return addedByUses;\r
+ }\r
+\r
+ private void setAddedByUses(final boolean addedByUses) {\r
+ this.addedByUses = addedByUses;\r
+ }\r
+\r
@Override\r
public Map<SchemaPath, SchemaNode> getRefines() {\r
return refines;\r
}\r
}\r
\r
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
+ return unknownNodes;\r
+ }\r
+\r
+ private void setUnknownSchemaNodes(List<UnknownSchemaNode> unknownSchemaNodes) {\r
+ if (unknownSchemaNodes != null) {\r
+ this.unknownNodes = unknownSchemaNodes;\r
+ }\r
+ }\r
+\r
+ public UsesNodeBuilder toBuilder() {\r
+ return UsesNodeBuilderImpl.this;\r
+ }\r
+\r
@Override\r
public int hashCode() {\r
final int prime = 31;\r
int result = 1;\r
- result = prime * result\r
- + ((groupingPath == null) ? 0 : groupingPath.hashCode());\r
- result = prime * result\r
- + ((augmentations == null) ? 0 : augmentations.hashCode());\r
+ result = prime * result + ((groupingPath == null) ? 0 : groupingPath.hashCode());\r
+ result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());\r
result = prime * result + (augmenting ? 1231 : 1237);\r
return result;\r
}\r
\r
@Override\r
public String toString() {\r
- StringBuilder sb = new StringBuilder(\r
- UsesNodeImpl.class.getSimpleName());\r
+ StringBuilder sb = new StringBuilder(UsesNodeImpl.class.getSimpleName());\r
sb.append("[groupingPath=" + groupingPath + "]");\r
return sb.toString();\r
}\r
import org.opendaylight.controller.antlrv4.code.gen.YangLexer;
import org.opendaylight.controller.antlrv4.code.gen.YangParser;
import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
import org.opendaylight.controller.yang.model.api.GroupingDefinition;
import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.api.SchemaContext;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
import org.opendaylight.controller.yang.model.util.ExtendedType;
import org.opendaylight.controller.yang.model.util.IdentityrefType;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.GroupingBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.IdentityrefTypeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.RpcDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl;
+import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl.UsesNodeImpl;
import org.opendaylight.controller.yang.parser.util.ModuleDependencySort;
import org.opendaylight.controller.yang.parser.util.RefineHolder;
import org.opendaylight.controller.yang.parser.util.RefineUtils;
import com.google.common.collect.Sets;
public final class YangParserImpl implements YangModelParser {
-
private static final Logger logger = LoggerFactory.getLogger(YangParserImpl.class);
@Override
nodeToResolve.setTypedef(newType);
} else {
- if(nodeToResolve instanceof TypeDefinitionBuilder) {
- TypeDefinitionBuilder tdb = (TypeDefinitionBuilder)nodeToResolve;
- TypeConstraints tc = findConstraintsFromTypeBuilder(nodeToResolve, new TypeConstraints(module.getName(), nodeToResolve.getLine()), modules, module, context);
+ if (nodeToResolve instanceof TypeDefinitionBuilder) {
+ TypeDefinitionBuilder tdb = (TypeDefinitionBuilder) nodeToResolve;
+ TypeConstraints tc = findConstraintsFromTypeBuilder(nodeToResolve,
+ new TypeConstraints(module.getName(), nodeToResolve.getLine()), modules, module, context);
tdb.setLengths(tc.getLength());
tdb.setPatterns(tc.getPatterns());
tdb.setRanges(tc.getRange());
/**
* Go through all augment definitions and resolve them. This method works in
- * same way as {@link #resolveAugments(Map)} except that if target node is not
- * found in loaded modules, it search for target node in given context.
+ * same way as {@link #resolveAugments(Map)} except that if target node is
+ * not found in loaded modules, it search for target node in given context.
*
* @param modules
* all loaded modules
* SchemaContext containing already resolved modules
*/
private void resolveIdentitiesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
- final ModuleBuilder module, SchemaContext context) {
+ final ModuleBuilder module, final SchemaContext context) {
final Set<IdentitySchemaNodeBuilder> identities = module.getIdentities();
for (IdentitySchemaNodeBuilder identity : identities) {
final String baseIdentityName = identity.getBaseIdentityName();
private void resolveUsesRefine(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
final Map<List<String>, UsesNodeBuilder> moduleUses = module.getUsesNodes();
for (Map.Entry<List<String>, UsesNodeBuilder> entry : moduleUses.entrySet()) {
+ // refine
final UsesNodeBuilder usesNode = entry.getValue();
final int line = usesNode.getLine();
final GroupingBuilder targetGrouping = getTargetGroupingFromModules(usesNode, modules, module);
for (RefineHolder refine : usesNode.getRefines()) {
final SchemaNodeBuilder nodeToRefine = RefineUtils.getRefineNodeFromGroupingBuilder(targetGrouping,
refine, module.getName());
+ if(nodeToRefine instanceof GroupingMember) {
+ ((GroupingMember)nodeToRefine).setAddedByUses(true);
+ }
RefineUtils.performRefine(nodeToRefine, refine, line);
usesNode.addRefineNode(nodeToRefine);
}
+
+ // child nodes
+ processUsesNode(usesNode, targetGrouping);
}
}
* SchemaContext containing already resolved modules
*/
private void resolveUsesRefineWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
- final ModuleBuilder module, SchemaContext context) {
+ final ModuleBuilder module, final SchemaContext context) {
final Map<List<String>, UsesNodeBuilder> moduleUses = module.getUsesNodes();
for (Map.Entry<List<String>, UsesNodeBuilder> entry : moduleUses.entrySet()) {
final UsesNodeBuilder usesNode = entry.getValue();
for (RefineHolder refine : usesNode.getRefines()) {
final SchemaNodeBuilder nodeToRefine = RefineUtils.getRefineNodeFromGroupingDefinition(
targetGrouping, refine, module.getName());
+ if(nodeToRefine instanceof GroupingMember) {
+ ((GroupingMember)nodeToRefine).setAddedByUses(true);
+ }
RefineUtils.performRefine(nodeToRefine, refine, line);
usesNode.addRefineNode(nodeToRefine);
}
+
+ processUsesNode(usesNode, targetGrouping);
} else {
usesNode.setGroupingPath(targetGroupingBuilder.getPath());
for (RefineHolder refine : usesNode.getRefines()) {
final SchemaNodeBuilder nodeToRefine = RefineUtils.getRefineNodeFromGroupingBuilder(
targetGroupingBuilder, refine, module.getName());
+ if(nodeToRefine instanceof GroupingMember) {
+ ((GroupingMember)nodeToRefine).setAddedByUses(true);
+ }
RefineUtils.performRefine(nodeToRefine, refine, line);
usesNode.addRefineNode(nodeToRefine);
}
+
+ processUsesNode(usesNode, targetGroupingBuilder);
}
}
}
return null;
}
- List<QName> path = usesBuilder.getPath().getPath();
+ List<QName> path = usesBuilder.getParent().getPath().getPath();
GroupingBuilder result = null;
Set<GroupingBuilder> groupings = dependentModule.getModuleGroupings();
result = findGroupingBuilder(groupings, groupingName);
if (currentNode instanceof RpcDefinitionBuilder) {
groupings = ((RpcDefinitionBuilder) currentNode).getGroupings();
} else if (currentNode instanceof DataNodeContainerBuilder) {
- groupings = ((DataNodeContainerBuilder) currentNode).getGroupings();
+ groupings = ((DataNodeContainerBuilder) currentNode).getGroupingBuilders();
} else {
groupings = Collections.emptySet();
}
* @return grouping with given name if found, null otherwise
*/
private GroupingDefinition getTargetGroupingFromContext(final UsesNodeBuilder usesBuilder,
- final ModuleBuilder module, SchemaContext context) {
+ final ModuleBuilder module, final SchemaContext context) {
final int line = usesBuilder.getLine();
String groupingString = usesBuilder.getGroupingName();
String groupingPrefix;
return findGroupingDefinition(dependentModule.getGroupings(), groupingName);
}
+ /**
+ * Add nodes defined in target grouping to current context.
+ *
+ * @param usesNode
+ * @param targetGrouping
+ */
+ private void processUsesNode(final UsesNodeBuilder usesNode, final GroupingBuilder targetGrouping) {
+ List<SchemaNodeBuilder> refineNodes = usesNode.getRefineNodes();
+ DataNodeContainerBuilder parent = usesNode.getParent();
+ SchemaPath parentPath = parent.getPath();
+ for (DataSchemaNodeBuilder child : targetGrouping.getChildNodeBuilders()) {
+ // if node is refined, take it from refined nodes and continue
+ SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+ if(refined != null) {
+ refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+ parent.addChildNode((DataSchemaNodeBuilder)refined);
+ continue;
+ }
+
+ DataSchemaNodeBuilder newChild = null;
+ if (child instanceof AnyXmlBuilder) {
+ newChild = new AnyXmlBuilder((AnyXmlBuilder) child);
+ } else if (child instanceof ChoiceBuilder) {
+ newChild = new ChoiceBuilder((ChoiceBuilder) child);
+ } else if (child instanceof ContainerSchemaNodeBuilder) {
+ newChild = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) child);
+ } else if (child instanceof LeafListSchemaNodeBuilder) {
+ newChild = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) child);
+ } else if (child instanceof LeafSchemaNodeBuilder) {
+ newChild = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) child);
+ } else if (child instanceof ListSchemaNodeBuilder) {
+ newChild = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) child);
+ }
+
+ if (newChild instanceof GroupingMember) {
+ ((GroupingMember) newChild).setAddedByUses(true);
+ }
+ newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+ parent.addChildNode(newChild);
+ }
+ for (GroupingBuilder g : targetGrouping.getGroupingBuilders()) {
+ GroupingBuilder newGrouping = new GroupingBuilderImpl(g);
+ newGrouping.setAddedByUses(true);
+ newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName()));
+ parent.addGrouping(newGrouping);
+ }
+ for (TypeDefinitionBuilder td : targetGrouping.getTypeDefinitionBuilders()) {
+ TypeDefinitionBuilder newType = new TypeDefinitionBuilderImpl(td);
+ newType.setAddedByUses(true);
+ newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName()));
+ parent.addTypedef(newType);
+ }
+ for (UsesNodeBuilder un : targetGrouping.getUses()) {
+ UsesNodeBuilder newUses = new UsesNodeBuilderImpl(un);
+ newUses.setAddedByUses(true);
+ // uses has not path
+ parent.addUsesNode(newUses);
+ }
+ for (UnknownSchemaNodeBuilder un : targetGrouping.getUnknownNodes()) {
+ UnknownSchemaNodeBuilder newUn = new UnknownSchemaNodeBuilder(un);
+ newUn.setAddedByUses(true);
+ newUn.setPath(createSchemaPath(parentPath, un.getQName().getLocalName()));
+ parent.addUnknownSchemaNode(newUn);
+ }
+ }
+
+ private void processUsesNode(final UsesNodeBuilder usesNode, final GroupingDefinition targetGrouping) {
+ final int line = usesNode.getLine();
+ List<SchemaNodeBuilder> refineNodes = usesNode.getRefineNodes();
+ DataNodeContainerBuilder parent = usesNode.getParent();
+ SchemaPath parentPath = parent.getPath();
+ for (DataSchemaNode child : targetGrouping.getChildNodes()) {
+ // if node is refined, take it from refined nodes and continue
+ SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+ if(refined != null) {
+ refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+ parent.addChildNode((DataSchemaNodeBuilder)refined);
+ continue;
+ }
+
+ DataSchemaNodeBuilder newChild = null;
+ if (child instanceof AnyXmlSchemaNode) {
+ newChild = createAnyXml((AnyXmlSchemaNode) child, line);
+ } else if (child instanceof ChoiceNode) {
+ newChild = createChoice((ChoiceNode) child, line);
+ } else if (child instanceof ContainerSchemaNode) {
+ newChild = createContainer((ContainerSchemaNode) child, line);
+ } else if (child instanceof LeafListSchemaNode) {
+ newChild = createLeafList((LeafListSchemaNode) child, line);
+ } else if (child instanceof LeafSchemaNode) {
+ newChild = createLeafBuilder((LeafSchemaNode) child, line);
+ } else if (child instanceof ListSchemaNode) {
+ newChild = createList((ListSchemaNode) child, line);
+ }
+
+ if (newChild instanceof GroupingMember) {
+ ((GroupingMember) newChild).setAddedByUses(true);
+ }
+ newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+ parent.addChildNode(newChild);
+ }
+ for (GroupingDefinition g : targetGrouping.getGroupings()) {
+ GroupingBuilder newGrouping = createGrouping(g, line);
+ newGrouping.setAddedByUses(true);
+ newGrouping.setPath(createSchemaPath(parentPath, newGrouping.getQName().getLocalName()));
+ parent.addGrouping(newGrouping);
+ }
+ for (TypeDefinition<?> td : targetGrouping.getTypeDefinitions()) {
+ TypeDefinitionBuilder newType = createTypedef((ExtendedType) td, line);
+ newType.setAddedByUses(true);
+ newType.setPath(createSchemaPath(parentPath, newType.getQName().getLocalName()));
+ parent.addTypedef(newType);
+ }
+ for (UsesNode un : targetGrouping.getUses()) {
+ if (un instanceof UsesNodeImpl) {
+ UsesNodeBuilder newUses = new UsesNodeBuilderImpl(((UsesNodeImpl) un).toBuilder());
+ newUses.setAddedByUses(true);
+ // uses has not path
+ parent.addUsesNode(newUses);
+ }
+ }
+ for (UnknownSchemaNode un : targetGrouping.getUnknownSchemaNodes()) {
+ UnknownSchemaNodeBuilder newNode = createUnknownSchemaNode(un, line);
+ newNode.setAddedByUses(true);
+ newNode.setPath(createSchemaPath(parentPath, un.getQName().getLocalName()));
+ parent.addUnknownSchemaNode(newNode);
+ }
+ }
+
private QName findFullQName(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module,
final IdentityrefTypeBuilder idref) {
QName result = null;
import java.util.Stack;
import org.antlr.v4.runtime.tree.ParseTree;
-import org.opendaylight.controller.antlrv4.code.gen.YangParser;
+import org.opendaylight.controller.antlrv4.code.gen.*;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Argument_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Base_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Contact_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Units_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.When_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext;
-import org.opendaylight.controller.antlrv4.code.gen.YangParserBaseListener;
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix);
moduleBuilder.addIdentityrefType(getIdentityrefBase(typeBody), actualPath, path, line);
} else {
- type = parseTypeBody(moduleName, typeName, typeBody, actualPath, namespace, revision,
+ type = parseTypeWithBody(moduleName, typeName, typeBody, actualPath, namespace, revision,
yangModelPrefix, moduleBuilder.getActualNode());
moduleBuilder.setType(type, actualPath);
}
}
} else {
- type = parseUnknownTypeBody(typeQName, typeBody, actualPath, namespace, revision, yangModelPrefix,
- moduleBuilder.getActualNode(), moduleBuilder);
- // mark parent node of this type statement as dirty
+ type = parseUnknownTypeWithBody(typeQName, typeBody, actualPath, namespace, revision, yangModelPrefix,
+ moduleBuilder.getActualNode());
+ // add parent node of this type statement to dirty nodes
moduleBuilder.addDirtyNode(actualPath);
moduleBuilder.setType(type, actualPath);
}
@Override
public void enterContainer_stmt(Container_stmtContext ctx) {
+ final int line = ctx.getStart().getLine();
final String containerName = stringFromNode(ctx);
QName containerQName = new QName(namespace, revision, yangModelPrefix, containerName);
- ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(containerQName, actualPath, ctx.getStart()
- .getLine());
+
+ SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, containerName);
+
+ ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(path, containerQName, actualPath, line);
moduleBuilder.enterNode(builder);
updatePath(containerName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree childNode = ctx.getChild(i);
public void enterLeaf_stmt(Leaf_stmtContext ctx) {
final String leafName = stringFromNode(ctx);
QName leafQName = new QName(namespace, revision, yangModelPrefix, leafName);
- LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(leafQName, actualPath, ctx.getStart().getLine());
+ SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, leafName);
+
+ LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(schemaPath, leafQName, actualPath, ctx.getStart().getLine());
moduleBuilder.enterNode(builder);
updatePath(leafName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
String defaultStr = null;
String unitsStr = null;
moduleBuilder.enterNode(builder);
updatePath(groupingPathStr);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
}
@Override
public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) {
final String leafListName = stringFromNode(ctx);
QName leafListQName = new QName(namespace, revision, yangModelPrefix, leafListName);
- LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(leafListQName, actualPath, ctx.getStart()
+ SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, leafListName);
+
+ LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(schemaPath, leafListQName, actualPath, ctx.getStart()
.getLine());
moduleBuilder.enterNode(builder);
updatePath(leafListName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree childNode = ctx.getChild(i);
@Override
public void enterList_stmt(List_stmtContext ctx) {
- final String containerName = stringFromNode(ctx);
- QName containerQName = new QName(namespace, revision, yangModelPrefix, containerName);
- ListSchemaNodeBuilder builder = moduleBuilder.addListNode(containerQName, actualPath, ctx.getStart().getLine());
+ final String listName = stringFromNode(ctx);
+ QName listQName = new QName(namespace, revision, yangModelPrefix, listName);
+ SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, listName);
+
+ ListSchemaNodeBuilder builder = moduleBuilder.addListNode(schemaPath, listQName, actualPath, ctx.getStart().getLine());
moduleBuilder.enterNode(builder);
- updatePath(containerName);
+ updatePath(listName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
String keyDefinition = "";
for (int i = 0; i < ctx.getChildCount(); ++i) {
public void enterAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) {
final String anyXmlName = stringFromNode(ctx);
QName anyXmlQName = new QName(namespace, revision, yangModelPrefix, anyXmlName);
- AnyXmlBuilder builder = moduleBuilder.addAnyXml(anyXmlQName, actualPath, ctx.getStart().getLine());
+ SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, anyXmlName);
+
+ AnyXmlBuilder builder = moduleBuilder.addAnyXml(schemaPath, anyXmlQName, actualPath, ctx.getStart().getLine());
moduleBuilder.enterNode(builder);
updatePath(anyXmlName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
}
@Override
builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
+ builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, ctx.getStart().getLine()));
// set 'default' case
for (int i = 0; i < ctx.getChildCount(); i++) {
public void enterInput_stmt(YangParser.Input_stmtContext ctx) {
final String input = "input";
QName rpcQName = new QName(namespace, revision, yangModelPrefix, input);
- ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(rpcQName, ctx.getStart().getLine());
+ SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, input);
+
+ ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(path, rpcQName, ctx.getStart().getLine());
moduleBuilder.enterNode(builder);
updatePath(input);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
}
public void enterOutput_stmt(YangParser.Output_stmtContext ctx) {
final String output = "output";
QName rpcQName = new QName(namespace, revision, yangModelPrefix, output);
- ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(rpcQName, ctx.getStart().getLine());
+ SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, output);
+
+ ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(path, rpcQName, ctx.getStart().getLine());
moduleBuilder.enterNode(builder);
updatePath(output);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
}
moduleBuilder.exitNode();
}
- @Override
- public void enterConfig_stmt(YangParser.Config_stmtContext ctx) {
- boolean configuration = parseConfig(ctx);
- moduleBuilder.addConfiguration(configuration, actualPath, ctx.getStart().getLine());
- }
-
@Override
public void enterIdentity_stmt(YangParser.Identity_stmtContext ctx) {
final String identityName = stringFromNode(ctx);
import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
-import org.opendaylight.controller.yang.model.api.ChoiceCaseNode;
import org.opendaylight.controller.yang.model.api.ChoiceNode;
import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
import org.opendaylight.controller.yang.model.api.SchemaNode;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition;
import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;
import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.GroupingMember;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl;
public final class ParserUtils {
private ParserUtils() {
}
+ /**
+ * Create new SchemaPath from given path and name.
+ *
+ * Append new qname to schema path created from name argument. New QName
+ * gets namespace, revision and prefix same as last qname in current schema
+ * path.
+ *
+ * @param schemaPath
+ * @param name
+ * @return
+ */
+ public static SchemaPath createSchemaPath(SchemaPath schemaPath, String name) {
+ List<QName> path = new ArrayList<QName>(schemaPath.getPath());
+ QName last = path.get(path.size() - 1);
+ QName newQName = new QName(last.getNamespace(), last.getRevision(), last.getPrefix(), name);
+ path.add(newQName);
+ return new SchemaPath(path, schemaPath.isAbsolute());
+ }
+
/**
* Get module import referenced by given prefix.
*
return new SchemaPath(path, absolute);
}
+ /**
+ * Check if node is present in refine nodes.
+ *
+ * @param nodeQName
+ * qname of node
+ * @param refineNodes
+ * collections of refined nodes
+ * @return true, if node with given qname was found, false otherwise
+ */
+ public static SchemaNodeBuilder getRefined(QName nodeQName, List<SchemaNodeBuilder> refineNodes) {
+ for (SchemaNodeBuilder rn : refineNodes) {
+ if (rn.getQName().equals(nodeQName)) {
+ return rn;
+ }
+ }
+ return null;
+ }
+
/**
* Pull restriction from type and add them to constraints.
*
Builder result = grouping.getChildNode(refineNodeName);
// search groupings
if (result == null) {
- Set<GroupingBuilder> grps = grouping.getGroupings();
+ Set<GroupingBuilder> grps = grouping.getGroupingBuilders();
for (GroupingBuilder gr : grps) {
if (gr.getQName().getLocalName().equals(refineNodeName)) {
result = gr;
}
// search typedefs
if (result == null) {
- Set<TypeDefinitionBuilder> typedefs = grouping.getTypeDefinitions();
+ Set<TypeDefinitionBuilder> typedefs = grouping.getTypeDefinitionBuilders();
for (TypeDefinitionBuilder typedef : typedefs) {
if (typedef.getQName().getLocalName().equals(refineNodeName)) {
result = typedef;
* augmentation target node
*/
public static void fillAugmentTarget(final AugmentationSchemaBuilder augment, final DataNodeContainerBuilder target) {
- for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+ boolean usesAugment = augment.getParent() instanceof UsesNodeBuilder;
+ for (DataSchemaNodeBuilder builder : augment.getChildNodeBuilders()) {
builder.setAugmenting(true);
+ if (usesAugment) {
+ if (builder instanceof GroupingMember) {
+ ((GroupingMember) builder).setAddedByUses(true);
+ }
+ }
correctAugmentChildPath(builder, target.getPath());
target.addChildNode(builder);
}
* augmentation target choice node
*/
public static void fillAugmentTarget(final AugmentationSchemaBuilder augment, final ChoiceBuilder target) {
- for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+ boolean usesAugment = augment.getParent() instanceof UsesNodeBuilder;
+ for (DataSchemaNodeBuilder builder : augment.getChildNodeBuilders()) {
builder.setAugmenting(true);
+ if (usesAugment) {
+ if (builder instanceof GroupingMember) {
+ ((GroupingMember) builder).setAddedByUses(true);
+ }
+ }
correctAugmentChildPath(builder, target.getPath());
target.addChildNode(builder);
}
// set correct path for all child nodes
if (childNode instanceof DataNodeContainerBuilder) {
DataNodeContainerBuilder dataNodeContainer = (DataNodeContainerBuilder) childNode;
- for (DataSchemaNodeBuilder child : dataNodeContainer.getChildNodes()) {
+ for (DataSchemaNodeBuilder child : dataNodeContainer.getChildNodeBuilders()) {
correctAugmentChildPath(child, childNode.getPath());
}
}
return new SchemaPath(newPath, schemaPath.isAbsolute());
}
- public static LeafSchemaNodeBuilder copyLeafBuilder(final LeafSchemaNodeBuilder old) {
- final LeafSchemaNodeBuilder copy = new LeafSchemaNodeBuilder(old.getQName(), old.getLine());
- final TypeDefinition<?> type = old.getType();
- if (type == null) {
- copy.setTypedef(old.getTypedef());
- } else {
- copy.setType(type);
- }
- copyDataSchemaNodeArgs(old, copy);
- copyConstraintsFromBuilder(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDefaultStr(old.getDefaultStr());
- copy.setUnits(old.getUnits());
- return copy;
- }
-
- public static ContainerSchemaNodeBuilder copyContainerBuilder(final ContainerSchemaNodeBuilder old) {
- final ContainerSchemaNodeBuilder copy = new ContainerSchemaNodeBuilder(old.getQName(), old.getLine());
- copyDataSchemaNodeArgs(old, copy);
- copyConstraintsFromBuilder(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- for (DataSchemaNodeBuilder child : old.getChildNodes()) {
- copy.addChildNode(child);
- }
- for (GroupingBuilder grouping : old.getGroupings()) {
- copy.addGrouping(grouping);
- }
- for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
- copy.addTypedef(typedef);
- }
- for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- copy.addAugmentation(augment);
- }
- for (UsesNodeBuilder use : old.getUsesNodes()) {
- copy.addUsesNode(use);
- }
- copy.setPresence(old.isPresence());
- return copy;
- }
-
- public static ListSchemaNodeBuilder copyListBuilder(final ListSchemaNodeBuilder old) {
- final ListSchemaNodeBuilder copy = new ListSchemaNodeBuilder(old.getQName(), old.getLine());
- copyDataSchemaNodeArgs(old, copy);
- copyConstraintsFromBuilder(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- for (DataSchemaNodeBuilder child : old.getChildNodes()) {
- copy.addChildNode(child);
- }
- for (GroupingBuilder grouping : old.getGroupings()) {
- copy.addGrouping(grouping);
- }
- for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
- copy.addTypedef(typedef);
- }
- for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- copy.addAugmentation(augment);
- }
- for (UsesNodeBuilder use : old.getUsesNodes()) {
- copy.addUsesNode(use);
- }
- copy.setUserOrdered(old.isUserOrdered());
- return copy;
- }
-
- public static LeafListSchemaNodeBuilder copyLeafListBuilder(final LeafListSchemaNodeBuilder old) {
- final LeafListSchemaNodeBuilder copy = new LeafListSchemaNodeBuilder(old.getQName(), old.getLine());
- copyDataSchemaNodeArgs(old, copy);
- copyConstraintsFromBuilder(old, copy);
- final TypeDefinition<?> type = old.getType();
- if (type == null) {
- copy.setTypedef(old.getTypedef());
- } else {
- copy.setType(type);
- }
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setUserOrdered(old.isUserOrdered());
- return copy;
- }
-
- public static ChoiceBuilder copyChoiceBuilder(final ChoiceBuilder old) {
- final ChoiceBuilder copy = new ChoiceBuilder(old.getQName(), old.getLine());
- copyDataSchemaNodeArgs(old, copy);
- copyConstraintsFromBuilder(old, copy);
- for (ChoiceCaseBuilder caseBuilder : old.getCases()) {
- copy.addChildNode(caseBuilder);
- }
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDefaultCase(old.getDefaultCase());
- return copy;
- }
-
- public static AnyXmlBuilder copyAnyXmlBuilder(final AnyXmlBuilder old) {
- final AnyXmlBuilder copy = new AnyXmlBuilder(old.getQName(), old.getLine());
- copyDataSchemaNodeArgs(old, copy);
- copyConstraintsFromBuilder(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- return copy;
- }
-
- public static GroupingBuilder copyGroupingBuilder(final GroupingBuilder old) {
- final GroupingBuilder copy = new GroupingBuilderImpl(old.getQName(), old.getLine());
- copy.setPath(old.getPath());
- for (DataSchemaNodeBuilder child : old.getChildNodes()) {
- copy.addChildNode(child);
- }
- for (GroupingBuilder grouping : old.getGroupings()) {
- copy.addGrouping(grouping);
- }
- for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
- copy.addTypedef(typedef);
- }
- for (UsesNodeBuilder use : old.getUses()) {
- copy.addUsesNode(use);
- }
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- return copy;
- }
-
- public static TypeDefinitionBuilderImpl copyTypedefBuilder(final TypeDefinitionBuilderImpl old) {
- final TypeDefinitionBuilderImpl copy = new TypeDefinitionBuilderImpl(old.getQName(), old.getLine());
- copy.setPath(old.getPath());
- copy.setDefaultValue(old.getDefaultValue());
- copy.setUnits(old.getUnits());
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
-
- copy.setRanges(old.getRanges());
- copy.setLengths(old.getLengths());
- copy.setPatterns(old.getPatterns());
- copy.setFractionDigits(old.getFractionDigits());
-
- TypeDefinition<?> type = old.getType();
- if (type == null) {
- copy.setTypedef(old.getTypedef());
- } else {
- copy.setType(old.getType());
- }
- copy.setUnits(old.getUnits());
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- return copy;
- }
-
- public static UsesNodeBuilder copyUsesNodeBuilder(final UsesNodeBuilder old) {
- final UsesNodeBuilder copy = new UsesNodeBuilderImpl(old.getGroupingName(), old.getLine());
- for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- copy.addAugment(augment);
- }
- copy.setAugmenting(old.isAugmenting());
- for (SchemaNodeBuilder refineNode : old.getRefineNodes()) {
- copy.addRefineNode(refineNode);
- }
- return copy;
- }
-
- private static void copyDataSchemaNodeArgs(final DataSchemaNodeBuilder oldBuilder,
- final DataSchemaNodeBuilder newBuilder) {
- newBuilder.setPath(oldBuilder.getPath());
- newBuilder.setDescription(oldBuilder.getDescription());
- newBuilder.setReference(oldBuilder.getReference());
- newBuilder.setStatus(oldBuilder.getStatus());
- newBuilder.setAugmenting(oldBuilder.isAugmenting());
- if (!(oldBuilder instanceof ChoiceCaseNode)) {
- newBuilder.setConfiguration(oldBuilder.isConfiguration());
- }
- }
-
- /**
- * Copy constraints from old builder to new builder.
- *
- * @param oldBuilder
- * @param newBuilder
- */
- private static void copyConstraintsFromBuilder(final DataSchemaNodeBuilder oldBuilder,
- final DataSchemaNodeBuilder newBuilder) {
- final ConstraintsBuilder oldConstraints = oldBuilder.getConstraints();
- final ConstraintsBuilder newConstraints = newBuilder.getConstraints();
- newConstraints.addWhenCondition(oldConstraints.getWhenCondition());
- for (MustDefinition must : oldConstraints.getMustDefinitions()) {
- newConstraints.addMustDefinition(must);
- }
- newConstraints.setMandatory(oldConstraints.isMandatory());
- newConstraints.setMinElements(oldConstraints.getMinElements());
- newConstraints.setMaxElements(oldConstraints.getMaxElements());
- }
-
/**
* Create LeafSchemaNodeBuilder from given LeafSchemaNode.
*
* @return builder object from leaf
*/
public static LeafSchemaNodeBuilder createLeafBuilder(LeafSchemaNode leaf, int line) {
- final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(leaf.getQName(), line);
+ final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(leaf.getQName(), leaf.getPath(), line);
convertDataSchemaNode(leaf, builder);
+ builder.setConfiguration(leaf.isConfiguration());
final TypeDefinition<?> type = leaf.getType();
builder.setType(type);
builder.setPath(leaf.getPath());
}
public static ContainerSchemaNodeBuilder createContainer(ContainerSchemaNode container, int line) {
- final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(container.getQName(), line);
+ final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(container.getQName(),
+ container.getPath(), line);
convertDataSchemaNode(container, builder);
+ builder.setConfiguration(container.isConfiguration());
builder.setUnknownNodes(container.getUnknownSchemaNodes());
builder.setChildNodes(container.getChildNodes());
builder.setGroupings(container.getGroupings());
}
public static ListSchemaNodeBuilder createList(ListSchemaNode list, int line) {
- ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(list.getQName(), line);
+ ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(list.getQName(), list.getPath(), line);
convertDataSchemaNode(list, builder);
+ builder.setConfiguration(list.isConfiguration());
builder.setUnknownNodes(list.getUnknownSchemaNodes());
builder.setTypedefs(list.getTypeDefinitions());
builder.setChildNodes(list.getChildNodes());
}
public static LeafListSchemaNodeBuilder createLeafList(LeafListSchemaNode leafList, int line) {
- final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(leafList.getQName(), line);
+ final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(leafList.getQName(),
+ leafList.getPath(), line);
convertDataSchemaNode(leafList, builder);
+ builder.setConfiguration(leafList.isConfiguration());
builder.setType(leafList.getType());
builder.setUnknownNodes(leafList.getUnknownSchemaNodes());
builder.setUserOrdered(leafList.isUserOrdered());
public static ChoiceBuilder createChoice(ChoiceNode choice, int line) {
final ChoiceBuilder builder = new ChoiceBuilder(choice.getQName(), line);
convertDataSchemaNode(choice, builder);
+ builder.setConfiguration(choice.isConfiguration());
builder.setCases(choice.getCases());
builder.setUnknownNodes(choice.getUnknownSchemaNodes());
builder.setDefaultCase(choice.getDefaultCase());
}
public static AnyXmlBuilder createAnyXml(AnyXmlSchemaNode anyxml, int line) {
- final AnyXmlBuilder builder = new AnyXmlBuilder(anyxml.getQName(), line);
+ final AnyXmlBuilder builder = new AnyXmlBuilder(anyxml.getQName(), anyxml.getPath(), line);
convertDataSchemaNode(anyxml, builder);
+ builder.setConfiguration(anyxml.isConfiguration());
builder.setUnknownNodes(anyxml.getUnknownSchemaNodes());
return builder;
}
return builder;
}
+ public static UnknownSchemaNodeBuilder createUnknownSchemaNode(UnknownSchemaNode grouping, int line) {
+ final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(grouping.getQName(), line);
+ builder.setPath(grouping.getPath());
+ builder.setUnknownNodes(grouping.getUnknownSchemaNodes());
+ builder.setDescription(grouping.getDescription());
+ builder.setReference(grouping.getReference());
+ builder.setStatus(grouping.getStatus());
+ builder.setAddedByUses(grouping.isAddedByUses());
+ builder.setNodeType(grouping.getNodeType());
+ builder.setNodeParameter(grouping.getNodeParameter());
+ return builder;
+ }
+
/**
* Set DataSchemaNode arguments to builder object
*
builder.setReference(node.getReference());
builder.setStatus(node.getStatus());
builder.setAugmenting(node.isAugmenting());
- if (!(node instanceof ChoiceCaseNode)) {
- builder.setConfiguration(node.isConfiguration());
- }
copyConstraintsFromDefinition(node.getConstraints(), builder.getConstraints());
}
public static void processAugmentation(final AugmentationSchemaBuilder augmentBuilder, final List<QName> path,
final ModuleBuilder module, final QName qname, final ModuleBuilder dependentModuleBuilder) {
DataSchemaNodeBuilder currentParent = null;
- for (DataSchemaNodeBuilder child : dependentModuleBuilder.getChildNodes()) {
+ for (DataSchemaNodeBuilder child : dependentModuleBuilder.getChildNodeBuilders()) {
final QName childQName = child.getQName();
if (childQName.getLocalName().equals(qname.getLocalName())) {
currentParent = child;
for (int i = 1; i < path.size(); i++) {
final QName currentQName = path.get(i);
DataSchemaNodeBuilder newParent = null;
- for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder) currentParent).getChildNodes()) {
- final QName childQName = child.getQName();
- if (childQName.getLocalName().equals(currentQName.getLocalName())) {
- newParent = child;
- break;
+ if(currentParent instanceof DataNodeContainerBuilder) {
+ for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder) currentParent).getChildNodeBuilders()) {
+ final QName childQName = child.getQName();
+ if (childQName.getLocalName().equals(currentQName.getLocalName())) {
+ newParent = child;
+ break;
+ }
+ }
+ } else if(currentParent instanceof ChoiceBuilder) {
+ for(ChoiceCaseBuilder caseBuilder : ((ChoiceBuilder)currentParent).getCases()) {
+ final QName caseQName = caseBuilder.getQName();
+ if (caseQName.getLocalName().equals(currentQName.getLocalName())) {
+ newParent = caseBuilder;
+ break;
+ }
}
}
+
if (newParent == null) {
break; // node not found, quit search
} else {
if (currentNode instanceof RpcDefinitionBuilder) {
typedefs = ((RpcDefinitionBuilder) currentNode).getTypeDefinitions();
} else if (currentNode instanceof DataNodeContainerBuilder) {
- typedefs = ((DataNodeContainerBuilder) currentNode).getTypeDefinitions();
+ typedefs = ((DataNodeContainerBuilder) currentNode).getTypeDefinitionBuilders();
} else {
typedefs = Collections.emptySet();
}
import org.opendaylight.controller.yang.model.api.MustDefinition;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
-public final class RefineHolder implements Builder {
+public final class RefineHolder implements Builder, ConfigNode {
private final String name;
private final int line;
private String defaultStr;
this.reference = reference;
}
- public Boolean isConfig() {
+ @Override
+ public Boolean isConfiguration() {
return config;
}
- public void setConfig(final Boolean config) {
+ @Override
+ public void setConfiguration(final Boolean config) {
this.config = config;
}
import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.GroupingBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.LeafListSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
Builder result = null;
final Builder lookedUpBuilder = findRefineTargetBuilder(targetGrouping, refine.getName());
if (lookedUpBuilder instanceof LeafSchemaNodeBuilder) {
- result = copyLeafBuilder((LeafSchemaNodeBuilder) lookedUpBuilder);
+ result = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) lookedUpBuilder);
} else if (lookedUpBuilder instanceof ContainerSchemaNodeBuilder) {
- result = copyContainerBuilder((ContainerSchemaNodeBuilder) lookedUpBuilder);
+ result = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) lookedUpBuilder);
} else if (lookedUpBuilder instanceof ListSchemaNodeBuilder) {
- result = copyListBuilder((ListSchemaNodeBuilder) lookedUpBuilder);
+ result = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) lookedUpBuilder);
} else if (lookedUpBuilder instanceof LeafListSchemaNodeBuilder) {
- result = copyLeafListBuilder((LeafListSchemaNodeBuilder) lookedUpBuilder);
+ result = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) lookedUpBuilder);
} else if (lookedUpBuilder instanceof ChoiceBuilder) {
- result = copyChoiceBuilder((ChoiceBuilder) lookedUpBuilder);
+ result = new ChoiceBuilder((ChoiceBuilder) lookedUpBuilder);
} else if (lookedUpBuilder instanceof AnyXmlBuilder) {
- result = copyAnyXmlBuilder((AnyXmlBuilder) lookedUpBuilder);
+ result = new AnyXmlBuilder((AnyXmlBuilder) lookedUpBuilder);
} else if (lookedUpBuilder instanceof GroupingBuilder) {
- result = copyGroupingBuilder((GroupingBuilder) lookedUpBuilder);
+ result = new GroupingBuilderImpl((GroupingBuilder) lookedUpBuilder);
} else if (lookedUpBuilder instanceof TypeDefinitionBuilder) {
- result = copyTypedefBuilder((TypeDefinitionBuilderImpl) lookedUpBuilder);
+ result = new TypeDefinitionBuilderImpl((TypeDefinitionBuilder) lookedUpBuilder);
} else {
throw new YangParseException(moduleName, refine.getLine(), "Target '" + refine.getName()
+ "' can not be refined");
}
}
- Boolean config = refine.isConfig();
+ Boolean config = refine.isConfiguration();
if (config != null) {
try {
- Method method = cls.getDeclaredMethod("setConfiguration", Boolean.TYPE);
+ Method method = cls.getDeclaredMethod("setConfiguration", Boolean.class);
method.invoke(node, config);
} catch (Exception e) {
throw new YangParseException(line, "Cannot refine config in " + cls.getName(), e);
import java.util.Stack;
import org.antlr.v4.runtime.tree.ParseTree;
-import org.opendaylight.controller.antlrv4.code.gen.YangParser;
+import org.opendaylight.controller.antlrv4.code.gen.*;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Argument_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Base_stmtContext;
import org.opendaylight.controller.antlrv4.code.gen.YangParser.Bit_stmtContext;
import org.opendaylight.controller.yang.model.util.Uint8;
import org.opendaylight.controller.yang.model.util.UnknownType;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
+import org.opendaylight.controller.yang.parser.builder.api.ConfigNode;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.ChoiceCaseBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ConstraintsBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class YangModelBuilderUtil {
-
private static final Logger logger = LoggerFactory.getLogger(YangModelBuilderUtil.class);
private YangModelBuilderUtil() {
}
/**
- * Create SchemaPath object from given path list with namespace, revision
- * and prefix based on given values.
+ * Create SchemaPath from actualPath and names.
*
* @param actualPath
* current position in model
* @param namespace
* @param revision
* @param prefix
+ * @param names
* @return SchemaPath object.
*/
public static SchemaPath createActualSchemaPath(final List<String> actualPath, final URI namespace,
- final Date revision, final String prefix) {
+ final Date revision, final String prefix, final String... names) {
final List<QName> path = new ArrayList<QName>();
QName qname;
// start from index 1 - module name omited
qname = new QName(namespace, revision, prefix, actualPath.get(i));
path.add(qname);
}
+ for (String name : names) {
+ qname = new QName(namespace, revision, prefix, name);
+ path.add(qname);
+ }
return new SchemaPath(path, true);
}
}
/**
- * Parse orderedby statement.
+ * Parse 'ordered-by' statement.
+ *
+ * The 'ordered-by' statement defines whether the order of entries within a
+ * list are determined by the user or the system. The argument is one of the
+ * strings "system" or "user". If not present, order defaults to "system".
*
* @param childNode
* Ordered_by_stmtContext
- * @return true, if orderedby contains value 'user' or false otherwise
+ * @return true, if ordered-by contains value 'user', false otherwise
*/
public static boolean parseUserOrdered(Ordered_by_stmtContext childNode) {
boolean result = false;
return result;
}
+ public static Boolean getConfig(final ParseTree ctx, final Builder parent, final String moduleName, final int line) {
+ Boolean result = null;
+ // parse configuration statement
+ Boolean configuration = null;
+ for (int i = 0; i < ctx.getChildCount(); i++) {
+ ParseTree child = ctx.getChild(i);
+ if (child instanceof Config_stmtContext) {
+ configuration = parseConfig((Config_stmtContext) child);
+ break;
+ }
+ }
+
+ // If 'config' is not specified, the default is the same as the parent
+ // schema node's 'config' value
+ if (configuration == null) {
+ if (parent instanceof ConfigNode) {
+ Boolean parentConfig = ((ConfigNode) parent).isConfiguration();
+ // If the parent node is a rpc input or output, it can has
+ // config set to null
+ result = parentConfig == null ? true : parentConfig;
+ } else if (parent instanceof ChoiceCaseBuilder) {
+ // If the parent node is a 'case' node, the value is the same as
+ // the 'case' node's parent 'choice' node
+ ChoiceCaseBuilder choiceCase = (ChoiceCaseBuilder) parent;
+ ChoiceBuilder choice = choiceCase.getParent();
+ Boolean parentConfig = null;
+ if (choice == null) {
+ parentConfig = true;
+ } else {
+ parentConfig = choice.isConfiguration();
+ }
+ result = parentConfig;
+ } else {
+ result = true;
+ }
+ } else {
+ // Check first: if a node has 'config' set to 'false', no node
+ // underneath it can have 'config' set to 'true'
+ if (parent instanceof ConfigNode) {
+ Boolean parentConfig = ((ConfigNode) parent).isConfiguration();
+ if (parentConfig == false && configuration == true) {
+ throw new YangParseException(moduleName, line,
+ "Can not set 'config' to 'true' if parent node has 'config' set to 'false'");
+ }
+ }
+ result = configuration;
+ }
+
+ return result;
+ }
+
/**
- * Parse given config context and return true if it contains string 'true',
- * false otherwise.
+ * Parse config statement.
*
* @param ctx
* config context to parse.
* @return true if given context contains string 'true', false otherwise
*/
- public static boolean parseConfig(final Config_stmtContext ctx) {
- boolean result = false;
+ private static Boolean parseConfig(final Config_stmtContext ctx) {
+ Boolean result = null;
if (ctx != null) {
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree configContext = ctx.getChild(i);
if ("true".equals(value)) {
result = true;
break;
+ } else if ("false".equals(value)) {
+ result = false;
+ break;
+ } else {
+ throw new YangParseException(ctx.getStart().getLine(),
+ "Failed to parse 'config' statement value: '" + value + "'.");
}
}
}
}
/**
- * Parse given type body and creates UnknownType definition.
+ * Parse type body and create UnknownType definition.
*
* @param typedefQName
* qname of current type
* @param ctx
* type body
+ * @param actualPath
+ * @param namespace
+ * @param revision
+ * @param prefix
+ * @param parent
* @return UnknownType object with constraints from parsed type body
*/
- public static TypeDefinition<?> parseUnknownTypeBody(QName typedefQName, Type_body_stmtsContext ctx,
- final List<String> actualPath, final URI namespace, final Date revision, final String prefix,
- Builder parent, ModuleBuilder moduleBuilder) {
+ public static TypeDefinition<?> parseUnknownTypeWithBody(final QName typedefQName,
+ final Type_body_stmtsContext ctx, final List<String> actualPath, final URI namespace, final Date revision,
+ final String prefix, final Builder parent) {
String typeName = typedefQName.getLocalName();
UnknownType.Builder unknownType = new UnknownType.Builder(typedefQName);
/**
* Create TypeDefinition object based on given type name and type body.
*
+ * @param moduleName
+ * current module name
* @param typeName
* name of type
* @param typeBody
- * type body
+ * type body context
* @param actualPath
* current path in schema
* @param namespace
* current revision
* @param prefix
* current prefix
+ * @param parent
+ * parent builder
* @return TypeDefinition object based on parsed values.
*/
- public static TypeDefinition<?> parseTypeBody(final String moduleName, final String typeName,
+ public static TypeDefinition<?> parseTypeWithBody(final String moduleName, final String typeName,
final Type_body_stmtsContext typeBody, final List<String> actualPath, final URI namespace,
- final Date revision, final String prefix, Builder parent) {
+ final Date revision, final String prefix, final Builder parent) {
TypeDefinition<?> baseType = null;
- List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
Integer fractionDigits = getFractionDigits(typeBody);
List<LengthConstraint> lengthStatements = getLengthConstraints(typeBody);
List<PatternConstraint> patternStatements = getPatternConstraint(typeBody);
- List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(typeBody, actualPath, namespace, revision,
- prefix);
+ List<RangeConstraint> rangeStatements = getRangeConstraints(typeBody);
TypeConstraints constraints = new TypeConstraints(moduleName, typeBody.getStart().getLine());
constraints.addFractionDigits(fractionDigits);
constraints.addRanges(uintType.getRangeStatements());
baseType = uintType;
} else if ("enumeration".equals(typeName)) {
+ List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(typeBody, actualPath, namespace,
+ revision, prefix);
return new EnumerationType(baseTypePathFinal, enumConstants);
} else if ("string".equals(typeName)) {
StringTypeDefinition stringType = new StringType(baseTypePath);
}
/**
- * Parse given context and find require-instance value.
+ * Parse type body statement and find require-instance value.
*
* @param ctx
- * type body
+ * type body context
* @return require-instance value
*/
private static boolean isRequireInstance(Type_body_stmtsContext ctx) {
}
/**
- * Parse given context and find leafref path.
+ * Parse type body statement and find leafref path.
*
* @param ctx
- * type body
+ * type body context
* @return leafref path as String
*/
private static String parseLeafrefPath(Type_body_stmtsContext ctx) {
}
/**
- * Internal helper method for parsing Must_stmtContext.
+ * Internal helper method for parsing must statement.
*
* @param ctx
* Must_stmtContext
}
/**
- * Parse given tree and set constraints to given builder.
+ * Parse given context and set constraints to constraints builder.
*
* @param ctx
- * context to search
+ * context to parse
* @param constraints
* ConstraintsBuilder to fill
*/
String reference = stringFromNode(refineArg);
refine.setReference(reference);
} else if (refineArg instanceof Config_stmtContext) {
- boolean config = parseConfig((Config_stmtContext) refineArg);
- refine.setConfig(config);
+ Boolean config = parseConfig((Config_stmtContext) refineArg);
+ refine.setConfiguration(config);
}
}
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.FileNotFoundException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.MustDefinition;
+import org.opendaylight.controller.yang.model.api.SchemaNode;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.api.UsesNode;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
+
+public class GroupingTest {
+ private Set<Module> modules;
+
+ @Before
+ public void init() throws FileNotFoundException {
+ modules = TestUtils.loadModules(getClass().getResource("/model").getPath());
+ assertEquals(3, modules.size());
+ }
+
+ @Test
+ public void testRefine() {
+ Module testModule = TestUtils.findModule(modules, "types2");
+
+ ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
+ ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
+ Set<UsesNode> usesNodes = destination.getUses();
+ assertEquals(1, usesNodes.size());
+ UsesNode usesNode = usesNodes.iterator().next();
+ Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
+ assertEquals(5, refines.size());
+
+ LeafSchemaNode refineLeaf = null;
+ ContainerSchemaNode refineContainer = null;
+ ListSchemaNode refineList = null;
+ GroupingDefinition refineGrouping = null;
+ TypeDefinition<?> typedef = null;
+ for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
+ SchemaNode value = entry.getValue();
+ if (value instanceof LeafSchemaNode) {
+ refineLeaf = (LeafSchemaNode) value;
+ } else if (value instanceof ContainerSchemaNode) {
+ refineContainer = (ContainerSchemaNode) value;
+ } else if (value instanceof ListSchemaNode) {
+ refineList = (ListSchemaNode) value;
+ } else if (value instanceof GroupingDefinition) {
+ refineGrouping = (GroupingDefinition) value;
+ } else if (value instanceof TypeDefinition<?>) {
+ typedef = (TypeDefinition<?>) value;
+ }
+ }
+
+ // leaf address
+ assertNotNull(refineLeaf);
+ assertEquals("address", refineLeaf.getQName().getLocalName());
+ assertEquals("IP address of target node", refineLeaf.getDescription());
+ assertEquals("address reference added by refine", refineLeaf.getReference());
+ assertFalse(refineLeaf.isConfiguration());
+ assertTrue(refineLeaf.getConstraints().isMandatory());
+ Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
+ assertEquals(1, leafMustConstraints.size());
+ MustDefinition leafMust = leafMustConstraints.iterator().next();
+ assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString());
+
+ // container port
+ assertNotNull(refineContainer);
+ Set<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
+ assertTrue(mustConstraints.isEmpty());
+ assertEquals("description of port defined by refine", refineContainer.getDescription());
+ assertEquals("port reference added by refine", refineContainer.getReference());
+ assertFalse(refineContainer.isConfiguration());
+ assertTrue(refineContainer.isPresenceContainer());
+
+ // list addresses
+ assertNotNull(refineList);
+ assertEquals("description of addresses defined by refine", refineList.getDescription());
+ assertEquals("addresses reference added by refine", refineList.getReference());
+ assertFalse(refineList.isConfiguration());
+ assertEquals(2, (int) refineList.getConstraints().getMinElements());
+ assertEquals(12, (int) refineList.getConstraints().getMaxElements());
+
+ // grouping target-inner
+ assertNotNull(refineGrouping);
+ Set<DataSchemaNode> refineGroupingChildren = refineGrouping.getChildNodes();
+ assertEquals(1, refineGroupingChildren.size());
+ LeafSchemaNode refineGroupingLeaf = (LeafSchemaNode) refineGroupingChildren.iterator().next();
+ assertEquals("inner-grouping-id", refineGroupingLeaf.getQName().getLocalName());
+ assertEquals("new target-inner grouping description", refineGrouping.getDescription());
+
+ // typedef group-type
+ assertNotNull(typedef);
+ assertEquals("new group-type description", typedef.getDescription());
+ assertEquals("new group-type reference", typedef.getReference());
+ assertTrue(typedef.getBaseType() instanceof ExtendedType);
+ }
+
+ @Test
+ public void testGrouping() {
+ Module testModule = TestUtils.findModule(modules, "types2");
+ Set<GroupingDefinition> groupings = testModule.getGroupings();
+ assertEquals(1, groupings.size());
+ GroupingDefinition grouping = groupings.iterator().next();
+ Set<DataSchemaNode> children = grouping.getChildNodes();
+ assertEquals(5, children.size());
+ }
+
+ @Test
+ public void testUses() {
+ // suffix _u = added by uses
+ // suffix _g = defined in grouping
+
+ Module testModule = TestUtils.findModule(modules, "types2");
+
+ // get grouping
+ Set<GroupingDefinition> groupings = testModule.getGroupings();
+ assertEquals(1, groupings.size());
+ GroupingDefinition grouping = groupings.iterator().next();
+
+ // get node containing uses
+ ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
+ ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
+
+ // check uses
+ Set<UsesNode> uses = destination.getUses();
+ assertEquals(1, uses.size());
+
+ // check uses process
+ AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) destination.getDataChildByName("data");
+ assertNotNull(data_u);
+ assertTrue(data_u.isAddedByUses());
+
+ AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping.getDataChildByName("data");
+ assertNotNull(data_g);
+ assertFalse(data_g.isAddedByUses());
+ assertFalse(data_u.equals(data_g));
+
+ ChoiceNode how_u = (ChoiceNode) destination.getDataChildByName("how");
+ assertNotNull(how_u);
+ assertTrue(how_u.isAddedByUses());
+
+ ChoiceNode how_g = (ChoiceNode) grouping.getDataChildByName("how");
+ assertNotNull(how_g);
+ assertFalse(how_g.isAddedByUses());
+ assertFalse(how_u.equals(how_g));
+
+ LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName("address");
+ assertNotNull(address_u);
+ assertEquals("1.2.3.4", address_u.getDefault());
+ assertEquals("IP address of target node", address_u.getDescription());
+ assertEquals("address reference added by refine", address_u.getReference());
+ assertFalse(address_u.isConfiguration());
+ assertTrue(address_u.isAddedByUses());
+
+ LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName("address");
+ assertNotNull(address_g);
+ assertFalse(address_g.isAddedByUses());
+ assertNull(address_g.getDefault());
+ assertEquals("Target IP address", address_g.getDescription());
+ assertNull(address_g.getReference());
+ assertTrue(address_g.isConfiguration());
+ assertFalse(address_u.equals(address_g));
+
+ ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName("port");
+ assertNotNull(port_u);
+ assertTrue(port_u.isAddedByUses());
+
+ ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName("port");
+ assertNotNull(port_g);
+ assertFalse(port_g.isAddedByUses());
+ assertFalse(port_u.equals(port_g));
+
+ ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName("addresses");
+ assertNotNull(addresses_u);
+ assertTrue(addresses_u.isAddedByUses());
+
+ ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName("addresses");
+ assertNotNull(addresses_g);
+ assertFalse(addresses_g.isAddedByUses());
+ assertFalse(addresses_u.equals(addresses_g));
+
+ // grouping defined by 'uses'
+ Set<GroupingDefinition> groupings_u = destination.getGroupings();
+ assertEquals(1, groupings_u.size());
+ GroupingDefinition grouping_u = groupings_u.iterator().next();
+ assertTrue(grouping_u.isAddedByUses());
+
+ // grouping defined in 'grouping' node
+ Set<GroupingDefinition> groupings_g = grouping.getGroupings();
+ assertEquals(1, groupings_g.size());
+ GroupingDefinition grouping_g = groupings_g.iterator().next();
+ assertFalse(grouping_g.isAddedByUses());
+ assertFalse(grouping_u.equals(grouping_g));
+
+ List<UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
+ assertEquals(1, nodes_u.size());
+ UnknownSchemaNode node_u = nodes_u.get(0);
+ assertTrue(node_u.isAddedByUses());
+
+ List<UnknownSchemaNode> nodes_g = grouping.getUnknownSchemaNodes();
+ assertEquals(1, nodes_g.size());
+ UnknownSchemaNode node_g = nodes_g.get(0);
+ assertFalse(node_g.isAddedByUses());
+ assertFalse(node_u.equals(node_g));
+ }
+
+}
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.junit.Before;
import org.opendaylight.controller.yang.model.api.ChoiceNode;
import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.controller.yang.model.api.DataSchemaNode;
import org.opendaylight.controller.yang.model.api.Deviation;
import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
import org.opendaylight.controller.yang.model.api.FeatureDefinition;
-import org.opendaylight.controller.yang.model.api.GroupingDefinition;
import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
import org.opendaylight.controller.yang.model.api.ListSchemaNode;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.api.ModuleImport;
-import org.opendaylight.controller.yang.model.api.MustDefinition;
import org.opendaylight.controller.yang.model.api.NotificationDefinition;
import org.opendaylight.controller.yang.model.api.RpcDefinition;
-import org.opendaylight.controller.yang.model.api.SchemaNode;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
public class YangParserTest {
private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-
private Set<Module> modules;
@Before
assertEquals(0, interfaces.getUnknownSchemaNodes().size());
// test DataSchemaNode args
assertFalse(interfaces.isAugmenting());
- assertFalse(interfaces.isConfiguration());
+ assertTrue(interfaces.isConfiguration());
ConstraintDefinition constraints = interfaces.getConstraints();
assertNull(constraints.getWhenCondition());
assertEquals(0, constraints.getMustConstraints().size());
assertEquals(0, ifEntry.getUnknownSchemaNodes().size());
// test DataSchemaNode args
assertFalse(ifEntry.isAugmenting());
- assertFalse(ifEntry.isConfiguration());
+ assertTrue(ifEntry.isConfiguration());
ConstraintDefinition constraints = ifEntry.getConstraints();
assertNull(constraints.getWhenCondition());
assertEquals(0, constraints.getMustConstraints().size());
assertEquals(100L, range.getMax());
}
- @Test
- public void testRefine() {
- Module testModule = TestUtils.findModule(modules, "types2");
-
- ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
- ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
- Set<UsesNode> usesNodes = destination.getUses();
- assertEquals(1, usesNodes.size());
- UsesNode usesNode = usesNodes.iterator().next();
- Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
- assertEquals(5, refines.size());
-
- LeafSchemaNode refineLeaf = null;
- ContainerSchemaNode refineContainer = null;
- ListSchemaNode refineList = null;
- GroupingDefinition refineGrouping = null;
- TypeDefinition<?> typedef = null;
- for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
- SchemaNode value = entry.getValue();
- if (value instanceof LeafSchemaNode) {
- refineLeaf = (LeafSchemaNode) value;
- } else if (value instanceof ContainerSchemaNode) {
- refineContainer = (ContainerSchemaNode) value;
- } else if (value instanceof ListSchemaNode) {
- refineList = (ListSchemaNode) value;
- } else if (value instanceof GroupingDefinition) {
- refineGrouping = (GroupingDefinition) value;
- } else if (value instanceof TypeDefinition<?>) {
- typedef = (TypeDefinition<?>) value;
- }
- }
-
- // leaf address
- assertNotNull(refineLeaf);
- assertEquals("address", refineLeaf.getQName().getLocalName());
- assertEquals("description of address defined by refine", refineLeaf.getDescription());
- assertEquals("address reference added by refine", refineLeaf.getReference());
- assertFalse(refineLeaf.isConfiguration());
- assertTrue(refineLeaf.getConstraints().isMandatory());
- Set<MustDefinition> leafMustConstraints = refineLeaf.getConstraints().getMustConstraints();
- assertEquals(1, leafMustConstraints.size());
- MustDefinition leafMust = leafMustConstraints.iterator().next();
- assertEquals("\"ifType != 'ethernet' or (ifType = 'ethernet' and ifMTU = 1500)\"", leafMust.toString());
-
- // container port
- assertNotNull(refineContainer);
- Set<MustDefinition> mustConstraints = refineContainer.getConstraints().getMustConstraints();
- assertTrue(mustConstraints.isEmpty());
- assertEquals("description of port defined by refine", refineContainer.getDescription());
- assertEquals("port reference added by refine", refineContainer.getReference());
- assertFalse(refineContainer.isConfiguration());
- assertTrue(refineContainer.isPresenceContainer());
-
- // list addresses
- assertNotNull(refineList);
- assertEquals("description of addresses defined by refine", refineList.getDescription());
- assertEquals("addresses reference added by refine", refineList.getReference());
- assertFalse(refineList.isConfiguration());
- assertEquals(2, (int) refineList.getConstraints().getMinElements());
- assertEquals(12, (int) refineList.getConstraints().getMaxElements());
-
- // grouping target-inner
- assertNotNull(refineGrouping);
- Set<DataSchemaNode> refineGroupingChildren = refineGrouping.getChildNodes();
- assertEquals(1, refineGroupingChildren.size());
- LeafSchemaNode refineGroupingLeaf = (LeafSchemaNode) refineGroupingChildren.iterator().next();
- assertEquals("inner-grouping-id", refineGroupingLeaf.getQName().getLocalName());
- assertEquals("new target-inner grouping description", refineGrouping.getDescription());
-
- // typedef group-type
- assertNotNull(typedef);
- assertEquals("new group-type description", typedef.getDescription());
- assertEquals("new group-type reference", typedef.getReference());
- assertTrue(typedef.getBaseType() instanceof ExtendedType);
- }
-
@Test
public void testChoice() {
Module testModule = TestUtils.findModule(modules, "types1");
ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
ChoiceNode how = (ChoiceNode) peer.getDataChildByName("how");
Set<ChoiceCaseNode> cases = how.getCases();
- assertEquals(3, cases.size());
+ assertEquals(5, cases.size());
+ ChoiceCaseNode input = null;
+ ChoiceCaseNode output = null;
+ for(ChoiceCaseNode caseNode : cases) {
+ if("input".equals(caseNode.getQName().getLocalName())) {
+ input = caseNode;
+ } else if("output".equals(caseNode.getQName().getLocalName())) {
+ output = caseNode;
+ }
+ }
+ assertNotNull(input);
+ assertNotNull(input.getPath());
+ assertNotNull(output);
+ assertNotNull(output.getPath());
}
@Test
assertNotNull(output.getDataChildByName("data"));
}
- @Test
- public void testGrouping() {
- Module testModule = TestUtils.findModule(modules, "types2");
- Set<GroupingDefinition> groupings = testModule.getGroupings();
- assertEquals(1, groupings.size());
- GroupingDefinition grouping = groupings.iterator().next();
- Set<DataSchemaNode> children = grouping.getChildNodes();
- assertEquals(5, children.size());
- }
-
@Test
public void testAugmentNodesTypesSchemaPath() throws Exception {
Module testModule = TestUtils.findModule(modules, "types1");
import org.junit.Test;
import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
import org.opendaylight.controller.yang.model.api.DataSchemaNode;
import org.opendaylight.controller.yang.model.api.GroupingDefinition;
RangeConstraint range = ranges.get(0);
assertEquals(0L, range.getMin());
assertEquals(63L, range.getMax());
+ }
+ @Test
+ public void testUsesFromContext() throws Exception {
+ SchemaContext context = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/model/testfile2.yang").getPath())) {
+ context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+ }
+ Module testModule = null;
+ try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) {
+ testModule = TestUtils.loadModuleWithContext(stream, context);
+ }
+ assertNotNull(testModule);
+
+ // suffix _u = added by uses
+ // suffix _g = defined in grouping from context
+
+ // get grouping
+ Module contextModule = context.findModuleByNamespace(URI.create("urn:simple.types.data.demo"));
+ assertNotNull(contextModule);
+ Set<GroupingDefinition> groupings = contextModule.getGroupings();
+ assertEquals(1, groupings.size());
+ GroupingDefinition grouping = groupings.iterator().next();
+
+ // get node containing uses
+ ContainerSchemaNode peer = (ContainerSchemaNode)testModule.getDataChildByName("peer");
+ ContainerSchemaNode destination = (ContainerSchemaNode)peer.getDataChildByName("destination");
+
+ // check uses
+ Set<UsesNode> uses = destination.getUses();
+ assertEquals(1, uses.size());
+
+ // check uses process
+ AnyXmlSchemaNode data_u = (AnyXmlSchemaNode)destination.getDataChildByName("data");
+ assertNotNull(data_u);
+ assertTrue(data_u.isAddedByUses());
+
+ AnyXmlSchemaNode data_g = (AnyXmlSchemaNode)grouping.getDataChildByName("data");
+ assertNotNull(data_g);
+ assertFalse(data_g.isAddedByUses());
+ assertFalse(data_u.equals(data_g));
+
+ ChoiceNode how_u = (ChoiceNode)destination.getDataChildByName("how");
+ assertNotNull(how_u);
+ assertTrue(how_u.isAddedByUses());
+
+ ChoiceNode how_g = (ChoiceNode)grouping.getDataChildByName("how");
+ assertNotNull(how_g);
+ assertFalse(how_g.isAddedByUses());
+ assertFalse(how_u.equals(how_g));
+
+ LeafSchemaNode address_u = (LeafSchemaNode)destination.getDataChildByName("address");
+ assertNotNull(address_u);
+ assertTrue(address_u.isAddedByUses());
+
+ LeafSchemaNode address_g = (LeafSchemaNode)grouping.getDataChildByName("address");
+ assertNotNull(address_g);
+ assertFalse(address_g.isAddedByUses());
+ assertFalse(address_u.equals(address_g));
+
+ ContainerSchemaNode port_u = (ContainerSchemaNode)destination.getDataChildByName("port");
+ assertNotNull(port_u);
+ assertTrue(port_u.isAddedByUses());
+
+ ContainerSchemaNode port_g = (ContainerSchemaNode)grouping.getDataChildByName("port");
+ assertNotNull(port_g);
+ assertFalse(port_g.isAddedByUses());
+ assertFalse(port_u.equals(port_g));
+
+ ListSchemaNode addresses_u = (ListSchemaNode)destination.getDataChildByName("addresses");
+ assertNotNull(addresses_u);
+ assertTrue(addresses_u.isAddedByUses());
+
+ ListSchemaNode addresses_g = (ListSchemaNode)grouping.getDataChildByName("addresses");
+ assertNotNull(addresses_g);
+ assertFalse(addresses_g.isAddedByUses());
+ assertFalse(addresses_u.equals(addresses_g));
+
+ // grouping defined by 'uses'
+ Set<GroupingDefinition> groupings_u = destination.getGroupings();
+ assertEquals(1, groupings_u.size());
+ GroupingDefinition grouping_u = groupings_u.iterator().next();
+ assertTrue(grouping_u.isAddedByUses());
+
+ // grouping defined in 'grouping' node
+ Set<GroupingDefinition> groupings_g = grouping.getGroupings();
+ assertEquals(1, groupings_g.size());
+ GroupingDefinition grouping_g = groupings_g.iterator().next();
+ assertFalse(grouping_g.isAddedByUses());
+ assertFalse(grouping_u.equals(grouping_g));
+
+ List<UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
+ assertEquals(1, nodes_u.size());
+ UnknownSchemaNode node_u = nodes_u.get(0);
+ assertTrue(node_u.isAddedByUses());
+
+ List<UnknownSchemaNode> nodes_g = grouping.getUnknownSchemaNodes();
+ assertEquals(1, nodes_g.size());
+ UnknownSchemaNode node_g = nodes_g.get(0);
+ assertFalse(node_g.isAddedByUses());
+ assertFalse(node_u.equals(node_g));
}
@Test
- public void testUsesGroupingFromContext() throws Exception {
+ public void testUsesRefineFromContext() throws Exception {
SchemaContext context = null;
try (InputStream stream = new FileInputStream(getClass().getResource("/model/testfile2.yang").getPath())) {
context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
container transfer {
choice how {
default interval;
+ container input {
+ }
+ list output {
+ leaf id {
+ type string;
+ }
+ }
case interval {
leaf interval {
type uint16;
revision "2013-02-27" {
reference " WILL BE DEFINED LATER";
}
-
+
typedef my-base-int32-type {
type int32 {
range "2..20";
units "mile";
default "11";
}
-
+
typedef my-custom-string {
type string {
pattern "[a-k]*";
length "5..11";
}
}
-
+
typedef my-string-type {
type my-custom-string {
length "6..10";
range "10..20";
}
}
-
+
typedef my-int-type2 {
type my-int-type {
range "12..18";
}
}
-
+
typedef my-int-type-ext {
type my-int-type2 {
range "14..16";
}
}
-
+
typedef my-decimal-type {
type decimal64 {
fraction-digits 6;
}
}
-
+
typedef my-decimal-type-ext {
type decimal64 {
fraction-digits 5;
path "/interface/name";
}
}
-
+
leaf name {
type string;
}
-
+
leaf count {
type int8 {
range "1..10";
}
}
-
+
leaf nested-type-leaf {
type my-type1;
}
-
+
extension c-define {
description
"Takes as argument a name string.
yin-element "true";
}
}
-
+
container system {
leaf user {
type string;
}
}
-
+
grouping target {
anyxml data {
config true;
typedef group-type {
type my-decimal-type;
}
+
+ opendaylight;
}
container peer {
uses target {
refine address {
default "1.2.3.4";
- description "description of address defined by refine";
+ description "IP address of target node";
reference "address reference added by refine";
config false;
mandatory true;
}
}
}
-
+
container interfaces {
list ifEntry {
key "ifIndex";
type uint32;
units minutes;
}
-
+
leaf ifMtu {
type int32;
}
-
+
min-elements 1;
max-elements 11;
}
--- /dev/null
+package org.opendaylight.controller.yang.binding;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: lsedlak
+ * Date: 27.6.2013
+ * Time: 11:44
+ * To change this template use File | Settings | File Templates.
+ */
+public class InstanceIdentifier <T extends DataObject> {
+
+}
/**\r
* Returns <code>true</code> if the data node was added by augmentation,\r
* otherwise returns <code>false</code>\r
- * \r
+ *\r
* @return <code>true</code> if the data node was added by augmentation,\r
* otherwise returns <code>false</code>\r
*/\r
boolean isAugmenting();\r
\r
+ /**\r
+ * Returns <code>true</code> if the data node was added by uses statement,\r
+ * otherwise returns <code>false</code>\r
+ *\r
+ * @return <code>true</code> if the data node was added by uses statement,\r
+ * otherwise returns <code>false</code>\r
+ */\r
+ boolean isAddedByUses();\r
+\r
/**\r
* Returns <code>true</code> if the data represents configuration data,\r
* otherwise returns <code>false</code>\r
- * \r
+ *\r
* @return <code>true</code> if the data represents configuration data,\r
* otherwise returns <code>false</code>\r
*/\r
\r
/**\r
* Returns the constraints associated with Data Schema Node\r
- * \r
+ *\r
* @return the constraints associated with Data Schema Node\r
*/\r
ConstraintDefinition getConstraints();\r
*/\r
public interface GroupingDefinition extends DataNodeContainer, SchemaNode {\r
\r
+ boolean isAddedByUses();\r
+\r
}\r
public interface UnknownSchemaNode extends SchemaNode {
QName getNodeType();
+
String getNodeParameter();
+ boolean isAddedByUses();
+
}
*/\r
boolean isAugmenting();\r
\r
+ boolean isAddedByUses();\r
+\r
/**\r
* Some of the properties of each node in the grouping can be refined with\r
* the "refine" statement.\r
private Status status;
private String units;
private Object defaultValue;
+ private boolean addedByUses;
public static class Builder {
private final QName typeName;
private Status status = Status.CURRENT;
private String units = "";
private Object defaultValue = null;
+ private boolean addedByUses;
private List<RangeConstraint> ranges = Collections.emptyList();
private List<LengthConstraint> lengths = Collections.emptyList();
return this;
}
+ public Builder addedByUses(final boolean addedByUses) {
+ this.addedByUses = addedByUses;
+ return this;
+ }
+
public Builder unknownSchemaNodes(
final List<UnknownSchemaNode> unknownSchemaNodes) {
this.unknownSchemaNodes = unknownSchemaNodes;
this.status = builder.status;
this.units = builder.units;
this.defaultValue = builder.defaultValue;
+ this.addedByUses = builder.addedByUses;
this.ranges = builder.ranges;
this.lengths = builder.lengths;
return defaultValue;
}
+ public boolean isAddedByUses() {
+ return addedByUses;
+ }
+
@Override
public QName getQName() {
return typeName;
/*
- * 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.controller.yang.model.util;
import java.util.Collections;
import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition;
/**
- * The <code>default</code> implementation of Instance Identifier Type Definition interface.
+ * 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 String description = "The instance-identifier built-in type is used to " +
- "uniquely identify a particular instance node in the data tree.";
+ private static final QName name = BaseTypes.constructQName("instance-identifier");
+ 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 final transient SchemaPath path;
private final RevisionAwareXPath xpath;
private final String units = "";
private final InstanceIdentifierTypeDefinition baseType;
- private final boolean requireInstance;
+ private boolean requireInstance = true;
+
+ public InstanceIdentifier(final SchemaPath path, final RevisionAwareXPath xpath) {
+ super();
+ this.path = path;
+ this.xpath = xpath;
+ this.baseType = this;
+ }
- public InstanceIdentifier(final SchemaPath path, RevisionAwareXPath xpath, boolean requireInstance) {
+ public InstanceIdentifier(final SchemaPath path, final RevisionAwareXPath xpath, final boolean requireInstance) {
super();
this.path = path;
this.xpath = xpath;
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
+ * @see
+ * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
*/
@Override
public InstanceIdentifierTypeDefinition getBaseType() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+ * @see
+ * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+ * ()
*/
@Override
public Object getDefaultValue() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
+ * @see
+ * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
*/
@Override
public String getDescription() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes()
+ * @see
+ * org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes
+ * ()
*/
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
- * getPathStatement()
+ * @see org.opendaylight.controller.yang.model.api.type.
+ * InstanceIdentifierTypeDefinition# getPathStatement()
*/
@Override
public RevisionAwareXPath getPathStatement() {
/*
* (non-Javadoc)
*
- * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
- * requireInstance()
+ * @see org.opendaylight.controller.yang.model.api.type.
+ * InstanceIdentifierTypeDefinition# requireInstance()
*/
@Override
public boolean requireInstance() {
org.slf4j,
org.apache.felix.dm
</Import-Package>
+ <Export-Package>
+ org.opendaylight.controller.sample.simpleforwarding
+ </Export-Package>
<Bundle-Activator>
org.opendaylight.controller.samples.simpleforwarding.internal.Activator
</Bundle-Activator>
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.controller.samples.simpleforwarding.internal;
+package org.opendaylight.controller.samples.simpleforwarding;
import java.io.Serializable;
import org.opendaylight.controller.sal.utils.EtherTypes;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.samples.simpleforwarding.HostNodePair;
import org.opendaylight.controller.switchmanager.IInventoryListener;
import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.opendaylight.controller.topologymanager.ITopologyManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+
public class SimpleForwardingImpl implements IfNewHostNotify,
IListenRoutingUpdates, IInventoryListener {
private static Logger log = LoggerFactory
import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
import org.opendaylight.controller.sal.core.ConstructionException;
import org.opendaylight.controller.sal.utils.NodeCreator;
-import org.opendaylight.controller.samples.simpleforwarding.internal.HostNodePair;
+import org.opendaylight.controller.samples.simpleforwarding.HostNodePair;
+
public class HostSwitchTest {
@Test
public boolean matchNode(String nodeId) {
return this.nodeId.equals(nodeId);
}
+
+ @Override
+ public String toString() {
+ return ("Span Config [nodeId=" + nodeId + " spanPort=" + spanPort + "]");
+ }
}
nodePorts.remove(sp);
}
+ @Override
public String toString() {
return ("Subnet Config [Description=" + name + " Subnet=" + subnet
+ " NodeConnectors=" + nodePorts + "]");
return false;
return true;
}
+
+ @Override
+ public String toString() {
+ return ("Switch Config [Node=" + nodeId + " Description=" + description +
+ " Tier=" + tier + " Mode=" + mode + "]");
+ }
}
import org.opendaylight.controller.sal.core.UpdateType;
import org.opendaylight.controller.sal.inventory.IInventoryService;
import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
-import org.opendaylight.controller.sal.utils.HexEncode;
-import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.sal.utils.GlobalConstants;
+import org.opendaylight.controller.sal.utils.HexEncode;
import org.opendaylight.controller.sal.utils.IObjectReader;
import org.opendaylight.controller.sal.utils.ObjectReader;
import org.opendaylight.controller.sal.utils.ObjectWriter;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.sal.utils.StatusCode;
import org.opendaylight.controller.switchmanager.IInventoryListener;
import org.opendaylight.controller.switchmanager.ISpanAware;
import org.opendaylight.controller.switchmanager.ISwitchManager;
public void startUp() {
// Initialize configuration file names
- subnetFileName = ROOT + "subnets" + this.getContainerName() + ".conf";
+ subnetFileName = ROOT + "subnets_" + this.getContainerName() + ".conf";
spanFileName = ROOT + "spanPorts_" + this.getContainerName() + ".conf";
switchConfigFileName = ROOT + "switchConfig_" + this.getContainerName()
+ ".conf";
}
public void shutDown() {
- destroyCaches(this.getContainerName());
}
@SuppressWarnings("deprecation")
}
conf.addNodeConnectors(switchPorts);
+ subnetsConfigList.put(name, conf);
// Update Database
Subnet sub = subnets.get(conf.getIPnum());
Set<NodeConnector> sp = conf.getNodeConnectors(switchPorts);
sub.addNodeConnectors(sp);
+ subnets.put(conf.getIPnum(), sub);
return new Status(StatusCode.SUCCESS, null);
}
return new Status(StatusCode.NOTFOUND, "Subnet does not exist");
}
conf.removeNodeConnectors(switchPorts);
+ subnetsConfigList.put(name, conf);
// Update Database
Subnet sub = subnets.get(conf.getIPnum());
Set<NodeConnector> sp = conf.getNodeConnectors(switchPorts);
sub.deleteNodeConnectors(sp);
+ subnets.put(conf.getIPnum(), sub);
return new Status(StatusCode.SUCCESS, null);
}
@SuppressWarnings("unchecked")
private void loadSubnetConfiguration() {
ObjectReader objReader = new ObjectReader();
- ConcurrentMap<Integer, SubnetConfig> confList = (ConcurrentMap<Integer, SubnetConfig>) objReader
+ ConcurrentMap<String, SubnetConfig> confList = (ConcurrentMap<String, SubnetConfig>) objReader
.read(this, subnetFileName);
if (confList == null) {
@Override
public void updateSwitchConfig(SwitchConfig cfgObject) {
+ // update default container only
+ if (!isDefaultContainer) {
+ return;
+ }
+
boolean modeChange = false;
SwitchConfig sc = nodeConfigList.get(cfgObject.getNodeId());
nodeConfigList.put(cfgObject.getNodeId(), cfgObject);
try {
- // update default container only
- if (isDefaultContainer) {
- String nodeId = cfgObject.getNodeId();
- Node node = Node.fromString(nodeId);
- Map<String, Property> propMap;
- if (nodeProps.get(node) != null) {
- propMap = nodeProps.get(node);
- } else {
- propMap = new HashMap<String, Property>();
- }
- Property desc = new Description(cfgObject.getNodeDescription());
- propMap.put(desc.getName(), desc);
- Property tier = new Tier(Integer.parseInt(cfgObject.getTier()));
- propMap.put(tier.getName(), tier);
- addNodeProps(node, propMap);
+ String nodeId = cfgObject.getNodeId();
+ Node node = Node.fromString(nodeId);
+ Map<String, Property> propMap;
+ if (nodeProps.get(node) != null) {
+ propMap = nodeProps.get(node);
+ } else {
+ propMap = new HashMap<String, Property>();
+ }
+ Property desc = new Description(cfgObject.getNodeDescription());
+ propMap.put(desc.getName(), desc);
+ Property tier = new Tier(Integer.parseInt(cfgObject.getTier()));
+ propMap.put(tier.getName(), tier);
+ addNodeProps(node, propMap);
- log.info("Set Node {}'s Mode to {}", nodeId,
- cfgObject.getMode());
+ log.info("Set Node {}'s Mode to {}", nodeId,
+ cfgObject.getMode());
- if (modeChange) {
- notifyModeChange(node, cfgObject.isProactive());
- }
+ if (modeChange) {
+ notifyModeChange(node, cfgObject.isProactive());
}
} catch (Exception e) {
log.debug("updateSwitchConfig: {}", e.getMessage());
addNodeProps(node, null);
}
- // check if span is configed
addSpanPort(nodeConnector);
break;
case REMOVED:
return;
}
- nodeProps = this.inventoryService.getNodeProps();
- Set<Node> nodeSet = nodeProps.keySet();
- if (nodeSet != null) {
- for (Node node : nodeSet) {
- log.debug("getInventories: {} added for container {}",
- new Object[] { node, containerName });
- addNode(node, null);
+ Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
+ for(Map.Entry<Node, Map<String, Property>> entry : nodeProp.entrySet()) {
+ Node node = entry.getKey();
+ log.debug("getInventories: {} added for container {}",
+ new Object[] { node, containerName });
+ Map<String, Property> propMap = entry.getValue();
+ Set<Property> props = new HashSet<Property>();
+ for(Property property : propMap.values()) {
+ props.add(property);
}
+ addNode(node, props);
}
- nodeConnectorProps = inventoryService.getNodeConnectorProps();
+ Map<NodeConnector, Map<String, Property>> nodeConnectorProp = this.inventoryService.getNodeConnectorProps();
+ for(Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProp.entrySet()) {
+ Map<String, Property> propMap = entry.getValue();
+ for(Property property : propMap.values()) {
+ addNodeConnectorProp(entry.getKey(), property);
+ }
+ }
}
private void clearInventories() {
/*
* Add span configuration to local cache and notify clients
*/
- private void addSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
+ private void addSpanPorts(Node node, List<NodeConnector> nodeConnectors) {
List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConncetors) {
+ for (NodeConnector nodeConnector : nodeConnectors) {
if (!spanNodeConnectors.contains(nodeConnector)) {
ncLists.add(nodeConnector);
}
}
}
- private void addSpanPort(NodeConnector nodeConncetor) {
- List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
- ncLists.add(nodeConncetor);
- addSpanPorts(nodeConncetor.getNode(), ncLists);
+ private void addSpanPort(NodeConnector nodeConnector) {
+ // only add if span is configured on this nodeConnector
+ for (SpanConfig conf : getSpanConfigList(nodeConnector.getNode())) {
+ if (conf.getPortArrayList().contains(nodeConnector)) {
+ List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
+ ncLists.add(nodeConnector);
+ addSpanPorts(nodeConnector.getNode(), ncLists);
+ return;
+ }
+ }
}
/*
* Remove span configuration to local cache and notify clients
*/
- private void removeSpanPorts(Node node, List<NodeConnector> nodeConncetors) {
+ private void removeSpanPorts(Node node, List<NodeConnector> nodeConnectors) {
List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConncetors) {
+ for (NodeConnector nodeConnector : nodeConnectors) {
if (spanNodeConnectors.contains(nodeConnector)) {
ncLists.add(nodeConnector);
}
}
}
- private void removeSpanPort(NodeConnector nodeConncetor) {
- List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
- ncLists.add(nodeConncetor);
- removeSpanPorts(nodeConncetor.getNode(), ncLists);
+ private void removeSpanPort(NodeConnector nodeConnector) {
+ if (spanNodeConnectors.contains(nodeConnector)) {
+ List<NodeConnector> ncLists = new ArrayList<NodeConnector>();
+ ncLists.add(nodeConnector);
+ removeSpanPorts(nodeConnector.getNode(), ncLists);
+ }
}
private void addNodeProps(Node node, Map<String, Property> propMap) {
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
+ <button type="button" class="help" aria-hidden="true"
+ >?</button>
<h3></h3>
</div>
<div class="modal-body"></div>
.table-cursor tr:hover {
cursor: pointer;
}
+
+// hide
+.modal {
+ .help {
+ display: none;
+ }
+}
\ No newline at end of file