Refactored refine statement parsing.
Change-Id: Ic00b86c611f1f56b69d9e09bf197d9ddb79da145
Signed-off-by: Martin Vitez <mvitez@cisco.com>
return parser.resolveSchemaContext(modules);
}
- @Ignore
@Test
public void testLeafEnumResolving() {
final String ietfInterfacesPath = getClass().getResource(
void addAugment(AugmentationSchemaBuilder builder);
void setAugmenting(boolean augmenting);
List<RefineHolder> getRefines();
- void setRefines(List<RefineHolder> refines);
+ void addRefine(RefineHolder refine);
void addRefineNode(SchemaNodeBuilder refineNode);
UsesNode build();
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() {
@Override
public IdentityrefType build() {
- return new IdentityrefType(baseQName);
+ return new IdentityrefType(baseQName, schemaPath);
}
@Override
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;
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;
/**
public UsesNodeBuilder addUsesNode(final String groupingPathStr,
final List<String> parentPath) {
final List<String> pathToUses = new ArrayList<String>(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);
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<String> parentPath) {
- List<String> pathToRpc = new ArrayList<String>(parentPath);
+ final List<String> path = new ArrayList<String>(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<String> parentPath) {
+ final List<String> pathToRpc = new ArrayList<String>(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<String> pathToInput = new ArrayList<String>(pathToRpc);
+ final List<String> pathToInput = new ArrayList<String>(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<String> pathToOutput = new ArrayList<String>(pathToRpc);
+ final List<String> pathToOutput = new ArrayList<String>(pathToRpc);
pathToOutput.add("output");
moduleNodes.put(pathToOutput, outputBuilder);
rpcBuilder.setOutput(outputBuilder);
parent.setType(type);
}
- public void addUnionType(List<String> parentPath) {
+ public void addUnionType(final List<String> actualPath,
+ final URI namespace, final Date revision) {
+ List<String> pathToUnion = new ArrayList<String>(actualPath);
TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
- .get(parentPath);
- UnionTypeBuilder union = new UnionTypeBuilder();
+ .get(pathToUnion);
+ UnionTypeBuilder union = new UnionTypeBuilder(pathToUnion, namespace,
+ revision);
parent.setType(union);
- List<String> path = new ArrayList<String>(parentPath);
+ List<String> path = new ArrayList<String>(pathToUnion);
path.add("union");
moduleNodes.put(path, union);
}
- public void addIdentityrefType(String baseString, List<String> parentPath) {
+ public void addIdentityrefType(String baseString, List<String> parentPath,
+ SchemaPath schemaPath) {
List<String> pathToIdentityref = new ArrayList<String>(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);
}
return builder;
}
- public IdentitySchemaNodeBuilder addIdentity(QName qname, List<String> parentPath) {
+ public IdentitySchemaNodeBuilder addIdentity(QName qname,
+ List<String> parentPath) {
List<String> pathToIdentity = new ArrayList<String>(parentPath);
IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname);
pathToIdentity.add(qname.getLocalName());
final List<String> pathToUnknown = new ArrayList<String>(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 {
}
typeBuilder = new ExtendedType.Builder(qname, type, description,
- reference);
+ reference, schemaPath);
typeBuilder.status(status);
typeBuilder.units(units);
*/
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;
private final List<TypeDefinitionBuilder> typedefs;
private final UnionType instance;
- public UnionTypeBuilder() {
+ private final List<String> actualPath;
+ private final URI namespace;
+ private final Date revision;
+
+ public UnionTypeBuilder(final List<String> actualPath, final URI namespace,
+ final Date revision) {
types = new ArrayList<TypeDefinition<?>>();
typedefs = new ArrayList<TypeDefinitionBuilder>();
- instance = new UnionType(types);
+ instance = new UnionType(actualPath, namespace, revision, types);
+
+ this.actualPath = actualPath;
+ this.namespace = namespace;
+ this.revision = revision;
}
public List<TypeDefinition<?>> getTypes() {
+ UnionTypeBuilder.class.getSimpleName());
}
+ public List<String> getActualPath() {
+ return actualPath;
+ }
+
+ public URI getNamespace() {
+ return namespace;
+ }
+
+ public Date getRevision() {
+ return revision;
+ }
+
@Override
public String toString() {
final StringBuilder result = new StringBuilder(
private final SchemaPath groupingPath;\r
private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();\r
private List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
- private List<RefineHolder> refines = Collections.emptyList();\r
+ private List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
\r
UsesNodeBuilderImpl(final String groupingPathStr) {\r
this.groupingPath = parseUsesPath(groupingPathStr);\r
refineBuilders.add(refineNode);\r
}\r
\r
+ @Override\r
public List<RefineHolder> getRefines() {\r
return refines;\r
}\r
\r
@Override\r
- public void setRefines(List<RefineHolder> refines) {\r
- if(refines != null) {\r
- this.refines = refines;\r
- }\r
+ public void addRefine(RefineHolder refine) {\r
+ refines.add(refine);\r
}\r
\r
private SchemaPath parseUsesPath(final String augmentPath) {\r
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;
}
}
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);
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);
}
copy.setType(baseTdbCopyResolved);
return copy;
} else {
- throw new IllegalStateException(
- "TypeDefinitionBuilder in unexpected state");
+ throw new IllegalStateException("Failed to resolve type "
+ + copy.getQName().getLocalName());
}
}
final QName unknownTypeQName,
final Map<String, TreeMap<Date, ModuleBuilder>> 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);
}
final TypeConstraints constraints,
final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder builder) {
-
// union type cannot be restricted
if (nodeToResolve instanceof UnionTypeBuilder) {
return constraints;
mergeConstraints(referencedType, constraints);
return constraints;
}
-
}
/**
}
}
+ /**
+ *
+ * @param modules
+ * all available modules
+ * @param module
+ * current module
+ */
private void resolveAugment(
final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module) {
int i = 0;
final QName qname = path.get(i);
String prefix = qname.getPrefix();
- if(prefix == null) {
+ if (prefix == null) {
prefix = module.getPrefix();
}
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);
}
}
- /**
- * 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.
final String groupingName = key.get(key.size() - 1);
- final List<RefineHolder> 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();
final Boolean presence = refine.isPresence();
final Integer min = refine.getMinElements();
final Integer max = refine.getMaxElements();
+ final List<UnknownSchemaNodeBuilder> 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);
}
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);
}
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) {
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);
+ }
+ }
}
}
}
return builder.getChildNode(refineNodeName);
}
- private QName findFullQName(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ private QName findFullQName(
+ final Map<String, TreeMap<Date, ModuleBuilder>> 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;
}
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() + "'.");
return dependentModule;
}
-
private static class SchemaContextImpl implements SchemaContext {
private final Set<Module> modules;
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;
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<String> typePath = new ArrayList<String>(actualPath);
typePath.remove(0);
@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<RefineHolder> refines = parseRefines(ctx);
- builder.setRefines(refines);
}
@Override
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);
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;
/**
* Parse uses path.
- * @param usesPath as String
+ *
+ * @param usesPath
+ * as String
* @return SchemaPath from given String
*/
public static SchemaPath parseUsesPath(final String usesPath) {
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(
*/
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;
private MustDefinition must;
private Integer minElements;
private Integer maxElements;
+ private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
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;
}
return name;
}
- public enum Refine {
- CONTAINER, LEAF, LIST, LEAF_LIST, CHOICE, ANYXML
+ public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+ return addedUnknownNodes;
+ }
+
+ public void addUnknownSchemaNode(UnknownSchemaNodeBuilder unknownNode) {
+ addedUnknownNodes.add(unknownNode);
+ }
+
+ @Override
+ public Object build() {
+ return null;
}
}
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;
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;
} 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);
type = new Leafref(actualPath, namespace, revision, xpath);
} else if ("binary".equals(typeName)) {
List<Byte> 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;
}
return yinValue;
}
- public static List<RefineHolder> parseRefines(Uses_stmtContext ctx) {
- List<RefineHolder> refines = new ArrayList<RefineHolder>();
-
- 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<RefineHolder> parseRefines(Uses_stmtContext ctx) {
+// List<RefineHolder> refines = new ArrayList<RefineHolder>();
+//
+// 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) {
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) {
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) {
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) {
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) {
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) {
import org.opendaylight.controller.yang.model.util.UnionType;
public class TypesResolutionTest {
-
private Set<Module> testedModules;
@Before
private final String units;
private final List<RangeConstraint> 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<RangeConstraint>();
+ 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
private final String units;
private final List<RangeConstraint> 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<RangeConstraint>();
+ 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
*/
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;
/**
* The <code>default</code> 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<Byte> bytes;
private final List<LengthConstraint> lengthConstraints;
private String units = "";
- /**
- *
- */
- public BinaryType() {
+ private BinaryType() {
+ super();
+
+ final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
+ 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<String> actualPath, final URI namespace,
+ final Date revision) {
super();
-
+
final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
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<Byte> bytes,
+ public BinaryType(final List<String> actualPath, final URI namespace,
+ final Date revision, final List<Byte> bytes,
final List<LengthConstraint> lengthConstraints, final String units) {
super();
-
+
if ((lengthConstraints == null) || (lengthConstraints.isEmpty())) {
final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
} 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();
}
/*
*/
@Override
public BinaryTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
/*
/*
- * 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;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
-
/**
* The <code>default</code> 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<Bit> bits;
private String units = "";
* Default constructor. <br>
* 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<String> 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<Bit> bits) {
+ public BitsType(final List<String> actualPath, final URI namespace,
+ final Date revision, final List<Bit> 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.
- * <br>
+ * Constructor with explicit definition of bits assigned to BitsType and
+ * Units. <br>
* 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<Bit> bits, String units) {
+ public BitsType(final List<String> actualPath, final URI namespace,
+ final Date revision, List<Bit> 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
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+ *
+ * @see
+ * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+ * ()
*/
@Override
public Object getDefaultValue() {
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
*/
@Override
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
+ *
+ * @see
+ * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
*/
@Override
public String getDescription() {
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
*/
@Override
/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
package org.opendaylight.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;
/**
* The <code>default</code> 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<String> 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<String> 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<String> 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
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+ *
+ * @see
+ * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+ * ()
*/
@Override
public Object getDefaultValue() {
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
*/
@Override
/*
* (non-Javadoc)
- *
- * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
+ *
+ * @see
+ * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
*/
@Override
public String getDescription() {
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
*/
@Override
private final List<RangeConstraint> rangeStatements;
private final Integer fractionDigits;
+ private final DecimalTypeDefinition baseType;
/**
* Default Decimal64 Type Constructor. <br>
* @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<String> actualPath, final URI namespace,
final Date revision, final Integer fractionDigits) {
super();
this.fractionDigits = fractionDigits;
rangeStatements = defaultRangeStatements();
this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+ this.baseType = new Decimal64(fractionDigits);
}
/**
* 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
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);
}
/**
* 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
* Range Constraint Statements
* @param fractionDigits
* integer between 1 and 18 inclusively
- *
- * @exception IllegalArgumentException
*/
public Decimal64(final List<String> actualPath, final URI namespace,
- final Date revision, final String units, final BigDecimal defaultValue,
+ final Date revision, final String units,
+ final BigDecimal defaultValue,
final List<RangeConstraint> rangeStatements,
final Integer fractionDigits) {
super();
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);
}
/**
@Override
public DecimalTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
@Override
*/
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;
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<String> 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
/*
- * 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;
private List<PatternConstraint> patterns = Collections.emptyList();
private Integer fractionDigits = null;
-
private Status status;
private String units;
private Object defaultValue;
private final String description;
private final String reference;
- private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();;
+ private List<UnknownSchemaNode> unknownSchemaNodes = Collections
+ .emptyList();
private Status status = Status.CURRENT;
private String units = "";
private Object defaultValue = null;
private List<PatternConstraint> patterns = Collections.emptyList();
private Integer fractionDigits = null;
+ public Builder(final List<String> 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;
}
return this;
}
- public Builder unknownSchemaNodes(final List<UnknownSchemaNode> unknownSchemaNodes) {
+ public Builder unknownSchemaNodes(
+ final List<UnknownSchemaNode> unknownSchemaNodes) {
this.unknownSchemaNodes = unknownSchemaNodes;
return this;
}
public Builder ranges(final List<RangeConstraint> ranges) {
- if(ranges != null) {
+ if (ranges != null) {
this.ranges = ranges;
}
return this;
}
public Builder lengths(final List<LengthConstraint> lengths) {
- if(lengths != null) {
+ if (lengths != null) {
this.lengths = lengths;
}
return this;
}
public Builder patterns(final List<PatternConstraint> patterns) {
- if(patterns != null) {
+ if (patterns != null) {
this.patterns = patterns;
}
return this;
+ ((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());
*/\r
package org.opendaylight.controller.yang.model.util;\r
\r
+import java.net.URI;\r
import java.util.Collections;\r
+import java.util.Date;\r
import java.util.List;\r
\r
import org.opendaylight.controller.yang.common.QName;\r
public class IdentityrefType implements IdentityrefTypeDefinition {\r
\r
private final QName name = BaseTypes.constructQName("identityref");\r
- private final SchemaPath path = BaseTypes.schemaPath(name);\r
+ private final SchemaPath path;\r
private final String description = "The identityref type is used to reference an existing identity.";\r
private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.10";\r
+ private final IdentityrefTypeDefinition baseType;\r
\r
private final QName identity;\r
\r
private String units = "";\r
\r
- public IdentityrefType(QName identity) {\r
+ private IdentityrefType(QName identity) {\r
this.identity = identity;\r
+ this.path = BaseTypes.schemaPath(name);\r
+ this.baseType = this;\r
+ }\r
+\r
+ public IdentityrefType(QName identity, SchemaPath schemaPath) {\r
+ this.identity = identity;\r
+ this.path = schemaPath;\r
+ this.baseType = new IdentityrefType(identity);\r
+ }\r
+\r
+ public IdentityrefType(final List<String> actualPath,\r
+ final URI namespace, final Date revision, final QName identity) {\r
+ this.identity = identity;\r
+ this.path = BaseTypes.schemaPath(actualPath, namespace, revision);\r
+ this.baseType = new IdentityrefType(identity);\r
}\r
\r
@Override\r
\r
@Override\r
public IdentityrefTypeDefinition getBaseType() {\r
- return this;\r
+ return baseType;\r
}\r
\r
}\r
*/
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;
"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<String> 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
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes()
*/
@Override
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
* getPathStatement()
*/
/*
* (non-Javadoc)
- *
+ *
* @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
* requireInstance()
*/
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<String> 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<String> actualPath, final URI namespace,
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
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<String> 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<String> 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;
}
final Date revision, final List<RangeConstraint> rangeStatements,
final String units, final Integer defaultValue) {
super(actualPath, namespace, revision, name, description, rangeStatements, units);
+ this.baseType = new Int32();
this.defaultValue = defaultValue;
}
*/
@Override
public IntegerTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
/*
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<String> 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<String> 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;
}
final Date revision, final List<RangeConstraint> rangeStatements,
final String units, final Long defaultValue) {
super(actualPath, namespace, revision, name, description, rangeStatements, units);
+ this.baseType = new Int64();
this.defaultValue = defaultValue;
}
*/
@Override
public IntegerTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
/*
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<String> 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<String> 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;
}
final Date revision, final List<RangeConstraint> rangeStatements,
final String units, final Byte defaultValue) {
super(actualPath, namespace, revision, name, description, rangeStatements, units);
+ this.baseType = new Int8();
this.defaultValue = defaultValue;
}
*/
@Override
public IntegerTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
/*
private final List<LengthConstraint> lengthStatements;
private final List<PatternConstraint> patterns;
private String units = "";
+ private final StringTypeDefinition baseType;
+
+ private StringType() {
+ super();
+ path = BaseTypes.schemaPath(name);
+ final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
+ constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
+ lengthStatements = Collections.unmodifiableList(constraints);
+ patterns = Collections.emptyList();
+ baseType = this;
+ }
/**
* Default Constructor.
final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
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
*/
this.lengthStatements = Collections.unmodifiableList(lengthStatements);
}
this.patterns = Collections.unmodifiableList(patterns);
+ baseType = new StringType();
}
/**
final List<LengthConstraint> lengthStatements,
final List<PatternConstraint> 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<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
} else {
this.lengthStatements = Collections.unmodifiableList(lengthStatements);
}
- this.patterns = patterns;
+ this.patterns = Collections.unmodifiableList(patterns);
this.units = units;
+ this.baseType = new StringType();
}
/*
*/
@Override
public StringTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
/*
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<String> 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<String> 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;
}
final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
final String units, final Integer defaultValue) {
super(actualPath, namespace, revision, name, description, rangeStatements, units);
+ this.baseType = new Uint16();
this.defaultValue = defaultValue;
}
*/
@Override
public UnsignedIntegerTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
/*
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<String> 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<String> 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;
}
final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
final String units, final Long defaultValue) {
super(actualPath, namespace, revision, name, description, rangeStatements, units);
+ this.baseType = new Uint32();
this.defaultValue = defaultValue;
}
*/
@Override
public UnsignedIntegerTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
/*
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<String> 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<String> 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;
}
final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
final String units, final BigInteger defaultValue) {
super(actualPath, namespace, revision, name, description, rangeStatements, units);
+ this.baseType = new Uint64();
this.defaultValue = defaultValue;
}
*/
@Override
public UnsignedIntegerTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
/*
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<String> 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<String> 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;
}
final URI namespace, final Date revision, final List<RangeConstraint> rangeStatements,
final String units, final Short defaultValue) {
super(actualPath, namespace, revision, name, description, rangeStatements, units);
+ this.baseType = new Uint8();
this.defaultValue = defaultValue;
}
*/
@Override
public UnsignedIntegerTypeDefinition getBaseType() {
- return this;
+ return baseType;
}
/*
*/
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;
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<TypeDefinition<?>> types;
+ private UnionType(List<TypeDefinition<?>> 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<TypeDefinition<?>> types) {
+ public UnionType(final List<String> actualPath, final URI namespace,
+ final Date revision, List<TypeDefinition<?>> 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
@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
\r
import java.net.URI;\r
import java.util.Date;\r
-import java.util.HashMap;\r
import java.util.HashSet;\r
import java.util.List;\r
-import java.util.Map;\r
import java.util.Set;\r
\r
-import org.opendaylight.controller.yang.common.QName;\r
import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.BooleanTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.EmptyTypeDefinition;\r
-import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition;\r
\r
public class YangTypesConverter {\r
-\r
- private static final Map<String, TypeDefinition<? extends TypeDefinition<?>>> baseYangTypeMap = new HashMap<String, TypeDefinition<? extends TypeDefinition<?>>>();\r
private static final Set<String> baseYangTypes = new HashSet<String>();\r
\r
- private static final TypeDefinition<BinaryTypeDefinition> BINARY = new BinaryType();\r
- private static final TypeDefinition<BitsTypeDefinition> BITS = new BitsType();\r
- private static final TypeDefinition<BooleanTypeDefinition> BOOLEAN_TYPE = new BooleanType();\r
- private static final TypeDefinition<EmptyTypeDefinition> EMPTY_TYPE = new EmptyType();\r
- private static final TypeDefinition<InstanceIdentifierTypeDefinition> INST_ID_TYPE = new InstanceIdentifier(\r
- null, true);\r
-\r
static {\r
- baseYangTypeMap.put("binary", BINARY);\r
- baseYangTypeMap.put("bits", BITS);\r
- baseYangTypeMap.put("boolean", BOOLEAN_TYPE);\r
- baseYangTypeMap.put("empty", EMPTY_TYPE);\r
- baseYangTypeMap.put("instance-identifier", INST_ID_TYPE);\r
-\r
baseYangTypes.add("binary");\r
baseYangTypes.add("bits");\r
baseYangTypes.add("boolean");\r
return baseYangTypes.contains(type);\r
}\r
\r
- public static TypeDefinition<?> javaTypeForBaseYangType(QName typeQName) {\r
- TypeDefinition<?> type = baseYangTypeMap.get(typeQName.getLocalName());\r
- return type;\r
- }\r
-\r
public static TypeDefinition<?> javaTypeForBaseYangType(\r
List<String> actualPath, URI namespace, Date revision,\r
String typeName) {\r
+ TypeDefinition<?> type = null;\r
\r
if (typeName.startsWith("int")) {\r
if (typeName.equals("int8")) {\r
- return new Int8(actualPath, namespace, revision);\r
+ type = new Int8(actualPath, namespace, revision);\r
} else if (typeName.equals("int16")) {\r
- return new Int16(actualPath, namespace, revision);\r
+ type = new Int16(actualPath, namespace, revision);\r
} else if (typeName.equals("int32")) {\r
- return new Int32(actualPath, namespace, revision);\r
+ type = new Int32(actualPath, namespace, revision);\r
} else if (typeName.equals("int64")) {\r
- return new Int64(actualPath, namespace, revision);\r
+ type = new Int64(actualPath, namespace, revision);\r
}\r
} else if (typeName.startsWith("uint")) {\r
if (typeName.equals("uint8")) {\r
- return new Uint8(actualPath, namespace, revision);\r
+ type = new Uint8(actualPath, namespace, revision);\r
} else if (typeName.equals("uint16")) {\r
- return new Uint16(actualPath, namespace, revision);\r
+ type = new Uint16(actualPath, namespace, revision);\r
} else if (typeName.equals("uint32")) {\r
- return new Uint32(actualPath, namespace, revision);\r
+ type = new Uint32(actualPath, namespace, revision);\r
} else if (typeName.equals("uint64")) {\r
- return new Uint64(actualPath, namespace, revision);\r
+ type = new Uint64(actualPath, namespace, revision);\r
}\r
- } else if (typeName.equals("string")) {\r
- return new StringType(actualPath, namespace, revision);\r
+ } else if ("string".equals(typeName)) {\r
+ type = new StringType(actualPath, namespace, revision);\r
+ } else if("binary".equals(typeName)) {\r
+ type = new BinaryType(actualPath, namespace, revision);\r
+ } else if("bits".equals(typeName)) {\r
+ type = new BitsType(actualPath, namespace, revision);\r
+ } else if("boolean".equals(typeName)) {\r
+ type = new BooleanType(actualPath, namespace, revision);\r
+ } else if("empty".equals(typeName)) {\r
+ type = new EmptyType(actualPath, namespace, revision);\r
+ } else if("instance-identifier".equals(typeName)) {\r
+ type = new InstanceIdentifier(actualPath, namespace, revision, null, true);\r
}\r
\r
- TypeDefinition<?> type = baseYangTypeMap.get(typeName);\r
return type;\r
}\r
\r