*/
public interface Builder {
- Object build();
- int getLine();
+ Object build();
+
+ int getLine();
}
\r
import java.util.List;\r
\r
-import org.opendaylight.controller.yang.common.QName;\r
-import org.opendaylight.controller.yang.model.api.SchemaPath;\r
import org.opendaylight.controller.yang.model.api.Status;\r
import org.opendaylight.controller.yang.model.api.TypeDefinition;\r
import org.opendaylight.controller.yang.model.api.type.LengthConstraint;\r
\r
TypeDefinition<?> build();\r
\r
- QName getQName();\r
-\r
- SchemaPath getPath();\r
-\r
String getDescription();\r
\r
String getReference();\r
instance.setConfiguration(configuration);
}
- private static class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
+ private class AnyXmlSchemaNodeImpl implements AnyXmlSchemaNode {
private final QName qname;
private SchemaPath path;
private String description;
int result = 1;
result = prime * result
+ ((augmentTargetStr == null) ? 0 : augmentTargetStr.hashCode());
- result = prime * result
- + ((childNodes == null) ? 0 : childNodes.hashCode());
- result = prime * result
- + ((groupings == null) ? 0 : groupings.hashCode());
- result = prime * result + ((usesNodes == null) ? 0 : usesNodes.hashCode());
result = prime * result
+ ((whenCondition == null) ? 0 : whenCondition.hashCode());
return result;
} else if (!augmentTargetStr.equals(other.augmentTargetStr)) {
return false;
}
- if (childNodes == null) {
- if (other.childNodes != null) {
- return false;
- }
- } else if (!childNodes.equals(other.childNodes)) {
- return false;
- }
- if (groupings == null) {
- if (other.groupings != null) {
- return false;
- }
- } else if (!groupings.equals(other.groupings)) {
- return false;
- }
- if (usesNodes == null) {
- if (other.usesNodes != null) {
- return false;
- }
- } else if (!usesNodes.equals(other.usesNodes)) {
- return false;
- }
if (whenCondition == null) {
if (other.whenCondition != null) {
return false;
int result = 1;
result = prime * result
+ ((targetPath == null) ? 0 : targetPath.hashCode());
- result = prime * result
- + ((childNodes == null) ? 0 : childNodes.hashCode());
- result = prime * result
- + ((groupings == null) ? 0 : groupings.hashCode());
- result = prime * result + ((uses == null) ? 0 : uses.hashCode());
result = prime * result
+ ((whenCondition == null) ? 0 : whenCondition.hashCode());
return result;
} else if (!targetPath.equals(other.targetPath)) {
return false;
}
- if (childNodes == null) {
- if (other.childNodes != null) {
- return false;
- }
- } else if (!childNodes.equals(other.childNodes)) {
- return false;
- }
- if (groupings == null) {
- if (other.groupings != null) {
- return false;
- }
- } else if (!groupings.equals(other.groupings)) {
- return false;
- }
- if (uses == null) {
- if (other.uses != null) {
- return false;
- }
- } else if (!uses.equals(other.uses)) {
- return false;
- }
if (whenCondition == null) {
if (other.whenCondition != null) {
return false;
import java.util.Set;
import org.opendaylight.controller.yang.model.api.ConstraintDefinition;
-import org.opendaylight.controller.yang.model.api.DataSchemaNode;
import org.opendaylight.controller.yang.model.api.MustDefinition;
import org.opendaylight.controller.yang.model.api.RevisionAwareXPath;
import org.opendaylight.controller.yang.model.util.RevisionAwareXPathImpl;
private static class ConstraintDefinitionImpl implements
ConstraintDefinition {
- private DataSchemaNode parent;
private RevisionAwareXPath whenCondition;
private Set<MustDefinition> mustConstraints;
private boolean mandatory;
private Integer minElements;
private Integer maxElements;
- @Override
- public DataSchemaNode getParent() {
- return parent;
- }
-
@Override
public RevisionAwareXPath getWhenCondition() {
return whenCondition;
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result
- + ((parent == null) ? 0 : parent.hashCode());
result = prime * result
+ ((whenCondition == null) ? 0 : whenCondition.hashCode());
result = prime
return false;
}
ConstraintDefinitionImpl other = (ConstraintDefinitionImpl) obj;
- if (parent == null) {
- if (other.parent != null) {
- return false;
- }
- } else if (!parent.equals(other.parent)) {
- return false;
- }
if (whenCondition == null) {
if (other.whenCondition != null) {
return false;
StringBuilder sb = new StringBuilder(
ConstraintDefinitionImpl.class.getSimpleName());
sb.append("[");
- sb.append("parent=" + parent);
- sb.append(", whenCondition=" + whenCondition);
+ sb.append("whenCondition=" + whenCondition);
sb.append(", mustConstraints=" + mustConstraints);
sb.append(", mandatory=" + mandatory);
sb.append(", minElements=" + minElements);
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
public class DeviationBuilder implements Builder {
private final DeviationImpl instance;
} else if ("delete".equals(deviate)) {
instance.setDeviate(Deviate.DELETE);
} else {
- throw new IllegalArgumentException(
+ throw new YangParseException(line,
"Unsupported type of 'deviate' statement: " + deviate);
}
}
instance.setReference(reference);
}
- private static class DeviationImpl implements Deviation {
+ private class DeviationImpl implements Deviation {
private final SchemaPath targetPath;
private Deviate deviate;
private String reference;
addedUnknownNodes.add(unknownNode);
}
- private static class ExtensionDefinitionImpl implements ExtensionDefinition {
+ private class ExtensionDefinitionImpl implements ExtensionDefinition {
private final QName qname;
private String argument;
private SchemaPath schemaPath;
result = prime * result + ((qname == null) ? 0 : qname.hashCode());
result = prime * result
+ ((schemaPath == null) ? 0 : schemaPath.hashCode());
- result = prime
- * result
- + ((unknownNodes == null) ? 0
- : unknownNodes.hashCode());
- result = prime * result + (yin ? 1231 : 1237);
return result;
}
} else if (!schemaPath.equals(other.schemaPath)) {
return false;
}
- if (unknownNodes == null) {
- if (other.unknownNodes != null) {
- return false;
- }
- } else if (!unknownNodes.equals(other.unknownNodes)) {
- return false;
- }
- if (yin != other.yin) {
- return false;
- }
return true;
}
addedUnknownNodes.add(unknownNode);
}
- private static class FeatureDefinitionImpl implements FeatureDefinition {
+ private class FeatureDefinitionImpl implements FeatureDefinition {
private final QName qname;
private SchemaPath path;
private String description;
final int prime = 31;
int result = 1;
result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
return result;
}
} else if (!qname.equals(other.qname)) {
return false;
}
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
return true;
}
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
import org.opendaylight.controller.yang.model.util.IdentityrefType;
import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
/**
* Builder for YANG union type. User can add type to this union as
* types.
*/
public class IdentityrefTypeBuilder extends AbstractTypeAwareBuilder implements
- TypeDefinitionBuilder, Builder {
+ TypeDefinitionBuilder {
+ private static final String NAME = "identityref";
+
private final int line;
private final String baseString;
private final SchemaPath schemaPath;
private QName baseQName;
-
- public IdentityrefTypeBuilder(final String baseString, final SchemaPath schemaPath, final int line) {
+ IdentityrefTypeBuilder(final String baseString,
+ final SchemaPath schemaPath, final int line) {
this.line = line;
this.baseString = baseString;
this.schemaPath = schemaPath;
}
+ @Override
+ public IdentityrefType build() {
+ return new IdentityrefType(baseQName, schemaPath);
+ }
+
public String getBaseString() {
return baseString;
}
@Override
public void setType(final TypeDefinition<?> type) {
- throw new IllegalStateException("Can not set type to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set type to " + NAME);
}
@Override
public void setType(final TypeDefinitionBuilder tdb) {
- throw new IllegalStateException("Can not set type to "
- + IdentityrefTypeBuilder.class.getSimpleName());
- }
-
- @Override
- public IdentityrefType build() {
- return new IdentityrefType(baseQName, schemaPath);
+ throw new YangParseException(line, "Can not set type to " + NAME);
}
@Override
public void setPath(final SchemaPath schemaPath) {
- throw new IllegalStateException("Can not set path to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set path to " + NAME);
}
@Override
public void setDescription(final String description) {
- throw new IllegalStateException("Can not set description to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set description to " + NAME);
}
@Override
public void setReference(final String reference) {
- throw new IllegalStateException("Can not set reference to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set reference to " + NAME);
}
@Override
public void setStatus(final Status status) {
- throw new IllegalStateException("Can not set status to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set status to " + NAME);
}
@Override
public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- throw new IllegalStateException("Can not add unknown node to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not add unknown node to "
+ + NAME);
}
@Override
@Override
public void setRanges(List<RangeConstraint> ranges) {
- throw new IllegalStateException("Can not set ranges to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set ranges to " + NAME);
}
@Override
@Override
public void setLengths(List<LengthConstraint> lengths) {
- throw new IllegalStateException("Can not set lengths to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set lengths to " + NAME);
}
@Override
@Override
public void setPatterns(List<PatternConstraint> patterns) {
- throw new IllegalStateException("Can not set patterns to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set patterns to " + NAME);
}
@Override
@Override
public void setFractionDigits(Integer fractionDigits) {
- throw new IllegalStateException("Can not set fraction digits to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set fraction digits to "
+ + NAME);
}
@Override
@Override
public void setDefaultValue(Object defaultValue) {
- throw new IllegalStateException("Can not set default value to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set default value to "
+ + NAME);
}
@Override
@Override
public void setUnits(String units) {
- throw new IllegalStateException("Can not set units to "
- + IdentityrefTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set units to " + NAME);
}
@Override
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
public class ListSchemaNodeBuilder extends AbstractChildNodeBuilder implements
- DataSchemaNodeBuilder, SchemaNodeBuilder, AugmentationTargetBuilder,
+ DataSchemaNodeBuilder, AugmentationTargetBuilder,
TypeDefinitionAwareBuilder {
private final ListSchemaNodeImpl instance;
private final int line;
// AugmentationTarget args
private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
// ListSchemaNode args
- private List<QName> keyDefinition;
+ private List<QName> keyDefinition = Collections.emptyList();
private boolean userOrdered;
public ListSchemaNodeBuilder(final QName qname, final int line) {
}
public void setKeyDefinition(final List<QName> keyDefinition) {
- this.keyDefinition = keyDefinition;
+ if (keyDefinition != null) {
+ this.keyDefinition = keyDefinition;
+ }
}
public boolean isAugmenting() {
public String toString() {
StringBuilder sb = new StringBuilder(
ModuleImpl.class.getSimpleName());
- sb.append("[\n");
- sb.append("name=" + name + ",\n");
- sb.append("namespace=" + namespace + ",\n");
- sb.append("revision=" + revision + ",\n");
- sb.append("prefix=" + prefix + ",\n");
- sb.append("yangVersion=" + yangVersion + ",\n");
- sb.append("description=" + description + ",\n");
- sb.append("reference=" + reference + ",\n");
- sb.append("organization=" + organization + ",\n");
- sb.append("contact=" + contact + ",\n");
- sb.append("childNodes=" + childNodes.values() + ",\n");
- sb.append("groupings=" + groupings + ",\n");
- sb.append("imports=" + imports + ",\n");
- sb.append("features=" + features + ",\n");
- sb.append("typeDefinitions=" + typeDefinitions + ",\n");
- sb.append("notifications=" + notifications + ",\n");
- sb.append("augmentations=" + augmentations + ",\n");
- sb.append("rpcs=" + rpcs + ",\n");
- sb.append("deviations=" + deviations + "\n");
- sb.append("uses=" + uses + "\n");
+ sb.append("[");
+ sb.append("name=" + name);
+ sb.append(", namespace=" + namespace);
+ sb.append(", revision=" + revision);
+ sb.append(", prefix=" + prefix);
+ sb.append(", yangVersion=" + yangVersion);
sb.append("]");
return sb.toString();
}
return true;
}
- private static class RpcDefinitionImpl implements RpcDefinition {
-
+ private class RpcDefinitionImpl implements RpcDefinition {
private final QName qname;
private SchemaPath path;
private String description;
final int prime = 31;
int result = 1;
result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
return result;
}
} else if (!qname.equals(other.qname)) {
return false;
}
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
return true;
}
import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
import org.opendaylight.controller.yang.model.util.UnionType;
import org.opendaylight.controller.yang.parser.builder.api.AbstractTypeAwareBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.Builder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
/**
* Builder for YANG union type. User can add type to this union as
* types.
*/
public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
- TypeDefinitionBuilder, Builder {
- private final static String CLASS_NAME = UnionTypeBuilder.class
- .getSimpleName();
+ TypeDefinitionBuilder {
+ private final static String NAME = "union";
private final int line;
private final List<TypeDefinition<?>> types;
@Override
public void setPath(final SchemaPath schemaPath) {
- throw new IllegalStateException("Can not set path to " + CLASS_NAME);
+ throw new YangParseException(line, "Can not set path to " + NAME);
}
@Override
public void setDescription(final String description) {
- throw new IllegalStateException("Can not set description to "
- + CLASS_NAME);
+ throw new YangParseException(line, "Can not set description to " + NAME);
}
@Override
public void setReference(final String reference) {
- throw new IllegalStateException("Can not set reference to "
- + CLASS_NAME);
+ throw new YangParseException(line, "Can not set reference to " + NAME);
}
@Override
public void setStatus(final Status status) {
- throw new IllegalStateException("Can not set status to " + CLASS_NAME);
+ throw new YangParseException(line, "Can not set status to " + NAME);
}
@Override
public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
- throw new IllegalStateException("Can not add unknown node to "
- + CLASS_NAME);
+ throw new YangParseException(line, "Can not add unknown node to "
+ + NAME);
}
@Override
@Override
public void setRanges(List<RangeConstraint> ranges) {
- throw new IllegalStateException("Can not set ranges to "
- + UnionTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set ranges to " + NAME);
}
@Override
@Override
public void setLengths(List<LengthConstraint> lengths) {
- throw new IllegalStateException("Can not set lengths to "
- + UnionTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set lengths to " + NAME);
}
@Override
@Override
public void setPatterns(List<PatternConstraint> patterns) {
- throw new IllegalStateException("Can not set patterns to "
- + UnionTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set patterns to " + NAME);
}
@Override
@Override
public void setFractionDigits(Integer fractionDigits) {
- throw new IllegalStateException("Can not set fraction digits to "
- + UnionTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set fraction digits to "
+ + NAME);
}
@Override
@Override
public void setDefaultValue(Object defaultValue) {
- throw new IllegalStateException("Can not set default value to "
- + UnionTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set default value to "
+ + NAME);
}
@Override
@Override
public void setUnits(String units) {
- throw new IllegalStateException("Can not set units to "
- + UnionTypeBuilder.class.getSimpleName());
+ throw new YangParseException(line, "Can not set units to " + NAME);
}
public List<String> getActualPath() {
import org.opendaylight.controller.yang.model.api.SchemaPath;\r
import org.opendaylight.controller.yang.model.api.UsesNode;\r
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;\r
-import org.opendaylight.controller.yang.parser.builder.api.Builder;\r
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;\r
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;\r
import org.opendaylight.controller.yang.parser.util.RefineHolder;\r
\r
-final class UsesNodeBuilderImpl implements UsesNodeBuilder, Builder {\r
+final class UsesNodeBuilderImpl implements UsesNodeBuilder {\r
private final UsesNodeImpl instance;\r
private final int line;\r
private final SchemaPath groupingPath;\r
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.yang.parser.impl;
-
-/**
- * Unchecked exception thrown if yang definition is not valid according to
- * {@link YangModelValidationListener}
- */
-public class YangValidationException extends RuntimeException {
-
- private static final long serialVersionUID = 7414330400390825381L;
-
- public YangValidationException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public YangValidationException(String message) {
- super(message);
- }
-
-}
\ No newline at end of file
return result;
}
+ /**
+ * Parse type body and return pattern constraints.
+ *
+ * @param ctx
+ * type body
+ * @return list of pattern constraints
+ */
private static List<PatternConstraint> getPatternConstraint(
final Type_body_stmtsContext ctx) {
List<PatternConstraint> patterns = new ArrayList<PatternConstraint>();
}
/**
- * Get fraction digits value from context.
+ * Get fraction digits value from type body.
*
* @param ctx
* type body context to parse
return result;
}
+ /**
+ * Parse decimal64 fraction-digits value.
+ *
+ * @param ctx
+ * decimal64 context
+ * @return fraction-digits value as Integer
+ */
private static Integer parseFractionDigits(
Decimal64_specificationContext ctx) {
Integer result = null;
public static TypeDefinition<?> parseUnknownTypeBody(QName typedefQName,
Type_body_stmtsContext ctx) {
UnknownType.Builder unknownType = new UnknownType.Builder(typedefQName);
-
if (ctx != null) {
List<RangeConstraint> rangeStatements = getRangeConstraints(ctx);
List<LengthConstraint> lengthStatements = getLengthConstraints(ctx);
unknownType.patterns(patternStatements);
unknownType.fractionDigits(fractionDigits);
}
-
return unknownType.build();
}
type = new Decimal64(actualPath, namespace, revision,
fractionDigits);
} else if (typeName.startsWith("int")) {
- if (typeName.equals("int8")) {
+ if ("int8".equals(typeName)) {
type = new Int8(actualPath, namespace, revision,
rangeStatements, null, null);
- } else if (typeName.equals("int16")) {
+ } else if ("int16".equals(typeName)) {
type = new Int16(actualPath, namespace, revision,
rangeStatements, null, null);
- } else if (typeName.equals("int32")) {
+ } else if ("int32".equals(typeName)) {
type = new Int32(actualPath, namespace, revision,
rangeStatements, null, null);
- } else if (typeName.equals("int64")) {
+ } else if ("int64".equals(typeName)) {
type = new Int64(actualPath, namespace, revision,
rangeStatements, null, null);
}
} else if (typeName.startsWith("uint")) {
- if (typeName.equals("uint8")) {
+ if ("uint8".equals(typeName)) {
type = new Uint8(actualPath, namespace, revision,
rangeStatements, null, null);
- } else if (typeName.equals("uint16")) {
+ } else if ("uint16".equals(typeName)) {
type = new Uint16(actualPath, namespace, revision,
rangeStatements, null, null);
- } else if (typeName.equals("uint32")) {
+ } else if ("uint32".equals(typeName)) {
type = new Uint32(actualPath, namespace, revision,
rangeStatements, null, null);
- } else if (typeName.equals("uint64")) {
+ } else if ("uint64".equals(typeName)) {
type = new Uint64(actualPath, namespace, revision,
rangeStatements, null, null);
}
return type;
}
+ /**
+ * Parse given context and find identityref base value.
+ *
+ * @param ctx
+ * type body
+ * @return identityref base value as String
+ */
public static String getIdentityrefBase(Type_body_stmtsContext ctx) {
String result = null;
outer: for (int i = 0; i < ctx.getChildCount(); i++) {
return result;
}
+ /**
+ * Parse given context and find require-instance value.
+ *
+ * @param ctx
+ * type body
+ * @return require-instance value
+ */
private static boolean isRequireInstance(Type_body_stmtsContext ctx) {
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
return false;
}
+ /**
+ * Parse given context and find leafref path.
+ *
+ * @param ctx
+ * type body
+ * @return leafref path as String
+ */
private static String parseLeafrefPath(Type_body_stmtsContext ctx) {
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
} else if ("leafref".equals(typeName)) {
throw new YangParseException(moduleName, line,
"The 'path' statement MUST be present if the type is 'leafref'.");
- } else if("bits".equals(typeName)) {
+ } else if ("bits".equals(typeName)) {
throw new YangParseException(moduleName, line,
"The 'bit' statement MUST be present if the type is 'bits'.");
- } else if("enumeration".equals(typeName)) {
+ } else if ("enumeration".equals(typeName)) {
throw new YangParseException(moduleName, line,
"The 'enum' statement MUST be present if the type is 'enumeration'.");
}
}
- public static RefineHolder parseRefine(Refine_stmtContext child) {
- final String refineTarget = stringFromNode(child);
- final RefineHolder refine = new RefineHolder(refineTarget, child
+ /**
+ * Parse refine statement.
+ * @param refineCtx refine statement
+ * @return
+ */
+ public static RefineHolder parseRefine(Refine_stmtContext refineCtx) {
+ final String refineTarget = stringFromNode(refineCtx);
+ final RefineHolder refine = new RefineHolder(refineTarget, refineCtx
.getStart().getLine());
- for (int j = 0; j < child.getChildCount(); j++) {
- ParseTree refinePom = child.getChild(j);
+ for (int j = 0; j < refineCtx.getChildCount(); j++) {
+ ParseTree refinePom = refineCtx.getChild(j);
if (refinePom instanceof Refine_pomContext) {
for (int k = 0; k < refinePom.getChildCount(); k++) {
ParseTree refineStmt = refinePom.getChild(k);
import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition.Bit;
import org.opendaylight.controller.yang.model.api.type.EnumTypeDefinition.EnumPair;
@Test
public void testEnumeration() {
- Module tested = TestUtils.findModule(testedModules, "custom-types-test");
+ Module tested = TestUtils
+ .findModule(testedModules, "custom-types-test");
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version");
EnumPair value3 = values.get(3);
assertEquals("default", value3.getName());
assertEquals(20, (int) value3.getValue());
- assertEquals("default ip",
- value3.getDescription());
+ assertEquals("default ip", value3.getDescription());
}
@Test
assertEquals(502L, (long) bit4.getPosition());
}
-
@Test
public void testIanaTimezones() {
Module tested = TestUtils.findModule(testedModules, "iana-timezones");
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs,
"iana-timezone");
- /*
- // FIXME: Refactor sources not to be timezone specific.
- String expectedDesc = "A timezone location as defined by the IANA timezone\n database (http://www.iana.org/time-zones)";
- assertEquals(expectedDesc, testedType.getDescription());
+
+ String expectedDesc = "A timezone location as defined by the IANA timezone";
+ assertTrue(testedType.getDescription().contains(expectedDesc));
assertNull(testedType.getReference());
assertEquals(Status.CURRENT, testedType.getStatus());
- */
+
QName testedTypeQName = testedType.getQName();
assertEquals(URI.create("urn:ietf:params:xml:ns:yang:iana-timezones"),
testedTypeQName.getNamespace());
Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs,
"service-type-ref");
- IdentityrefType baseType = (IdentityrefType)testedType.getBaseType();
+ IdentityrefType baseType = (IdentityrefType) testedType.getBaseType();
QName identity = baseType.getIdentity();
- assertEquals(URI.create("urn:simple.container.demo"), identity.getNamespace());
+ assertEquals(URI.create("urn:simple.container.demo"),
+ identity.getNamespace());
assertEquals(TestUtils.createDate("2012-04-16"), identity.getRevision());
assertEquals("iit", identity.getPrefix());
assertEquals("service-type", identity.getLocalName());
.getDataChildByName("ifEntry");
ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry
.getDataChildByName("augment-holder");
- // Set<AugmentationSchema> augmentedContainerAugments =
- // augmentedContainer
- // .getAvailableAugmentations();
+
+ // augmentation defined in testfile1 and augmentation returned from
+ // augmented container have to be same
+ Set<AugmentationSchema> augmentedContainerAugments = augmentedContainer
+ .getAvailableAugmentations();
+ AugmentationSchema augmentDefinition = augmentedContainerAugments
+ .iterator().next();
+ assertEquals(augment1, augmentDefinition);
+
LeafSchemaNode augmentedLeaf = (LeafSchemaNode) augmentedContainer
.getDataChildByName("ds0ChannelNumber");
assertTrue(augmentedLeaf.isAugmenting());
Set<AugmentationSchema> module3Augmentations = module3
.getAugmentations();
assertEquals(2, module3Augmentations.size());
- // AugmentationSchema augment3 = module3Augmentations.iterator().next();
- // ContainerSchemaNode augmentedContainerDefinition =
- // (ContainerSchemaNode) augment3
- // .getDataChildByName("augment-holder");
- // assertTrue(augmentedContainerDefinition.isAugmenting());
- //
- // // check
- // assertEquals(augmentedContainer, augmentedContainerDefinition);
- // assertEquals(augmentedContainerAugments.iterator().next(), augment1);
- //
- // assertEquals(augmentedLeaf, augmentedLeafDefinition);
- // assertEquals(ifEntryAugments.iterator().next(), augment3);
+ AugmentationSchema augment3 = null;
+ for (AugmentationSchema as : module3Augmentations) {
+ if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
+ augment3 = as;
+ }
+ }
+ ContainerSchemaNode augmentedContainerDefinition = (ContainerSchemaNode) augment3
+ .getDataChildByName("augment-holder");
+ assertTrue(augmentedContainerDefinition.isAugmenting());
+
+ // check
+ assertEquals(augmentedContainer, augmentedContainerDefinition);
+ assertEquals(augmentedContainerAugments.iterator().next(), augment1);
+
+ assertEquals(augmentedLeaf, augmentedLeafDefinition);
+ assertEquals(ifEntryAugments.iterator().next(), augment3);
}
@Test
.getAvailableAugmentations();
assertEquals(2, augmentations.size());
- // AugmentationSchema augment = augmentations.iterator().next();
-
- // ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment
- // .getDataChildByName("augment-holder");
- // assertNotNull(augmentHolder);
- // assertTrue(augmentHolder.isAugmenting());
- // QName augmentHolderQName = augmentHolder.getQName();
- // assertEquals("augment-holder", augmentHolderQName.getLocalName());
- // assertEquals("t3", augmentHolderQName.getPrefix());
- // assertEquals("Description for augment holder",
- // augmentHolder.getDescription());
+ AugmentationSchema augment = null;
+ for (AugmentationSchema as : augmentations) {
+ if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
+ augment = as;
+ }
+ }
+ ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment
+ .getDataChildByName("augment-holder");
+ assertNotNull(augmentHolder);
+ assertTrue(augmentHolder.isAugmenting());
+ QName augmentHolderQName = augmentHolder.getQName();
+ assertEquals("augment-holder", augmentHolderQName.getLocalName());
+ assertEquals("t3", augmentHolderQName.getPrefix());
+ assertEquals("Description for augment holder",
+ augmentHolder.getDescription());
}
@Test
List<RangeConstraint> ranges = leafType.getRanges();
assertEquals(1, ranges.size());
RangeConstraint range = ranges.get(0);
- assertEquals(11L, range.getMin());
+ assertEquals(3L, range.getMin());
assertEquals(20L, range.getMax());
}
typedef my-type1 {
type my-base-int32-type {
- range "11..max";
+ range "3..9|11..max";
}
units "mile";
default "11";
*/\r
package org.opendaylight.controller.yang.model.api;\r
\r
-import java.util.Set;\r
-\r
+/**\r
+ * AugmentationSchema represents augment definition. The "augment" statement\r
+ * allows a module or submodule to add to the schema tree defined in an external\r
+ * module, or the current module and its submodules, and to add to the nodes\r
+ * from a grouping in a "uses" statement.\r
+ */\r
public interface AugmentationSchema extends DataNodeContainer {\r
\r
+ /**\r
+ * @return when statement\r
+ */\r
RevisionAwareXPath getWhenCondition();\r
\r
+ /**\r
+ * @return textual description of this augment.\r
+ */\r
String getDescription();\r
\r
+ /**\r
+ * @return textual cross-reference to an external document that provides\r
+ * additional information relevant to this node.\r
+ */\r
String getReference();\r
\r
+ /**\r
+ * @return actual status of this node.\r
+ */\r
Status getStatus();\r
\r
+ /**\r
+ * @return SchemaPath that identifies a node in the schema tree. This node\r
+ * is called the augment's target node. The target node MUST be\r
+ * either a container, list, choice, case, input, output, or\r
+ * notification node. It is augmented with the nodes defined as\r
+ * child nodes of this AugmentationSchema.\r
+ */\r
SchemaPath getTargetPath();\r
\r
- Set<UsesNode> getUses();\r
-\r
}\r
\r
import java.util.Set;\r
\r
+/**\r
+ * Interface for all nodes which are possible targets of augmentation. The\r
+ * target node of augmentation MUST be either a container, list, choice, case,\r
+ * input, output, or notification node.\r
+ */\r
public interface AugmentationTarget {\r
+\r
/**\r
- * Returns a set of augmentations targeting this element.\r
- * \r
- * @return\r
+ * @return set of augmentations targeting this element.\r
*/\r
Set<AugmentationSchema> getAvailableAugmentations();\r
+\r
}\r
*/\r
package org.opendaylight.controller.yang.model.api;\r
\r
+/**\r
+ * The ChoiceCaseNode interface is used to define branches of the ChoiceNode.\r
+ */\r
public interface ChoiceCaseNode extends DataSchemaNode, DataNodeContainer,\r
AugmentationTarget {\r
\r
import java.util.Set;
+/**
+ * The ChoiceNode defines a set of alternatives. It consists of a number of
+ * branches defined as ChoiceCaseNode objects.
+ */
public interface ChoiceNode extends DataSchemaNode, AugmentationTarget {
+ /**
+ * @return ChoiceCaseNode objects defined in this node
+ */
Set<ChoiceCaseNode> getCases();
+
}
import java.util.Set;\r
\r
public interface ConstraintDefinition {\r
- DataSchemaNode getParent();\r
\r
RevisionAwareXPath getWhenCondition();\r
\r
*/\r
package org.opendaylight.controller.yang.model.api;\r
\r
+/**\r
+ * The ContainerSchemaNode is used to define an interior data node in the schema\r
+ * tree. There are two styles of containers, those that exist only for\r
+ * organizing the hierarchy of data nodes, and those whose presence in the\r
+ * configuration has an explicit meaning.\r
+ */\r
public interface ContainerSchemaNode extends DataNodeContainer,\r
AugmentationTarget, DataSchemaNode {\r
\r
+ /**\r
+ * @return true, if presence of this container has an explicit meaning,\r
+ * false otherwise\r
+ */\r
boolean isPresenceContainer();\r
\r
}\r
\r
import org.opendaylight.controller.yang.common.QName;\r
\r
+/**\r
+ * Node which can contains other nodes.\r
+ */\r
public interface DataNodeContainer {\r
\r
+ /**\r
+ * @return Set of all newly defined types within this DataNodeContainer\r
+ */\r
Set<TypeDefinition<?>> getTypeDefinitions();\r
\r
+ /**\r
+ * Set of all child nodes defined within this DataNodeContainer\r
+ */\r
Set<DataSchemaNode> getChildNodes();\r
\r
+ /**\r
+ * Set of all groupings defined within this DataNodeContainer\r
+ */\r
Set<GroupingDefinition> getGroupings();\r
\r
+ /**\r
+ * @param name\r
+ * QName of seeked child\r
+ * @return child node of this DataNodeContainer if child with given name is\r
+ * present, null otherwise\r
+ */\r
DataSchemaNode getDataChildByName(QName name);\r
\r
+ /**\r
+ * @param name\r
+ * name of seeked child as String\r
+ * @return child node of this DataNodeContainer if child with given name is\r
+ * present, null otherwise\r
+ */\r
DataSchemaNode getDataChildByName(String name);\r
\r
+ /**\r
+ * @return Set of all uses nodes defined within this DataNodeContainer\r
+ */\r
Set<UsesNode> getUses();\r
\r
}\r
\r
import org.opendaylight.controller.yang.common.QName;\r
\r
+/**\r
+ * SchemaNode represents a node in schema tree.\r
+ */\r
public interface SchemaNode {\r
\r
public QName getQName();\r
\r
public SchemaPath getPath();\r
\r
+ /**\r
+ * @return textual description of this node.\r
+ */\r
public String getDescription();\r
\r
+ /**\r
+ * @return textual cross-reference to an external document that provides\r
+ * additional information relevant to this node.\r
+ */\r
public String getReference();\r
\r
+ /**\r
+ * @return actual status of this node.\r
+ */\r
public Status getStatus();\r
\r
+ /**\r
+ * @return collection of all unknown nodes defined under this schema node.\r
+ */\r
public List<UnknownSchemaNode> getUnknownSchemaNodes();\r
+\r
}\r
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, containerName, this);
List<Map<String, String>> nodeData = new ArrayList<Map<String, String>>();
- for (Switch device : switchManager.getNetworkDevices()) {
- HashMap<String, String> nodeDatum = new HashMap<String, String>();
- Node node = device.getNode();
- Tier tier = (Tier) switchManager.getNodeProp(node,
- Tier.TierPropName);
-
- nodeDatum.put("containerName", containerName);
- nodeDatum.put("nodeName", switchManager.getNodeDescription(node));
- nodeDatum.put("nodeId", node.toString());
- int tierNumber = (tier == null) ? TierHelper.unknownTierNumber
- : tier.getValue();
- nodeDatum.put("tierName", TierHelper.getTierName(tierNumber)
- + " (Tier-" + tierNumber + ")");
- nodeDatum.put("tier", tierNumber + "");
- SwitchConfig sc = switchManager.getSwitchConfig(device.getNode()
- .toString());
- String modeStr = (sc != null) ? sc.getMode() : "0";
- nodeDatum.put("mode", modeStr);
-
- nodeDatum.put("json", gson.toJson(nodeDatum));
- nodeDatum.put("mac",
- HexEncode.bytesToHexString(device.getDataLayerAddress()));
- StringBuffer sb1 = new StringBuffer();
- Set<NodeConnector> nodeConnectorSet = device.getNodeConnectors();
- if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) {
- Map<Short, String> portList = new HashMap<Short, String>();
- for (NodeConnector nodeConnector : nodeConnectorSet) {
- String nodeConnectorNumberToStr = nodeConnector.getID().toString();
- Name ncName = ((Name) switchManager.getNodeConnectorProp(
- nodeConnector, Name.NamePropName));
- Config portStatus = ((Config) switchManager
- .getNodeConnectorProp(nodeConnector,
- Config.ConfigPropName));
-
- String nodeConnectorName = (ncName != null) ? ncName.getValue()
- : "";
- nodeConnectorName += " ("+nodeConnector.getID()+")";
-
- if (portStatus != null) {
- if (portStatus.getValue() == Config.ADMIN_UP) {
- nodeConnectorName = "<span style='color:green;'>"+nodeConnectorName+"</span>";
- } else if (portStatus.getValue() == Config.ADMIN_DOWN) {
- nodeConnectorName = "<span style='color:red;'>"+nodeConnectorName+"</span>";
+ if (switchManager != null) {
+ for (Switch device : switchManager.getNetworkDevices()) {
+ HashMap<String, String> nodeDatum = new HashMap<String, String>();
+ Node node = device.getNode();
+ Tier tier = (Tier) switchManager.getNodeProp(node,
+ Tier.TierPropName);
+
+ nodeDatum.put("containerName", containerName);
+ nodeDatum.put("nodeName",
+ switchManager.getNodeDescription(node));
+ nodeDatum.put("nodeId", node.toString());
+ int tierNumber = (tier == null) ? TierHelper.unknownTierNumber
+ : tier.getValue();
+ nodeDatum.put("tierName", TierHelper.getTierName(tierNumber)
+ + " (Tier-" + tierNumber + ")");
+ nodeDatum.put("tier", tierNumber + "");
+ SwitchConfig sc = switchManager.getSwitchConfig(device
+ .getNode().toString());
+ String modeStr = (sc != null) ? sc.getMode() : "0";
+ nodeDatum.put("mode", modeStr);
+
+ nodeDatum.put("json", gson.toJson(nodeDatum));
+ nodeDatum.put("mac", HexEncode.bytesToHexString(device
+ .getDataLayerAddress()));
+ StringBuffer sb1 = new StringBuffer();
+ Set<NodeConnector> nodeConnectorSet = device
+ .getNodeConnectors();
+ if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) {
+ Map<Short, String> portList = new HashMap<Short, String>();
+ for (NodeConnector nodeConnector : nodeConnectorSet) {
+ String nodeConnectorNumberToStr = nodeConnector.getID()
+ .toString();
+ Name ncName = ((Name) switchManager
+ .getNodeConnectorProp(nodeConnector,
+ Name.NamePropName));
+ Config portStatus = ((Config) switchManager
+ .getNodeConnectorProp(nodeConnector,
+ Config.ConfigPropName));
+
+ String nodeConnectorName = (ncName != null) ? ncName
+ .getValue() : "";
+ nodeConnectorName += " (" + nodeConnector.getID() + ")";
+
+ if (portStatus != null) {
+ if (portStatus.getValue() == Config.ADMIN_UP) {
+ nodeConnectorName = "<span style='color:green;'>"
+ + nodeConnectorName + "</span>";
+ } else if (portStatus.getValue() == Config.ADMIN_DOWN) {
+ nodeConnectorName = "<span style='color:red;'>"
+ + nodeConnectorName + "</span>";
+ }
}
+
+ portList.put(
+ Short.parseShort(nodeConnectorNumberToStr),
+ nodeConnectorName);
}
-
- portList.put(Short.parseShort(nodeConnectorNumberToStr),
- nodeConnectorName);
- }
- Map<Short, String> sortedPortList = new TreeMap<Short, String>(portList);
+ Map<Short, String> sortedPortList = new TreeMap<Short, String>(
+ portList);
- for (Entry<Short, String> e : sortedPortList.entrySet()) {
- sb1.append(e.getValue());
- sb1.append("<br>");
+ for (Entry<Short, String> e : sortedPortList.entrySet()) {
+ sb1.append(e.getValue());
+ sb1.append("<br>");
+ }
}
+ nodeDatum.put("ports", sb1.toString());
+ nodeData.add(nodeDatum);
}
- nodeDatum.put("ports", sb1.toString());
- nodeData.add(nodeDatum);
}
+
DevicesJsonBean result = new DevicesJsonBean();
result.setNodeData(nodeData);
List<String> columnNames = new ArrayList<String>();
String containerName = DaylightWebUtil.getAuthorizedContainer(request, container, this);
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, containerName, this);
- for (SubnetConfig conf : switchManager.getSubnetsConfigList()) {
- Map<String, String> subnet = new HashMap<String, String>();
- subnet.put("name", conf.getName());
- subnet.put("subnet", conf.getSubnet());
- subnet.put("json", gson.toJson(conf));
- subnets.add(subnet);
+ if (switchManager != null) {
+ for (SubnetConfig conf : switchManager.getSubnetsConfigList()) {
+ Map<String, String> subnet = new HashMap<String, String>();
+ subnet.put("name", conf.getName());
+ subnet.put("subnet", conf.getSubnet());
+ subnet.put("json", gson.toJson(conf));
+ subnets.add(subnet);
+ }
}
DevicesJsonBean result = new DevicesJsonBean();
result.setColumnNames(SubnetConfig.getGuiFieldsNames());
String containerName = DaylightWebUtil.getAuthorizedContainer(request, container, this);
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, containerName, this);
- for (SpanConfig conf : switchManager.getSpanConfigList()) {
- spanConfigs_json.add(gson.toJson(conf));
+ if (switchManager != null) {
+ for (SpanConfig conf : switchManager.getSpanConfigList()) {
+ spanConfigs_json.add(gson.toJson(conf));
+ }
}
ObjectMapper mapper = new ObjectMapper();
List<Map<String, String>> spanConfigs = new ArrayList<Map<String, String>>();
String containerName = DaylightWebUtil.getAuthorizedContainer(request, container, this);
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, containerName, this);
- if (switchManager == null)
+ if (switchManager == null) {
return null;
+ }
Map<String, Object> nodes = new HashMap<String, Object>();
Map<Short, String> port;