Refactored refine statement parsing.
Change-Id: Ic00b86c611f1f56b69d9e09bf197d9ddb79da145
Signed-off-by: Martin Vitez <mvitez@cisco.com>
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