From: Martin Vitez Date: Fri, 26 Apr 2013 09:42:59 +0000 (+0200) Subject: Fixed SchemaPath resolution for base YANG types. X-Git-Tag: releasepom-0.1.0~518 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=9fab620d933bab1ddf7eef39087fa515e6d0c988;p=controller.git Fixed SchemaPath resolution for base YANG types. Refactored refine statement parsing. Change-Id: Ic00b86c611f1f56b69d9e09bf197d9ddb79da145 Signed-off-by: Martin Vitez --- diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java index aa3debff94..39afc37de7 100644 --- a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypesTest.java @@ -37,7 +37,6 @@ public class GeneratedTypesTest { return parser.resolveSchemaContext(modules); } - @Ignore @Test public void testLeafEnumResolving() { final String ietfInterfacesPath = getClass().getResource( diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java index 99add7c334..69346b0f72 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/api/UsesNodeBuilder.java @@ -22,7 +22,7 @@ public interface UsesNodeBuilder extends Builder { void addAugment(AugmentationSchemaBuilder builder); void setAugmenting(boolean augmenting); List getRefines(); - void setRefines(List refines); + void addRefine(RefineHolder refine); void addRefineNode(SchemaNodeBuilder refineNode); UsesNode build(); diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/IdentityrefTypeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/IdentityrefTypeBuilder.java index 9cf91c7315..33b6416234 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/IdentityrefTypeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/IdentityrefTypeBuilder.java @@ -31,10 +31,13 @@ import org.opendaylight.controller.yang.model.util.IdentityrefType; public class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder implements TypeDefinitionBuilder, Builder { private final String baseString; + private final SchemaPath schemaPath; private QName baseQName; - public IdentityrefTypeBuilder(String baseString) { + + public IdentityrefTypeBuilder(final String baseString, SchemaPath schemaPath) { this.baseString = baseString; + this.schemaPath = schemaPath; } public String getBaseString() { @@ -69,7 +72,7 @@ public class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder implements @Override public IdentityrefType build() { - return new IdentityrefType(baseQName); + return new IdentityrefType(baseQName, schemaPath); } @Override diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java index e309172f4c..51ab3639bb 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/ModuleBuilder.java @@ -29,6 +29,7 @@ import org.opendaylight.controller.yang.model.api.Module; import org.opendaylight.controller.yang.model.api.ModuleImport; import org.opendaylight.controller.yang.model.api.NotificationDefinition; import org.opendaylight.controller.yang.model.api.RpcDefinition; +import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.TypeDefinition; import org.opendaylight.controller.yang.model.api.UsesNode; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; @@ -41,6 +42,7 @@ import org.opendaylight.controller.yang.model.parser.builder.api.TypeAwareBuilde import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; +import org.opendaylight.controller.yang.model.parser.util.RefineHolder; import org.opendaylight.controller.yang.model.parser.util.YangParseException; /** @@ -419,10 +421,9 @@ public class ModuleBuilder implements Builder { public UsesNodeBuilder addUsesNode(final String groupingPathStr, final List parentPath) { final List pathToUses = new ArrayList(parentPath); - - UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr); - - ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes + final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl( + groupingPathStr); + final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes .get(pathToUses); if (parent != null) { parent.addUsesNode(usesBuilder); @@ -430,33 +431,46 @@ public class ModuleBuilder implements Builder { pathToUses.add(groupingPathStr); addedUsesNodes.put(pathToUses, usesBuilder); - + moduleNodes.put(pathToUses, usesBuilder); return usesBuilder; } - public RpcDefinitionBuilder addRpc(final QName qname, + public void addRefine(final RefineHolder refine, final List parentPath) { - List pathToRpc = new ArrayList(parentPath); + final List path = new ArrayList(parentPath); + final Builder parent = moduleNodes.get(path); + if (!(parent instanceof UsesNodeBuilder)) { + throw new YangParseException("Failed to parse refine " + + refine.getName()); + } + UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent; + usesBuilder.addRefine(refine); + path.add(refine.getName()); + moduleNodes.put(path, refine); + } - RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname); + public RpcDefinitionBuilder addRpc(final QName qname, + final List parentPath) { + final List pathToRpc = new ArrayList(parentPath); + final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname); pathToRpc.add(qname.getLocalName()); addedRpcs.put(pathToRpc, rpcBuilder); - QName inputQName = new QName(qname.getNamespace(), qname.getRevision(), - qname.getPrefix(), "input"); - ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder( + final QName inputQName = new QName(qname.getNamespace(), + qname.getRevision(), qname.getPrefix(), "input"); + final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder( inputQName); - List pathToInput = new ArrayList(pathToRpc); + final List pathToInput = new ArrayList(pathToRpc); pathToInput.add("input"); moduleNodes.put(pathToInput, inputBuilder); rpcBuilder.setInput(inputBuilder); - QName outputQName = new QName(qname.getNamespace(), + final QName outputQName = new QName(qname.getNamespace(), qname.getRevision(), qname.getPrefix(), "output"); - ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder( + final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder( outputQName); - List pathToOutput = new ArrayList(pathToRpc); + final List pathToOutput = new ArrayList(pathToRpc); pathToOutput.add("output"); moduleNodes.put(pathToOutput, outputBuilder); rpcBuilder.setOutput(outputBuilder); @@ -577,23 +591,28 @@ public class ModuleBuilder implements Builder { parent.setType(type); } - public void addUnionType(List parentPath) { + public void addUnionType(final List actualPath, + final URI namespace, final Date revision) { + List pathToUnion = new ArrayList(actualPath); TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes - .get(parentPath); - UnionTypeBuilder union = new UnionTypeBuilder(); + .get(pathToUnion); + UnionTypeBuilder union = new UnionTypeBuilder(pathToUnion, namespace, + revision); parent.setType(union); - List path = new ArrayList(parentPath); + List path = new ArrayList(pathToUnion); path.add("union"); moduleNodes.put(path, union); } - public void addIdentityrefType(String baseString, List parentPath) { + public void addIdentityrefType(String baseString, List parentPath, + SchemaPath schemaPath) { List pathToIdentityref = new ArrayList(parentPath); TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes .get(pathToIdentityref); - IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(baseString); + IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder( + baseString, schemaPath); parent.setType(identityref); dirtyNodes.put(pathToIdentityref, parent); } @@ -608,7 +627,8 @@ public class ModuleBuilder implements Builder { return builder; } - public IdentitySchemaNodeBuilder addIdentity(QName qname, List parentPath) { + public IdentitySchemaNodeBuilder addIdentity(QName qname, + List parentPath) { List pathToIdentity = new ArrayList(parentPath); IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname); pathToIdentity.add(qname.getLocalName()); @@ -632,14 +652,13 @@ public class ModuleBuilder implements Builder { final List pathToUnknown = new ArrayList(parentPath); final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder( qname); - - final SchemaNodeBuilder parent = (SchemaNodeBuilder) moduleNodes - .get(pathToUnknown); - if (parent != null) { - parent.addUnknownSchemaNode(builder); + final Builder parent = moduleNodes.get(pathToUnknown); + if (parent instanceof RefineHolder) { + ((RefineHolder) parent).addUnknownSchemaNode(builder); + } else if (parent instanceof SchemaNodeBuilder) { + ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder); } - - return new UnknownSchemaNodeBuilder(qname); + return builder; } private class ModuleImpl implements Module { diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java index e4b1be5d75..0e768c1107 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/TypedefBuilder.java @@ -59,7 +59,7 @@ public class TypedefBuilder extends AbstractTypeAwareBuilder implements } typeBuilder = new ExtendedType.Builder(qname, type, description, - reference); + reference, schemaPath); typeBuilder.status(status); typeBuilder.units(units); diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnionTypeBuilder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnionTypeBuilder.java index 50a7a3a1f0..9ab103d71e 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnionTypeBuilder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UnionTypeBuilder.java @@ -7,8 +7,10 @@ */ package org.opendaylight.controller.yang.model.parser.builder.impl; +import java.net.URI; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -35,10 +37,19 @@ public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements private final List typedefs; private final UnionType instance; - public UnionTypeBuilder() { + private final List actualPath; + private final URI namespace; + private final Date revision; + + public UnionTypeBuilder(final List actualPath, final URI namespace, + final Date revision) { types = new ArrayList>(); typedefs = new ArrayList(); - instance = new UnionType(types); + instance = new UnionType(actualPath, namespace, revision, types); + + this.actualPath = actualPath; + this.namespace = namespace; + this.revision = revision; } public List> getTypes() { @@ -203,6 +214,18 @@ public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements + UnionTypeBuilder.class.getSimpleName()); } + public List getActualPath() { + return actualPath; + } + + public URI getNamespace() { + return namespace; + } + + public Date getRevision() { + return revision; + } + @Override public String toString() { final StringBuilder result = new StringBuilder( diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java index 5fb4c99ff6..7d3e929357 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/builder/impl/UsesNodeBuilderImpl.java @@ -32,7 +32,7 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { private final SchemaPath groupingPath; private final Set addedAugments = new HashSet(); private List refineBuilders = new ArrayList(); - private List refines = Collections.emptyList(); + private List refines = new ArrayList(); UsesNodeBuilderImpl(final String groupingPathStr) { this.groupingPath = parseUsesPath(groupingPathStr); @@ -79,15 +79,14 @@ public class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder { refineBuilders.add(refineNode); } + @Override public List getRefines() { return refines; } @Override - public void setRefines(List refines) { - if(refines != null) { - this.refines = refines; - } + public void addRefine(RefineHolder refine) { + refines.add(refine); } private SchemaPath parseUsesPath(final String augmentPath) { diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java index b10798b980..8a72419176 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserImpl.java @@ -70,9 +70,9 @@ import org.opendaylight.controller.yang.model.parser.builder.impl.ListSchemaNode import org.opendaylight.controller.yang.model.parser.builder.impl.ModuleBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.TypedefBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.UnionTypeBuilder; +import org.opendaylight.controller.yang.model.parser.builder.impl.UnknownSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.util.ParserUtils; import org.opendaylight.controller.yang.model.parser.util.RefineHolder; -import org.opendaylight.controller.yang.model.parser.util.RefineHolder.Refine; import org.opendaylight.controller.yang.model.parser.util.TypeConstraints; import org.opendaylight.controller.yang.model.parser.util.YangParseException; import org.opendaylight.controller.yang.model.util.ExtendedType; @@ -282,9 +282,11 @@ public class YangModelParserImpl implements YangModelParser { } } unionTypes.removeAll(toRemove); - } else if(nodeToResolve.getTypedef() instanceof IdentityrefTypeBuilder) { - IdentityrefTypeBuilder idref = (IdentityrefTypeBuilder)nodeToResolve.getTypedef(); - nodeToResolve.setType(new IdentityrefType(findFullQName(modules, module, idref))); + } else if (nodeToResolve.getTypedef() instanceof IdentityrefTypeBuilder) { + IdentityrefTypeBuilder idref = (IdentityrefTypeBuilder) nodeToResolve + .getTypedef(); + nodeToResolve.setType(new IdentityrefType(findFullQName( + modules, module, idref), idref.getPath())); } else { final TypeDefinitionBuilder resolvedType = resolveType( nodeToResolve, modules, module); @@ -388,7 +390,9 @@ public class YangModelParserImpl implements YangModelParser { final TypeDefinitionBuilder old, final boolean seekByTypedefBuilder) { if (old instanceof UnionTypeBuilder) { final UnionTypeBuilder oldUnion = (UnionTypeBuilder) old; - final UnionTypeBuilder newUnion = new UnionTypeBuilder(); + final UnionTypeBuilder newUnion = new UnionTypeBuilder( + oldUnion.getActualPath(), oldUnion.getNamespace(), + oldUnion.getRevision()); for (TypeDefinition td : oldUnion.getTypes()) { newUnion.setType(td); } @@ -472,8 +476,8 @@ public class YangModelParserImpl implements YangModelParser { copy.setType(baseTdbCopyResolved); return copy; } else { - throw new IllegalStateException( - "TypeDefinitionBuilder in unexpected state"); + throw new IllegalStateException("Failed to resolve type " + + copy.getQName().getLocalName()); } } @@ -481,14 +485,11 @@ public class YangModelParserImpl implements YangModelParser { final QName unknownTypeQName, final Map> modules, final ModuleBuilder builder) { - // search for module which contains referenced typedef final ModuleBuilder dependentModule = findDependentModule(modules, builder, unknownTypeQName.getPrefix()); - final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName( dependentModule, unknownTypeQName.getLocalName()); - return copyTypedefBuilder(lookedUpBuilder, true); } @@ -497,7 +498,6 @@ public class YangModelParserImpl implements YangModelParser { final TypeConstraints constraints, final Map> modules, final ModuleBuilder builder) { - // union type cannot be restricted if (nodeToResolve instanceof UnionTypeBuilder) { return constraints; @@ -560,7 +560,6 @@ public class YangModelParserImpl implements YangModelParser { mergeConstraints(referencedType, constraints); return constraints; } - } /** @@ -666,6 +665,13 @@ public class YangModelParserImpl implements YangModelParser { } } + /** + * + * @param modules + * all available modules + * @param module + * current module + */ private void resolveAugment( final Map> modules, final ModuleBuilder module) { @@ -679,7 +685,7 @@ public class YangModelParserImpl implements YangModelParser { int i = 0; final QName qname = path.get(i); String prefix = qname.getPrefix(); - if(prefix == null) { + if (prefix == null) { prefix = module.getPrefix(); } @@ -719,7 +725,7 @@ public class YangModelParserImpl implements YangModelParser { final QName lastAugmentPathElement = path.get(path.size() - 1); if (currentQName.getLocalName().equals( lastAugmentPathElement.getLocalName())) { - fillAugmentTarget(augmentBuilder, + ParserUtils.fillAugmentTarget(augmentBuilder, (ChildNodeBuilder) currentParent); ((AugmentationTargetBuilder) currentParent) .addAugmentation(augmentBuilder); @@ -729,20 +735,6 @@ public class YangModelParserImpl implements YangModelParser { } } - /** - * Add all augment's child nodes to given target. - * - * @param augment - * @param target - */ - private void fillAugmentTarget(final AugmentationSchemaBuilder augment, - final ChildNodeBuilder target) { - for (DataSchemaNodeBuilder builder : augment.getChildNodes()) { - builder.setAugmenting(true); - target.addChildNode(builder); - } - } - /** * Go through identity statements defined in current module and resolve * their 'base' statement if present. @@ -806,9 +798,7 @@ public class YangModelParserImpl implements YangModelParser { final String groupingName = key.get(key.size() - 1); - final List refines = usesNode.getRefines(); - for (RefineHolder refine : refines) { - final Refine refineType = refine.getType(); + for (RefineHolder refine : usesNode.getRefines()) { // refine statements final String defaultStr = refine.getDefaultStr(); final Boolean mandatory = refine.isMandatory(); @@ -816,11 +806,13 @@ public class YangModelParserImpl implements YangModelParser { final Boolean presence = refine.isPresence(); final Integer min = refine.getMinElements(); final Integer max = refine.getMaxElements(); + final List unknownNodes = refine + .getUnknownNodes(); - switch (refineType) { - case LEAF: - final LeafSchemaNodeBuilder leaf = (LeafSchemaNodeBuilder) getRefineTargetBuilder( - groupingName, refine, modules, module); + Builder refineTarget = getRefineTargetBuilder(groupingName, + refine, modules, module); + if (refineTarget instanceof LeafSchemaNodeBuilder) { + final LeafSchemaNodeBuilder leaf = (LeafSchemaNodeBuilder) refineTarget; if (defaultStr != null && !("".equals(defaultStr))) { leaf.setDefaultStr(defaultStr); } @@ -830,22 +822,28 @@ public class YangModelParserImpl implements YangModelParser { if (must != null) { leaf.getConstraints().addMustDefinition(must); } + if (unknownNodes != null) { + for (UnknownSchemaNodeBuilder unknown : unknownNodes) { + leaf.addUnknownSchemaNode(unknown); + } + } usesNode.addRefineNode(leaf); - break; - case CONTAINER: - final ContainerSchemaNodeBuilder container = (ContainerSchemaNodeBuilder) getRefineTargetBuilder( - groupingName, refine, modules, module); + } else if (refineTarget instanceof ContainerSchemaNodeBuilder) { + final ContainerSchemaNodeBuilder container = (ContainerSchemaNodeBuilder) refineTarget; if (presence != null) { container.setPresence(presence); } if (must != null) { container.getConstraints().addMustDefinition(must); } + if (unknownNodes != null) { + for (UnknownSchemaNodeBuilder unknown : unknownNodes) { + container.addUnknownSchemaNode(unknown); + } + } usesNode.addRefineNode(container); - break; - case LIST: - final ListSchemaNodeBuilder list = (ListSchemaNodeBuilder) getRefineTargetBuilder( - groupingName, refine, modules, module); + } else if (refineTarget instanceof ListSchemaNodeBuilder) { + final ListSchemaNodeBuilder list = (ListSchemaNodeBuilder) refineTarget; if (must != null) { list.getConstraints().addMustDefinition(must); } @@ -855,8 +853,12 @@ public class YangModelParserImpl implements YangModelParser { if (max != null) { list.getConstraints().setMaxElements(max); } - break; - case LEAF_LIST: + if (unknownNodes != null) { + for (UnknownSchemaNodeBuilder unknown : unknownNodes) { + list.addUnknownSchemaNode(unknown); + } + } + } else if (refineTarget instanceof LeafListSchemaNodeBuilder) { final LeafListSchemaNodeBuilder leafList = (LeafListSchemaNodeBuilder) getRefineTargetBuilder( groupingName, refine, modules, module); if (must != null) { @@ -868,26 +870,37 @@ public class YangModelParserImpl implements YangModelParser { if (max != null) { leafList.getConstraints().setMaxElements(max); } - break; - case CHOICE: - final ChoiceBuilder choice = (ChoiceBuilder) getRefineTargetBuilder( - groupingName, refine, modules, module); + if (unknownNodes != null) { + for (UnknownSchemaNodeBuilder unknown : unknownNodes) { + leafList.addUnknownSchemaNode(unknown); + } + } + } else if (refineTarget instanceof ChoiceBuilder) { + final ChoiceBuilder choice = (ChoiceBuilder) refineTarget; if (defaultStr != null) { choice.setDefaultCase(defaultStr); } if (mandatory != null) { choice.getConstraints().setMandatory(mandatory); } - break; - case ANYXML: - final AnyXmlBuilder anyXml = (AnyXmlBuilder) getRefineTargetBuilder( - groupingName, refine, modules, module); + if (unknownNodes != null) { + for (UnknownSchemaNodeBuilder unknown : unknownNodes) { + choice.addUnknownSchemaNode(unknown); + } + } + } else if (refineTarget instanceof AnyXmlBuilder) { + final AnyXmlBuilder anyXml = (AnyXmlBuilder) refineTarget; if (mandatory != null) { anyXml.getConstraints().setMandatory(mandatory); } if (must != null) { anyXml.getConstraints().addMustDefinition(must); } + if (unknownNodes != null) { + for (UnknownSchemaNodeBuilder unknown : unknownNodes) { + anyXml.addUnknownSchemaNode(unknown); + } + } } } } @@ -978,21 +991,26 @@ public class YangModelParserImpl implements YangModelParser { return builder.getChildNode(refineNodeName); } - private QName findFullQName(final Map> modules, + private QName findFullQName( + final Map> modules, final ModuleBuilder module, final IdentityrefTypeBuilder idref) { QName result = null; String baseString = idref.getBaseString(); - if(baseString.contains(":")) { + if (baseString.contains(":")) { String[] splittedBase = baseString.split(":"); - if(splittedBase.length > 2) { - throw new YangParseException("Failed to parse identityref base: "+ baseString); + if (splittedBase.length > 2) { + throw new YangParseException( + "Failed to parse identityref base: " + baseString); } String prefix = splittedBase[0]; String name = splittedBase[1]; - ModuleBuilder dependentModule = findDependentModule(modules, module, prefix); - result = new QName(dependentModule.getNamespace(), dependentModule.getRevision(), prefix, name); + ModuleBuilder dependentModule = findDependentModule(modules, + module, prefix); + result = new QName(dependentModule.getNamespace(), + dependentModule.getRevision(), prefix, name); } else { - result = new QName(module.getNamespace(), module.getRevision(), module.getPrefix(), baseString); + result = new QName(module.getNamespace(), module.getRevision(), + module.getPrefix(), baseString); } return result; } @@ -1017,8 +1035,8 @@ public class YangModelParserImpl implements YangModelParser { if (prefix.equals(module.getPrefix())) { dependentModule = module; } else { - final ModuleImport dependentModuleImport = ParserUtils.getModuleImport(module, - prefix); + final ModuleImport dependentModuleImport = ParserUtils + .getModuleImport(module, prefix); if (dependentModuleImport == null) { throw new YangParseException("No import found with prefix '" + prefix + "' in module " + module.getName() + "'."); @@ -1053,7 +1071,6 @@ public class YangModelParserImpl implements YangModelParser { return dependentModule; } - private static class SchemaContextImpl implements SchemaContext { private final Set modules; diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java index bc5f77be83..11b655b4a1 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java @@ -52,11 +52,11 @@ 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; import org.opendaylight.controller.yang.model.api.TypeDefinition; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; -import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.AnyXmlBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceCaseBuilder; @@ -329,9 +329,10 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { moduleBuilder.setType(type, actualPath); } else { if ("union".equals(typeName)) { - moduleBuilder.addUnionType(actualPath); + moduleBuilder.addUnionType(actualPath, namespace, revision); } else if("identityref".equals(typeName)) { - moduleBuilder.addIdentityrefType(getIdentityrefBase(typeBody), actualPath); + SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix); + moduleBuilder.addIdentityrefType(getIdentityrefBase(typeBody), actualPath, path); } else { List typePath = new ArrayList(actualPath); typePath.remove(0); @@ -459,12 +460,9 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { @Override public void enterUses_stmt(YangParser.Uses_stmtContext ctx) { final String groupingPathStr = stringFromNode(ctx); - UsesNodeBuilder builder = moduleBuilder.addUsesNode(groupingPathStr, + moduleBuilder.addUsesNode(groupingPathStr, actualPath); updatePath(groupingPathStr); - - final List refines = parseRefines(ctx); - builder.setRefines(refines); } @Override @@ -473,6 +471,20 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { logger.debug("exiting " + actContainer); } + @Override + public void enterRefine_stmt(YangParser.Refine_stmtContext ctx) { + String refineString = stringFromNode(ctx); + RefineHolder refine = parseRefine(ctx); + moduleBuilder.addRefine(refine, actualPath); + updatePath(refineString); + } + + @Override + public void exitRefine_stmt(YangParser.Refine_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + @Override public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) { final String leafListName = stringFromNode(ctx); diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/ParserUtils.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/ParserUtils.java index e7775ce734..fa88a29981 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/ParserUtils.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/ParserUtils.java @@ -16,6 +16,7 @@ import org.opendaylight.controller.yang.model.api.MustDefinition; import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.TypeDefinition; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; +import org.opendaylight.controller.yang.model.parser.builder.api.ChildNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.DataSchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder; @@ -59,7 +60,9 @@ public final class ParserUtils { /** * Parse uses path. - * @param usesPath as String + * + * @param usesPath + * as String * @return SchemaPath from given String */ public static SchemaPath parseUsesPath(final String usesPath) { @@ -82,6 +85,21 @@ public final class ParserUtils { return new SchemaPath(path, absolute); } + /** + * Add all augment's child nodes to given target. + * + * @param augment + * @param target + */ + public static void fillAugmentTarget( + final AugmentationSchemaBuilder augment, + final ChildNodeBuilder target) { + for (DataSchemaNodeBuilder builder : augment.getChildNodes()) { + builder.setAugmenting(true); + target.addChildNode(builder); + } + } + public static LeafSchemaNodeBuilder copyLeafBuilder( final LeafSchemaNodeBuilder old) { final LeafSchemaNodeBuilder copy = new LeafSchemaNodeBuilder( diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/RefineHolder.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/RefineHolder.java index 19b6764e0a..0c31655610 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/RefineHolder.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/RefineHolder.java @@ -7,11 +7,15 @@ */ package org.opendaylight.controller.yang.model.parser.util; +import java.util.ArrayList; +import java.util.List; + import org.opendaylight.controller.yang.model.api.MustDefinition; +import org.opendaylight.controller.yang.model.parser.builder.api.Builder; +import org.opendaylight.controller.yang.model.parser.builder.impl.UnknownSchemaNodeBuilder; -public final class RefineHolder { +public final class RefineHolder implements Builder { private final String name; - private Refine type; private String defaultStr; private String description; private String reference; @@ -21,19 +25,12 @@ public final class RefineHolder { private MustDefinition must; private Integer minElements; private Integer maxElements; + private final List addedUnknownNodes = new ArrayList(); public RefineHolder(final String name) { this.name = name; } - public Refine getType() { - return type; - } - - public void setType(final Refine type) { - this.type = type; - } - public String getDefaultStr() { return defaultStr; } @@ -110,8 +107,17 @@ public final class RefineHolder { return name; } - public enum Refine { - CONTAINER, LEAF, LIST, LEAF_LIST, CHOICE, ANYXML + public List getUnknownNodes() { + return addedUnknownNodes; + } + + public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) { + addedUnknownNodes.add(unknownNode); + } + + @Override + public Object build() { + return null; } } diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java index 94b790f78f..fff33b63bd 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/util/YangModelBuilderUtil.java @@ -63,7 +63,6 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.StringContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.String_restrictionsContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Type_body_stmtsContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Units_stmtContext; -import org.opendaylight.controller.antlrv4.code.gen.YangParser.Uses_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Value_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.When_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yin_element_argContext; @@ -84,7 +83,6 @@ import org.opendaylight.controller.yang.model.api.type.PatternConstraint; import org.opendaylight.controller.yang.model.api.type.RangeConstraint; import org.opendaylight.controller.yang.model.parser.builder.api.SchemaNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.ConstraintsBuilder; -import org.opendaylight.controller.yang.model.parser.util.RefineHolder.Refine; import org.opendaylight.controller.yang.model.util.BaseConstraints; import org.opendaylight.controller.yang.model.util.BinaryType; import org.opendaylight.controller.yang.model.util.BitsType; @@ -1017,7 +1015,7 @@ public final class YangModelBuilderUtil { } else if ("string".equals(typeName)) { type = new StringType(actualPath, namespace, revision, lengthStatements, patternStatements); } else if ("bits".equals(typeName)) { - type = new BitsType(getBits(typeBody, actualPath, namespace, + type = new BitsType(actualPath, namespace, revision, getBits(typeBody, actualPath, namespace, revision, prefix)); } else if ("leafref".equals(typeName)) { final String path = parseLeafrefPath(typeBody); @@ -1027,10 +1025,10 @@ public final class YangModelBuilderUtil { type = new Leafref(actualPath, namespace, revision, xpath); } else if ("binary".equals(typeName)) { List bytes = Collections.emptyList(); - type = new BinaryType(bytes, lengthStatements, null); + type = new BinaryType(actualPath, namespace, revision, bytes, lengthStatements, null); } else if ("instance-identifier".equals(typeName)) { boolean requireInstance = isRequireInstance(typeBody); - type = new InstanceIdentifier(null, requireInstance); + type = new InstanceIdentifier(actualPath, namespace, revision, null, requireInstance); } return type; } @@ -1196,52 +1194,86 @@ public final class YangModelBuilderUtil { return yinValue; } - public static List parseRefines(Uses_stmtContext ctx) { - List refines = new ArrayList(); - - for (int i = 0; i < ctx.getChildCount(); i++) { - ParseTree child = ctx.getChild(i); - if (child instanceof Refine_stmtContext) { - final String refineTarget = stringFromNode(child); - final RefineHolder refine = new RefineHolder(refineTarget); - for (int j = 0; j < child.getChildCount(); j++) { - ParseTree refinePom = child.getChild(j); - if (refinePom instanceof Refine_pomContext) { - for (int k = 0; k < refinePom.getChildCount(); k++) { - ParseTree refineStmt = refinePom.getChild(k); - if (refineStmt instanceof Refine_leaf_stmtsContext) { - parseRefine(refine, - (Refine_leaf_stmtsContext) refineStmt); - } else if (refineStmt instanceof Refine_container_stmtsContext) { - parseRefine( - refine, - (Refine_container_stmtsContext) refineStmt); - } else if (refineStmt instanceof Refine_list_stmtsContext) { - parseRefine(refine, - (Refine_list_stmtsContext) refineStmt); - } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) { - parseRefine( - refine, - (Refine_leaf_list_stmtsContext) refineStmt); - } else if (refineStmt instanceof Refine_choice_stmtsContext) { - parseRefine(refine, - (Refine_choice_stmtsContext) refineStmt); - } else if (refineStmt instanceof Refine_anyxml_stmtsContext) { - parseRefine(refine, - (Refine_anyxml_stmtsContext) refineStmt); - } - } +// public static List parseRefines(Uses_stmtContext ctx) { +// List refines = new ArrayList(); +// +// for (int i = 0; i < ctx.getChildCount(); i++) { +// ParseTree child = ctx.getChild(i); +// if (child instanceof Refine_stmtContext) { +// final String refineTarget = stringFromNode(child); +// final RefineHolder refine = new RefineHolder(refineTarget); +// for (int j = 0; j < child.getChildCount(); j++) { +// ParseTree refinePom = child.getChild(j); +// if (refinePom instanceof Refine_pomContext) { +// for (int k = 0; k < refinePom.getChildCount(); k++) { +// ParseTree refineStmt = refinePom.getChild(k); +// if (refineStmt instanceof Refine_leaf_stmtsContext) { +// parseRefine(refine, +// (Refine_leaf_stmtsContext) refineStmt); +// } else if (refineStmt instanceof Refine_container_stmtsContext) { +// parseRefine( +// refine, +// (Refine_container_stmtsContext) refineStmt); +// } else if (refineStmt instanceof Refine_list_stmtsContext) { +// parseRefine(refine, +// (Refine_list_stmtsContext) refineStmt); +// } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) { +// parseRefine( +// refine, +// (Refine_leaf_list_stmtsContext) refineStmt); +// } else if (refineStmt instanceof Refine_choice_stmtsContext) { +// parseRefine(refine, +// (Refine_choice_stmtsContext) refineStmt); +// } else if (refineStmt instanceof Refine_anyxml_stmtsContext) { +// parseRefine(refine, +// (Refine_anyxml_stmtsContext) refineStmt); +// } +// } +// } +// } +// refines.add(refine); +// } +// } +// return refines; +// } + + public static RefineHolder parseRefine(Refine_stmtContext child) { + final String refineTarget = stringFromNode(child); + final RefineHolder refine = new RefineHolder(refineTarget); + for (int j = 0; j < child.getChildCount(); j++) { + ParseTree refinePom = child.getChild(j); + if (refinePom instanceof Refine_pomContext) { + for (int k = 0; k < refinePom.getChildCount(); k++) { + ParseTree refineStmt = refinePom.getChild(k); + if (refineStmt instanceof Refine_leaf_stmtsContext) { + parseRefine(refine, + (Refine_leaf_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_container_stmtsContext) { + parseRefine( + refine, + (Refine_container_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_list_stmtsContext) { + parseRefine(refine, + (Refine_list_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_leaf_list_stmtsContext) { + parseRefine( + refine, + (Refine_leaf_list_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_choice_stmtsContext) { + parseRefine(refine, + (Refine_choice_stmtsContext) refineStmt); + } else if (refineStmt instanceof Refine_anyxml_stmtsContext) { + parseRefine(refine, + (Refine_anyxml_stmtsContext) refineStmt); } } - refines.add(refine); } } - return refines; + return refine; } private static RefineHolder parseRefine(RefineHolder refine, Refine_leaf_stmtsContext refineStmt) { - refine.setType(Refine.LEAF); for (int i = 0; i < refineStmt.getChildCount(); i++) { ParseTree refineArg = refineStmt.getChild(i); if (refineArg instanceof Default_stmtContext) { @@ -1267,7 +1299,6 @@ public final class YangModelBuilderUtil { private static RefineHolder parseRefine(RefineHolder refine, Refine_container_stmtsContext refineStmt) { - refine.setType(Refine.CONTAINER); for (int m = 0; m < refineStmt.getChildCount(); m++) { ParseTree refineArg = refineStmt.getChild(m); if (refineArg instanceof Must_stmtContext) { @@ -1282,7 +1313,6 @@ public final class YangModelBuilderUtil { private static RefineHolder parseRefine(RefineHolder refine, Refine_list_stmtsContext refineStmt) { - refine.setType(Refine.LIST); for (int m = 0; m < refineStmt.getChildCount(); m++) { ParseTree refineArg = refineStmt.getChild(m); if (refineArg instanceof Must_stmtContext) { @@ -1301,7 +1331,6 @@ public final class YangModelBuilderUtil { private static RefineHolder parseRefine(RefineHolder refine, Refine_leaf_list_stmtsContext refineStmt) { - refine.setType(Refine.LEAF_LIST); for (int m = 0; m < refineStmt.getChildCount(); m++) { ParseTree refineArg = refineStmt.getChild(m); if (refineArg instanceof Must_stmtContext) { @@ -1320,7 +1349,6 @@ public final class YangModelBuilderUtil { private static RefineHolder parseRefine(RefineHolder refine, Refine_choice_stmtsContext refineStmt) { - refine.setType(Refine.CHOICE); for (int i = 0; i < refineStmt.getChildCount(); i++) { ParseTree refineArg = refineStmt.getChild(i); if (refineArg instanceof Default_stmtContext) { @@ -1342,7 +1370,6 @@ public final class YangModelBuilderUtil { private static RefineHolder parseRefine(RefineHolder refine, Refine_anyxml_stmtsContext refineStmt) { - refine.setType(Refine.ANYXML); for (int i = 0; i < refineStmt.getChildCount(); i++) { ParseTree refineArg = refineStmt.getChild(i); if (refineArg instanceof Must_stmtContext) { diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TypesResolutionTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TypesResolutionTest.java index e22fef0f17..46630b845a 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TypesResolutionTest.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/model/parser/impl/TypesResolutionTest.java @@ -34,7 +34,6 @@ import org.opendaylight.controller.yang.model.util.StringType; import org.opendaylight.controller.yang.model.util.UnionType; public class TypesResolutionTest { - private Set testedModules; @Before diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractSignedInteger.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractSignedInteger.java index 3907cc13e5..c2ae7d304a 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractSignedInteger.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractSignedInteger.java @@ -46,6 +46,20 @@ public abstract class AbstractSignedInteger implements IntegerTypeDefinition { private final String units; private final List rangeStatements; + protected AbstractSignedInteger(final QName name, final String description, + final Number minRange, final Number maxRange, final String units) { + this.name = name; + this.description = description; + this.path = BaseTypes.schemaPath(name); + this.units = units; + this.rangeStatements = new ArrayList(); + final String rangeDescription = "Integer values between " + minRange + + " and " + maxRange + ", inclusively."; + this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange, + maxRange, rangeDescription, + "https://tools.ietf.org/html/rfc6020#section-9.2.4")); + } + /** * @param name * @param description diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractUnsignedInteger.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractUnsignedInteger.java index 76048519e7..31a62ececd 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractUnsignedInteger.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/AbstractUnsignedInteger.java @@ -42,7 +42,26 @@ public abstract class AbstractUnsignedInteger implements private final String units; private final List rangeStatements; + protected AbstractUnsignedInteger(final QName name, + final String description, final Number minRange, + final Number maxRange, final String units) { + this.name = name; + this.description = description; + this.path = BaseTypes.schemaPath(name); + this.units = units; + this.rangeStatements = new ArrayList(); + final String rangeDescription = "Integer values between " + minRange + + " and " + maxRange + ", inclusively."; + this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange, + maxRange, rangeDescription, + "https://tools.ietf.org/html/rfc6020#section-9.2.4")); + } + /** + * + * @param actualPath + * @param namespace + * @param revision * @param name * @param description * @param minRange diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BinaryType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BinaryType.java index 70298a7e07..253fe484f0 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BinaryType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BinaryType.java @@ -7,8 +7,10 @@ */ package org.opendaylight.controller.yang.model.util; +import java.net.URI; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -20,43 +22,55 @@ import org.opendaylight.controller.yang.model.api.type.LengthConstraint; /** * The default implementation of Binary Type Definition interface. - * + * * @see BinaryTypeDefinition */ public class BinaryType implements BinaryTypeDefinition { private final QName name = BaseTypes.constructQName("binary"); - private final SchemaPath path = BaseTypes.schemaPath(name); + private final SchemaPath path; private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets."; private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8"; - + private final BinaryTypeDefinition baseType; private List bytes; private final List lengthConstraints; private String units = ""; - /** - * - */ - public BinaryType() { + private BinaryType() { + super(); + + final List constraints = new ArrayList(); + constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", "")); + this.lengthConstraints = Collections.unmodifiableList(constraints); + this.bytes = Collections.emptyList(); + this.path = BaseTypes.schemaPath(name); + this.baseType = this; + } + + public BinaryType(final List actualPath, final URI namespace, + final Date revision) { super(); - + final List constraints = new ArrayList(); constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", "")); - lengthConstraints = Collections.unmodifiableList(constraints); - bytes = Collections.emptyList(); + this.lengthConstraints = Collections.unmodifiableList(constraints); + this.bytes = Collections.emptyList(); + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new BinaryType(); } /** - * - * + * + * * @param bytes * @param lengthConstraints * @param units */ - public BinaryType(final List bytes, + public BinaryType(final List actualPath, final URI namespace, + final Date revision, final List bytes, final List lengthConstraints, final String units) { super(); - + if ((lengthConstraints == null) || (lengthConstraints.isEmpty())) { final List constraints = new ArrayList(); constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", "")); @@ -64,9 +78,11 @@ public class BinaryType implements BinaryTypeDefinition { } else { this.lengthConstraints = Collections.unmodifiableList(lengthConstraints); } - + + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); this.bytes = Collections.unmodifiableList(bytes); this.units = units; + this.baseType = new BinaryType(); } /* @@ -76,7 +92,7 @@ public class BinaryType implements BinaryTypeDefinition { */ @Override public BinaryTypeDefinition getBaseType() { - return this; + return baseType; } /* diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BitsType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BitsType.java index e6c118934e..717c24ed50 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BitsType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BitsType.java @@ -1,13 +1,15 @@ /* - * 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.net.URI; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -16,22 +18,21 @@ import org.opendaylight.controller.yang.model.api.Status; import org.opendaylight.controller.yang.model.api.UnknownSchemaNode; import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition; - /** * The default implementation of Bits Type Definition interface. - * + * * @see BitsTypeDefinition */ public class BitsType implements BitsTypeDefinition { private final QName name = BaseTypes.constructQName("bits"); - private final SchemaPath path = BaseTypes.schemaPath(name); - private final String description = "The bits built-in type represents a bit set. " + - "That is, a bits value is a set of flags identified by small integer position " + - "numbers starting at 0. Each bit number has an assigned name."; - - private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7"; + private final SchemaPath path; + private final String description = "The bits built-in type represents a bit set. " + + "That is, a bits value is a set of flags identified by small integer position " + + "numbers starting at 0. Each bit number has an assigned name."; + private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7"; + private final BitsTypeDefinition baseType; private final List bits; private String units = ""; @@ -39,52 +40,72 @@ public class BitsType implements BitsTypeDefinition { * Default constructor.
* Instantiates Bits type as empty bits list. */ - public BitsType() { + private BitsType() { super(); - bits = Collections.emptyList(); + this.bits = Collections.emptyList(); + this.path = BaseTypes.schemaPath(name); + this.baseType = this; + } + + public BitsType(final List actualPath, final URI namespace, + final Date revision) { + super(); + this.bits = Collections.emptyList(); + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new BitsType(); } /** - * Constructor with explicit definition of bits assigned to - * BitsType. - * + * Constructor with explicit definition of bits assigned to BitsType. + * + * @param actualPath + * @param namespace + * @param revision * @param bits * The bits assigned for Bits Type */ - public BitsType(final List bits) { + public BitsType(final List actualPath, final URI namespace, + final Date revision, final List bits) { super(); this.bits = Collections.unmodifiableList(bits); this.units = ""; + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new BitsType(); } /** - * Constructor with explicit definition of bits assigned to - * BitsType and Units. - *
+ * Constructor with explicit definition of bits assigned to BitsType and + * Units.
* The default value of Bits Type is List of bits. - * - * @param bits The bits assigned for Bits Type - * @param units units for bits type + * + * @param bits + * The bits assigned for Bits Type + * @param units + * units for bits type */ - public BitsType(List bits, String units) { + public BitsType(final List actualPath, final URI namespace, + final Date revision, List bits, String units) { super(); this.bits = Collections.unmodifiableList(bits); this.units = units; + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new BitsType(); } /* * (non-Javadoc) - * - * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType() + * + * @see + * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType() */ @Override public BitsTypeDefinition getBaseType() { - return this; + return baseType; } /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits() */ @Override @@ -94,8 +115,10 @@ public class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * - * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue() + * + * @see + * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue + * () */ @Override public Object getDefaultValue() { @@ -104,7 +127,7 @@ public class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName() */ @Override @@ -114,7 +137,7 @@ public class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath() */ @Override @@ -124,8 +147,9 @@ public class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * - * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription() + * + * @see + * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription() */ @Override public String getDescription() { @@ -134,7 +158,7 @@ public class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference() */ @Override @@ -144,7 +168,7 @@ public class BitsType implements BitsTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus() */ @Override diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BooleanType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BooleanType.java index 9717ff66a6..f588bf425c 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BooleanType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/BooleanType.java @@ -1,13 +1,15 @@ /* - * 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.net.URI; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -18,62 +20,82 @@ import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition; /** * The default implementation of Boolean Type Definition interface. - * + * * @see BooleanTypeDefinition */ public class BooleanType implements BooleanTypeDefinition { private final QName name = BaseTypes.constructQName("boolean"); - private final SchemaPath path = BaseTypes.schemaPath(name); + private final SchemaPath path; private final String description = "The boolean built-in type represents a boolean value."; private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.5"; - + private final BooleanTypeDefinition baseType; private final Boolean defaultValue; private String units = ""; /** * Default constructor with default value set to "false". */ - public BooleanType() { + private BooleanType() { + super(); + this.defaultValue = false; + this.path = BaseTypes.schemaPath(name); + this.baseType = this; + } + + public BooleanType(final List actualPath, final URI namespace, + final Date revision) { super(); - defaultValue = false; + this.defaultValue = false; + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new BooleanType(); } /** * Boolean Type constructor. - * - * @param defaultValue Default Value + * + * @param defaultValue + * Default Value */ - public BooleanType(final Boolean defaultValue) { + public BooleanType(final List actualPath, final URI namespace, + final Date revision, final Boolean defaultValue) { super(); this.defaultValue = defaultValue; + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new BooleanType(); } /** * Boolean Type constructor. - * - * @param defaultValue Default Value - * @param units Units + * + * @param defaultValue + * Default Value + * @param units + * Units */ - public BooleanType(final Boolean defaultValue, final String units) { + public BooleanType(final List actualPath, final URI namespace, + final Date revision, final Boolean defaultValue, final String units) { super(); this.defaultValue = defaultValue; this.units = units; + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new BooleanType(); } /* * (non-Javadoc) - * - * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType() + * + * @see + * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType() */ @Override public BooleanTypeDefinition getBaseType() { - return this; + return baseType; } /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits() */ @Override @@ -83,8 +105,10 @@ public class BooleanType implements BooleanTypeDefinition { /* * (non-Javadoc) - * - * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue() + * + * @see + * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue + * () */ @Override public Object getDefaultValue() { @@ -93,7 +117,7 @@ public class BooleanType implements BooleanTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName() */ @Override @@ -103,7 +127,7 @@ public class BooleanType implements BooleanTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath() */ @Override @@ -113,8 +137,9 @@ public class BooleanType implements BooleanTypeDefinition { /* * (non-Javadoc) - * - * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription() + * + * @see + * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription() */ @Override public String getDescription() { @@ -123,7 +148,7 @@ public class BooleanType implements BooleanTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference() */ @Override @@ -133,7 +158,7 @@ public class BooleanType implements BooleanTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus() */ @Override diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Decimal64.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Decimal64.java index 158865aec9..adb4c1a3cb 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Decimal64.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Decimal64.java @@ -43,6 +43,7 @@ public class Decimal64 implements DecimalTypeDefinition { private final List rangeStatements; private final Integer fractionDigits; + private final DecimalTypeDefinition baseType; /** * Default Decimal64 Type Constructor.
@@ -61,6 +62,17 @@ public class Decimal64 implements DecimalTypeDefinition { * @see DecimalTypeDefinition * @exception IllegalArgumentException */ + private Decimal64(final Integer fractionDigits) { + if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) { + throw new IllegalArgumentException( + "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively"); + } + this.fractionDigits = fractionDigits; + this.rangeStatements = defaultRangeStatements(); + this.path = BaseTypes.schemaPath(name); + this.baseType = this; + } + public Decimal64(final List actualPath, final URI namespace, final Date revision, final Integer fractionDigits) { super(); @@ -71,6 +83,7 @@ public class Decimal64 implements DecimalTypeDefinition { this.fractionDigits = fractionDigits; rangeStatements = defaultRangeStatements(); this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new Decimal64(fractionDigits); } /** @@ -87,6 +100,9 @@ public class Decimal64 implements DecimalTypeDefinition { * If the fraction digits are not defined inner the definition boundaries * the constructor will throw {@link IllegalArgumentException} * + * @param actualPath + * @param namespace + * @param revision * @param rangeStatements * Range Constraint Statements * @param fractionDigits @@ -104,10 +120,12 @@ public class Decimal64 implements DecimalTypeDefinition { if (rangeStatements == null || rangeStatements.isEmpty()) { this.rangeStatements = defaultRangeStatements(); } else { - this.rangeStatements = Collections.unmodifiableList(rangeStatements); + this.rangeStatements = Collections + .unmodifiableList(rangeStatements); } this.fractionDigits = fractionDigits; this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new Decimal64(fractionDigits); } /** @@ -123,6 +141,9 @@ public class Decimal64 implements DecimalTypeDefinition { * If the fraction digits are not defined inner the definition boundaries * the constructor will throw {@link IllegalArgumentException} * + * @param actualPath + * @param namespace + * @param revision * @param units * units associated with the type * @param defaultValue @@ -131,11 +152,10 @@ public class Decimal64 implements DecimalTypeDefinition { * Range Constraint Statements * @param fractionDigits * integer between 1 and 18 inclusively - * - * @exception IllegalArgumentException */ public Decimal64(final List actualPath, final URI namespace, - final Date revision, final String units, final BigDecimal defaultValue, + final Date revision, final String units, + final BigDecimal defaultValue, final List rangeStatements, final Integer fractionDigits) { super(); @@ -148,12 +168,14 @@ public class Decimal64 implements DecimalTypeDefinition { this.rangeStatements = defaultRangeStatements(); } else { - this.rangeStatements = Collections.unmodifiableList(rangeStatements); + this.rangeStatements = Collections + .unmodifiableList(rangeStatements); } this.units = units; this.defaultValue = defaultValue; this.fractionDigits = fractionDigits; this.path = BaseTypes.schemaPath(name); + this.baseType = new Decimal64(fractionDigits); } /** @@ -175,7 +197,7 @@ public class Decimal64 implements DecimalTypeDefinition { @Override public DecimalTypeDefinition getBaseType() { - return this; + return baseType; } @Override diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java index 9a7b13ddb3..1b5abb2209 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/EmptyType.java @@ -7,7 +7,9 @@ */ package org.opendaylight.controller.yang.model.util; +import java.net.URI; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -19,13 +21,25 @@ import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition; public class EmptyType implements EmptyTypeDefinition { private final QName name = BaseTypes.constructQName("empty"); - private final SchemaPath path = BaseTypes.schemaPath(name); + private final SchemaPath path; private final String description = "The empty built-in type represents a leaf that does not have any value, it conveys information by its presence or absence."; private final String reference = "https://tools.ietf.org/html/rfc6020#page-131"; + private final EmptyTypeDefinition baseType; + + private EmptyType() { + path = BaseTypes.schemaPath(name); + this.baseType = this; + } + + public EmptyType(final List actualPath, + final URI namespace, final Date revision) { + path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new EmptyType(); + } @Override public EmptyTypeDefinition getBaseType() { - return this; + return baseType; } @Override diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/ExtendedType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/ExtendedType.java index 2057a42eb6..86bde24d62 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/ExtendedType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/ExtendedType.java @@ -1,13 +1,15 @@ /* - * 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.net.URI; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -33,7 +35,6 @@ public class ExtendedType implements TypeDefinition> { private List patterns = Collections.emptyList(); private Integer fractionDigits = null; - private Status status; private String units; private Object defaultValue; @@ -46,7 +47,8 @@ public class ExtendedType implements TypeDefinition> { private final String description; private final String reference; - private List unknownSchemaNodes = Collections.emptyList();; + private List unknownSchemaNodes = Collections + .emptyList(); private Status status = Status.CURRENT; private String units = ""; private Object defaultValue = null; @@ -56,11 +58,23 @@ public class ExtendedType implements TypeDefinition> { private List patterns = Collections.emptyList(); private Integer fractionDigits = null; + public Builder(final List actualPath, final URI namespace, + final Date revision, final QName typeName, + TypeDefinition baseType, final String description, + final String reference) { + this.typeName = typeName; + this.baseType = baseType; + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.description = description; + this.reference = reference; + } + public Builder(final QName typeName, TypeDefinition baseType, - final String description, final String reference) { + final String description, final String reference, + SchemaPath path) { this.typeName = typeName; this.baseType = baseType; - this.path = BaseTypes.schemaPath(typeName); + this.path = path; this.description = description; this.reference = reference; } @@ -80,27 +94,28 @@ public class ExtendedType implements TypeDefinition> { return this; } - public Builder unknownSchemaNodes(final List unknownSchemaNodes) { + public Builder unknownSchemaNodes( + final List unknownSchemaNodes) { this.unknownSchemaNodes = unknownSchemaNodes; return this; } public Builder ranges(final List ranges) { - if(ranges != null) { + if (ranges != null) { this.ranges = ranges; } return this; } public Builder lengths(final List lengths) { - if(lengths != null) { + if (lengths != null) { this.lengths = lengths; } return this; } public Builder patterns(final List patterns) { - if(patterns != null) { + if (patterns != null) { this.patterns = patterns; } return this; @@ -188,8 +203,10 @@ public class ExtendedType implements TypeDefinition> { + ((defaultValue == null) ? 0 : defaultValue.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result - + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes.hashCode()); + result = prime + * result + + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes + .hashCode()); result = prime * result + ((path == null) ? 0 : path.hashCode()); result = prime * result + ((reference == null) ? 0 : reference.hashCode()); diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/IdentityrefType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/IdentityrefType.java index 3837f72a8a..533318e39e 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/IdentityrefType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/IdentityrefType.java @@ -7,7 +7,9 @@ */ package org.opendaylight.controller.yang.model.util; +import java.net.URI; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -24,16 +26,32 @@ import org.opendaylight.controller.yang.model.api.type.IdentityrefTypeDefinition public class IdentityrefType implements IdentityrefTypeDefinition { private final QName name = BaseTypes.constructQName("identityref"); - private final SchemaPath path = BaseTypes.schemaPath(name); + private final SchemaPath path; private final String description = "The identityref type is used to reference an existing identity."; private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.10"; + private final IdentityrefTypeDefinition baseType; private final QName identity; private String units = ""; - public IdentityrefType(QName identity) { + private IdentityrefType(QName identity) { this.identity = identity; + this.path = BaseTypes.schemaPath(name); + this.baseType = this; + } + + public IdentityrefType(QName identity, SchemaPath schemaPath) { + this.identity = identity; + this.path = schemaPath; + this.baseType = new IdentityrefType(identity); + } + + public IdentityrefType(final List actualPath, + final URI namespace, final Date revision, final QName identity) { + this.identity = identity; + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.baseType = new IdentityrefType(identity); } @Override @@ -83,7 +101,7 @@ public class IdentityrefType implements IdentityrefTypeDefinition { @Override public IdentityrefTypeDefinition getBaseType() { - return this; + return baseType; } } diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/InstanceIdentifier.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/InstanceIdentifier.java index e4f62546f6..e39b1fa026 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/InstanceIdentifier.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/InstanceIdentifier.java @@ -7,7 +7,9 @@ */ package org.opendaylight.controller.yang.model.util; +import java.net.URI; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -30,31 +32,42 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { "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 = BaseTypes.schemaPath(name); + private final transient SchemaPath path; private final RevisionAwareXPath xpath; private final String units = ""; - + private final InstanceIdentifierTypeDefinition baseType; private final boolean requireInstance; - public InstanceIdentifier(RevisionAwareXPath xpath, boolean requireInstance) { + private InstanceIdentifier(RevisionAwareXPath xpath, boolean requireInstance) { + super(); + path = BaseTypes.schemaPath(name); + this.xpath = xpath; + this.requireInstance = requireInstance; + this.baseType = this; + } + + public InstanceIdentifier(final List actualPath, final URI namespace, + final Date revision, RevisionAwareXPath xpath, boolean requireInstance) { super(); + path = BaseTypes.schemaPath(actualPath, namespace, revision); this.xpath = xpath; this.requireInstance = requireInstance; + this.baseType = new InstanceIdentifier(xpath, requireInstance); } /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType() */ @Override public InstanceIdentifierTypeDefinition getBaseType() { - return this; + return baseType; } /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits() */ @Override @@ -64,7 +77,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue() */ @Override @@ -74,7 +87,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName() */ @Override @@ -84,7 +97,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath() */ @Override @@ -94,7 +107,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription() */ @Override @@ -104,7 +117,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference() */ @Override @@ -114,7 +127,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus() */ @Override @@ -124,7 +137,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes() */ @Override @@ -134,7 +147,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition# * getPathStatement() */ @@ -145,7 +158,7 @@ public class InstanceIdentifier implements InstanceIdentifierTypeDefinition { /* * (non-Javadoc) - * + * * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition# * requireInstance() */ diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int16.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int16.java index 750dff5c7a..0e100dc790 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int16.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int16.java @@ -28,10 +28,18 @@ public class Int16 extends AbstractSignedInteger { private Short defaultValue = null; private static final String description = "int16 represents integer values between -32768 and 32767, inclusively."; + private final IntegerTypeDefinition baseType; + + private Int16() { + super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = this; + } public Int16(final List actualPath, final URI namespace, final Date revision) { super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = new Int16(); + } public Int16(final List actualPath, final URI namespace, @@ -39,11 +47,12 @@ public class Int16 extends AbstractSignedInteger { final String units, final Short defaultValue) { super(actualPath, namespace, revision, name, description, rangeStatements, units); this.defaultValue = defaultValue; + this.baseType = new Int16(); } @Override public IntegerTypeDefinition getBaseType() { - return this; + return baseType; } @Override diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int32.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int32.java index da356309a5..fb777c5992 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int32.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int32.java @@ -30,15 +30,23 @@ public class Int32 extends AbstractSignedInteger { private Integer defaultValue = null; private static final String description = "int32 represents integer values between -2147483648 and 2147483647, inclusively."; + private final IntegerTypeDefinition baseType; + + private Int32() { + super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, ""); + this.baseType = this; + } public Int32(final List actualPath, final URI namespace, final Date revision) { super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, ""); + this.baseType = new Int32(); } public Int32(final List actualPath, final URI namespace, final Date revision, final Integer defaultValue) { super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, ""); + this.baseType = new Int32(); this.defaultValue = defaultValue; } @@ -46,6 +54,7 @@ public class Int32 extends AbstractSignedInteger { final Date revision, final List rangeStatements, final String units, final Integer defaultValue) { super(actualPath, namespace, revision, name, description, rangeStatements, units); + this.baseType = new Int32(); this.defaultValue = defaultValue; } @@ -57,7 +66,7 @@ public class Int32 extends AbstractSignedInteger { */ @Override public IntegerTypeDefinition getBaseType() { - return this; + return baseType; } /* diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int64.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int64.java index 4b05bc59e7..b22412012b 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int64.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int64.java @@ -28,15 +28,23 @@ public class Int64 extends AbstractSignedInteger { private Long defaultValue = null; private static final String description = "int64 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively."; + private final IntegerTypeDefinition baseType; + + private Int64() { + super(name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, ""); + this.baseType = this; + } public Int64(final List actualPath, final URI namespace, final Date revision) { super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, ""); + this.baseType = new Int64(); } public Int64(final List actualPath, final URI namespace, final Date revision, final Long defaultValue) { super(actualPath, namespace, revision, name, description, Integer.MIN_VALUE, Integer.MAX_VALUE, ""); + this.baseType = new Int64(); this.defaultValue = defaultValue; } @@ -44,6 +52,7 @@ public class Int64 extends AbstractSignedInteger { final Date revision, final List rangeStatements, final String units, final Long defaultValue) { super(actualPath, namespace, revision, name, description, rangeStatements, units); + this.baseType = new Int64(); this.defaultValue = defaultValue; } @@ -54,7 +63,7 @@ public class Int64 extends AbstractSignedInteger { */ @Override public IntegerTypeDefinition getBaseType() { - return this; + return baseType; } /* diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int8.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int8.java index 6a917b252f..8b0fbe1fa7 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int8.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Int8.java @@ -29,15 +29,23 @@ public class Int8 extends AbstractSignedInteger { private Byte defaultValue = null; private static final String description = "represents integer values between -128 and 127, inclusively."; + private final IntegerTypeDefinition baseType; + + private Int8() { + super(name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, ""); + this.baseType = this; + } public Int8(final List actualPath, final URI namespace, final Date revision) { super(actualPath, namespace, revision, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, ""); + this.baseType = new Int8(); } public Int8(final List actualPath, final URI namespace, final Date revision, final Byte defaultValue) { super(actualPath, namespace, revision, name, description, Byte.MIN_VALUE, Byte.MAX_VALUE, ""); + this.baseType = new Int8(); this.defaultValue = defaultValue; } @@ -45,6 +53,7 @@ public class Int8 extends AbstractSignedInteger { final Date revision, final List rangeStatements, final String units, final Byte defaultValue) { super(actualPath, namespace, revision, name, description, rangeStatements, units); + this.baseType = new Int8(); this.defaultValue = defaultValue; } @@ -55,7 +64,7 @@ public class Int8 extends AbstractSignedInteger { */ @Override public IntegerTypeDefinition getBaseType() { - return this; + return baseType; } /* diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/StringType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/StringType.java index f58075bf30..b4e2d6b9ad 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/StringType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/StringType.java @@ -36,6 +36,17 @@ public class StringType implements StringTypeDefinition { private final List lengthStatements; private final List patterns; private String units = ""; + private final StringTypeDefinition baseType; + + private StringType() { + super(); + path = BaseTypes.schemaPath(name); + final List constraints = new ArrayList(); + constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", "")); + lengthStatements = Collections.unmodifiableList(constraints); + patterns = Collections.emptyList(); + baseType = this; + } /** * Default Constructor. @@ -47,13 +58,15 @@ public class StringType implements StringTypeDefinition { final List constraints = new ArrayList(); constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", "")); lengthStatements = Collections.unmodifiableList(constraints); - - this.patterns = Collections.emptyList(); + patterns = Collections.emptyList(); + baseType = new StringType(); } /** * - * + * @param actualPath + * @param namespace + * @param revision * @param lengthStatements * @param patterns */ @@ -70,6 +83,7 @@ public class StringType implements StringTypeDefinition { this.lengthStatements = Collections.unmodifiableList(lengthStatements); } this.patterns = Collections.unmodifiableList(patterns); + baseType = new StringType(); } /** @@ -85,7 +99,7 @@ public class StringType implements StringTypeDefinition { final List lengthStatements, final List patterns, final String units) { super(); - path = BaseTypes.schemaPath(actualPath, namespace, revision); + this.path = BaseTypes.schemaPath(actualPath, namespace, revision); this.defaultValue = defaultValue; if(lengthStatements == null || lengthStatements.size() == 0) { final List constraints = new ArrayList(); @@ -94,8 +108,9 @@ public class StringType implements StringTypeDefinition { } else { this.lengthStatements = Collections.unmodifiableList(lengthStatements); } - this.patterns = patterns; + this.patterns = Collections.unmodifiableList(patterns); this.units = units; + this.baseType = new StringType(); } /* @@ -105,7 +120,7 @@ public class StringType implements StringTypeDefinition { */ @Override public StringTypeDefinition getBaseType() { - return this; + return baseType; } /* diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint16.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint16.java index 9db4ea9df8..5764cb26c7 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint16.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint16.java @@ -26,15 +26,23 @@ public class Uint16 extends AbstractUnsignedInteger { private static final QName name = BaseTypes.constructQName("uint16"); private Integer defaultValue = null; private static final String description = "uint16 represents integer values between 0 and 65535, inclusively."; + private final UnsignedIntegerTypeDefinition baseType; + + private Uint16() { + super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = this; + } public Uint16(final List actualPath, final URI namespace, final Date revision) { super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = new Uint16(); } public Uint16(final List actualPath, final URI namespace, final Date revision, final Integer defaultValue) { super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = new Uint16(); this.defaultValue = defaultValue; } @@ -42,6 +50,7 @@ public class Uint16 extends AbstractUnsignedInteger { final URI namespace, final Date revision, final List rangeStatements, final String units, final Integer defaultValue) { super(actualPath, namespace, revision, name, description, rangeStatements, units); + this.baseType = new Uint16(); this.defaultValue = defaultValue; } @@ -53,7 +62,7 @@ public class Uint16 extends AbstractUnsignedInteger { */ @Override public UnsignedIntegerTypeDefinition getBaseType() { - return this; + return baseType; } /* diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint32.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint32.java index 75f9b49693..47af1e1c98 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint32.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint32.java @@ -26,15 +26,23 @@ public class Uint32 extends AbstractUnsignedInteger { private static final QName name = BaseTypes.constructQName("uint32"); private Long defaultValue = null; private static final String description = "uint32 represents integer values between 0 and 4294967295, inclusively."; + private final UnsignedIntegerTypeDefinition baseType; + + private Uint32() { + super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = this; + } public Uint32(final List actualPath, final URI namespace, final Date revision) { super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = new Uint32(); } public Uint32(final List actualPath, final URI namespace, final Date revision, final Long defaultValue) { super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = new Uint32(); this.defaultValue = defaultValue; } @@ -42,6 +50,7 @@ public class Uint32 extends AbstractUnsignedInteger { final URI namespace, final Date revision, final List rangeStatements, final String units, final Long defaultValue) { super(actualPath, namespace, revision, name, description, rangeStatements, units); + this.baseType = new Uint32(); this.defaultValue = defaultValue; } @@ -53,7 +62,7 @@ public class Uint32 extends AbstractUnsignedInteger { */ @Override public UnsignedIntegerTypeDefinition getBaseType() { - return this; + return baseType; } /* diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint64.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint64.java index 05ea8c9e09..f9c2aa3c90 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint64.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint64.java @@ -30,15 +30,23 @@ public class Uint64 extends AbstractUnsignedInteger { private BigInteger defaultValue = null; private static final String description = "uint64 represents integer values between 0 and 18446744073709551615, inclusively."; + private final UnsignedIntegerTypeDefinition baseType; + + private Uint64() { + super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = this; + } public Uint64(final List actualPath, final URI namespace, final Date revision) { super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = new Uint64(); } public Uint64(final List actualPath, final URI namespace, final Date revision, final BigInteger defaultValue) { super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = new Uint64(); this.defaultValue = defaultValue; } @@ -46,6 +54,7 @@ public class Uint64 extends AbstractUnsignedInteger { final URI namespace, final Date revision, final List rangeStatements, final String units, final BigInteger defaultValue) { super(actualPath, namespace, revision, name, description, rangeStatements, units); + this.baseType = new Uint64(); this.defaultValue = defaultValue; } @@ -57,7 +66,7 @@ public class Uint64 extends AbstractUnsignedInteger { */ @Override public UnsignedIntegerTypeDefinition getBaseType() { - return this; + return baseType; } /* diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint8.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint8.java index aa1e6cacfb..ece0eb5c3f 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint8.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/Uint8.java @@ -29,15 +29,23 @@ public class Uint8 extends AbstractUnsignedInteger { private Short defaultValue = null; private static final String description = "uint8 represents integer values between 0 and 255, inclusively."; + private final UnsignedIntegerTypeDefinition baseType; + + private Uint8() { + super(name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = this; + } public Uint8(final List actualPath, final URI namespace, final Date revision) { super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = new Uint8(); } public Uint8(final List actualPath, final URI namespace, final Date revision, final Short defaultValue) { super(actualPath, namespace, revision, name, description, Short.MIN_VALUE, Short.MAX_VALUE, ""); + this.baseType = new Uint8(); this.defaultValue = defaultValue; } @@ -45,6 +53,7 @@ public class Uint8 extends AbstractUnsignedInteger { final URI namespace, final Date revision, final List rangeStatements, final String units, final Short defaultValue) { super(actualPath, namespace, revision, name, description, rangeStatements, units); + this.baseType = new Uint8(); this.defaultValue = defaultValue; } @@ -55,7 +64,7 @@ public class Uint8 extends AbstractUnsignedInteger { */ @Override public UnsignedIntegerTypeDefinition getBaseType() { - return this; + return baseType; } /* diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/UnionType.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/UnionType.java index ad40393291..1063f3b22b 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/UnionType.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/UnionType.java @@ -7,7 +7,9 @@ */ package org.opendaylight.controller.yang.model.util; +import java.net.URI; import java.util.Collections; +import java.util.Date; import java.util.List; import org.opendaylight.controller.yang.common.QName; @@ -20,23 +22,34 @@ import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition; public class UnionType implements UnionTypeDefinition { private final QName name = BaseTypes.constructQName("union"); - private final SchemaPath path = BaseTypes.schemaPath(name); + private final SchemaPath path; private final String description = "The union built-in type represents a value that corresponds to one of its member types."; private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12"; - + private final UnionTypeDefinition baseType; private final List> types; + private UnionType(List> types) { + if(types == null) { + throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present."); + } + path = BaseTypes.schemaPath(name); + this.types = types; + this.baseType = this; + } - public UnionType(List> types) { + public UnionType(final List actualPath, final URI namespace, + final Date revision, List> types) { if(types == null) { throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present."); } + path = BaseTypes.schemaPath(actualPath, namespace, revision); this.types = types; + this.baseType = new UnionType(types); } @Override public UnionTypeDefinition getBaseType() { - return this; + return baseType; } @Override @@ -86,8 +99,12 @@ public class UnionType implements UnionTypeDefinition { @Override public int hashCode() { - // TODO: implement hashcode - return 4; + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((path == null) ? 0 : path.hashCode()); + result = prime * result + ((types == null) ? 0 : types.hashCode()); + return result; } @Override diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java index f3db85cf9a..6d41321bfd 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/YangTypesConverter.java @@ -9,39 +9,16 @@ package org.opendaylight.controller.yang.model.util; import java.net.URI; import java.util.Date; -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.common.QName; import org.opendaylight.controller.yang.model.api.TypeDefinition; -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.model.api.type.EmptyTypeDefinition; -import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition; public class YangTypesConverter { - - private static final Map>> baseYangTypeMap = new HashMap>>(); private static final Set baseYangTypes = new HashSet(); - private static final TypeDefinition BINARY = new BinaryType(); - private static final TypeDefinition BITS = new BitsType(); - private static final TypeDefinition BOOLEAN_TYPE = new BooleanType(); - private static final TypeDefinition EMPTY_TYPE = new EmptyType(); - private static final TypeDefinition INST_ID_TYPE = new InstanceIdentifier( - null, true); - static { - baseYangTypeMap.put("binary", BINARY); - baseYangTypeMap.put("bits", BITS); - baseYangTypeMap.put("boolean", BOOLEAN_TYPE); - baseYangTypeMap.put("empty", EMPTY_TYPE); - baseYangTypeMap.put("instance-identifier", INST_ID_TYPE); - baseYangTypes.add("binary"); baseYangTypes.add("bits"); baseYangTypes.add("boolean"); @@ -67,40 +44,45 @@ public class YangTypesConverter { return baseYangTypes.contains(type); } - public static TypeDefinition javaTypeForBaseYangType(QName typeQName) { - TypeDefinition type = baseYangTypeMap.get(typeQName.getLocalName()); - return type; - } - public static TypeDefinition javaTypeForBaseYangType( List actualPath, URI namespace, Date revision, String typeName) { + TypeDefinition type = null; if (typeName.startsWith("int")) { if (typeName.equals("int8")) { - return new Int8(actualPath, namespace, revision); + type = new Int8(actualPath, namespace, revision); } else if (typeName.equals("int16")) { - return new Int16(actualPath, namespace, revision); + type = new Int16(actualPath, namespace, revision); } else if (typeName.equals("int32")) { - return new Int32(actualPath, namespace, revision); + type = new Int32(actualPath, namespace, revision); } else if (typeName.equals("int64")) { - return new Int64(actualPath, namespace, revision); + type = new Int64(actualPath, namespace, revision); } } else if (typeName.startsWith("uint")) { if (typeName.equals("uint8")) { - return new Uint8(actualPath, namespace, revision); + type = new Uint8(actualPath, namespace, revision); } else if (typeName.equals("uint16")) { - return new Uint16(actualPath, namespace, revision); + type = new Uint16(actualPath, namespace, revision); } else if (typeName.equals("uint32")) { - return new Uint32(actualPath, namespace, revision); + type = new Uint32(actualPath, namespace, revision); } else if (typeName.equals("uint64")) { - return new Uint64(actualPath, namespace, revision); + type = new Uint64(actualPath, namespace, revision); } - } else if (typeName.equals("string")) { - return new StringType(actualPath, namespace, revision); + } else if ("string".equals(typeName)) { + type = new StringType(actualPath, namespace, revision); + } else if("binary".equals(typeName)) { + type = new BinaryType(actualPath, namespace, revision); + } else if("bits".equals(typeName)) { + type = new BitsType(actualPath, namespace, revision); + } else if("boolean".equals(typeName)) { + type = new BooleanType(actualPath, namespace, revision); + } else if("empty".equals(typeName)) { + type = new EmptyType(actualPath, namespace, revision); + } else if("instance-identifier".equals(typeName)) { + type = new InstanceIdentifier(actualPath, namespace, revision, null, true); } - TypeDefinition type = baseYangTypeMap.get(typeName); return type; }