} else if (typeStr.equals(NodeIDType.PRODUCTION)) {
this.nodeID = IDStr;
} else {
- // We need to lookup via OSGi service registry for an
- // handler for this
+ //Use plugin's method to get appropriate conversion from IDStr to nodeID
+ INodeFactory f = (INodeFactory) ServiceHelper
+ .getGlobalInstance(INodeFactory.class, new Node(), "(protocolName="+typeStr+")");
+ if(f!=null){
+ Node n = f.fromString(typeStr, IDStr);
+ this.nodeID = n.nodeID;
+ }
}
}
import java.util.LinkedHashMap;
import java.util.Map;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@Override
public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this);
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((fieldValues == null) ? 0 : fieldValues.hashCode());
+ return result;
}
@Override
public boolean equals(Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj);
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ARP other = (ARP) obj;
+ if (fieldValues == null) {
+ if (other.fieldValues != null)
+ return false;
+ } else if (!fieldValues.equals(other.fieldValues))
+ return false;
+ return true;
}
}
* Deriving the Total Length here
*/
int payloadLength = 0;
- try {
- payloadLength = payload.serialize().length;
- } catch (PacketException e) {
- logger.error("", e);
+ if (payload != null) {
+ try {
+ payloadLength = payload.serialize().length;
+ } catch (PacketException e) {
+ logger.error("", e);
+ }
}
this.setTotalLength((short) (this.getHeaderLen() + payloadLength));
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
-import java.util.HashMap;
-
import java.util.Arrays;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
+
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.opendaylight.controller.sal.utils.HexEncode;
@Override
public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this);
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((fieldValues == null) ? 0 : fieldValues.hashCode());
+ return result;
}
@Override
public boolean equals(Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj);
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ LLDPTLV other = (LLDPTLV) obj;
+ if (fieldValues == null) {
+ if (other.fieldValues != null)
+ return false;
+ } else if (!fieldValues.equals(other.fieldValues))
+ return false;
+ return true;
}
@Override
/**
* Returns the size in bits of the whole TLV
- *
+ *
* @return int - size in bits of full TLV
*/
public int getTLVSize() {
/**
* Creates the ChassisID TLV value including the subtype and ChassisID
* string
- *
+ *
* @param nodeId
* node identifier string
* @return the ChassisID TLV value in byte array
/**
* Creates the PortID TLV value including the subtype and PortID string
- *
+ *
* @param portId
* port identifier string
* @return the PortID TLV value in byte array
/**
* Creates the custom TLV value including OUI, subtype and custom string
- *
+ *
* @param portId
* port identifier string
* @return the custom TLV value in byte array
/**
* Retrieves the string from TLV value and returns it in HexString format
- *
+ *
* @param tlvValue
* the TLV value
* @param tlvLen
/**
* Retrieves the string from TLV value
- *
+ *
* @param tlvValue
* the TLV value
* @param tlvLen
/**
* Retrieves the custom string from the Custom TLV value which includes OUI,
* subtype and custom string
- *
+ *
* @param customTlvValue
* the custom TLV value
* @param customTlvLen
/**
* This method deserializes the data bits obtained from the wire into the
* respective header and payload which are of type Packet
- *
+ *
* @param byte[] data - data from wire to deserialize
* @param int bitOffset bit position where packet header starts in data
* array
/**
* This method serializes the header and payload from the respective
* packet class, into a single stream of bytes to be sent on the wire
- *
+ *
* @return The byte array representing the serialized Packet
* @throws PacketException
*/
* byte stream which cannot be done or cannot be done efficiently during the
* normal Packet.serialize() path. An example is the checksum computation
* for IPv4
- *
+ *
* @param byte[] - serialized bytes
* @throws PacketException
*/
* of checksum varies based on the protocol, this method is overridden.
* Currently only IPv4 and ICMP do checksum computation and validation. TCP
* and UDP need to implement these if required.
- *
+ *
* @param byte[] data The byte stream representing the Ethernet frame
* @param int startBitOffset The bit offset from where the byte array corresponding to this Packet starts in the frame
* @throws PacketException
/**
* Gets the header length in bits
- *
+ *
* @return int the header length in bits
*/
public int getHeaderSize() {
* This method fetches the start bit offset for header field specified by
* 'fieldname'. The offset is present in the hdrFieldCoordMap of the
* respective packet class
- *
+ *
* @param String
* fieldName
* @return Integer - startOffset of the requested field
* This method fetches the number of bits for header field specified by
* 'fieldname'. The numBits are present in the hdrFieldCoordMap of the
* respective packet class
- *
+ *
* @param String
* fieldName
* @return Integer - number of bits of the requested field
/**
* Returns the raw payload carried by this packet in case payload was not
* parsed. Caller can call this function in case the getPaylod() returns null.
- *
+ *
* @return The raw payload if not parsable as an array of bytes, null otherwise
*/
public byte[] getRawPayload() {
/**
* Set a raw payload in the packet class
- *
+ *
* @param payload The raw payload as byte array
*/
public void setRawPayload(byte[] payload) {
* packet received from wire is not equal to the checksum read from the
* stream. For the Packet class which do not have a checksum field, this
* function will always return false.
- *
- *
+ *
+ *
* @return true if the deserialized packet's recomputed checksum is not
* equal to the packet carried checksum
*/
default "1.2.3.4";
}
refine port {
- must "must-condition" {
- error-message "An error message test";
- error-app-tag "An error app tag test";
- }
+ description "new port description updated by refine";
}
}
}
import org.opendaylight.controller.yang.common.QName;
-public abstract class AbstractChildNodeBuilder implements ChildNodeBuilder {
+public abstract class AbstractDataNodeContainerBuilder implements DataNodeContainerBuilder {
private final QName qname;
protected final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
protected final Set<GroupingBuilder> groupings = new HashSet<GroupingBuilder>();
- protected AbstractChildNodeBuilder(QName qname) {
+ protected AbstractDataNodeContainerBuilder(QName qname) {
this.qname = qname;
}
}
@Override
- public void setType(TypeDefinitionBuilder typedef) {
+ public void setTypedef(TypeDefinitionBuilder typedef) {
this.typedef = typedef;
this.type = null;
}
/**
* Interface for builders of 'augment' statement.
*/
-public interface AugmentationSchemaBuilder extends ChildNodeBuilder {
+public interface AugmentationSchemaBuilder extends DataNodeContainerBuilder {
String getWhenCondition();
* Interface for all yang data-node containers [augment, case, container,
* grouping, list, module, notification].
*/
-public interface ChildNodeBuilder extends Builder {
+public interface DataNodeContainerBuilder extends Builder {
QName getQName();
+ Set<DataSchemaNodeBuilder> getChildNodes();
+
void addChildNode(DataSchemaNodeBuilder childNode);
void addGrouping(GroupingBuilder groupingBuilder);
void addUsesNode(UsesNodeBuilder usesBuilder);
- void addTypedef(TypeDefinitionBuilder typedefBuilder);
+ Set<TypeDefinitionBuilder> getTypeDefinitions();
- Set<DataSchemaNodeBuilder> getChildNodes();
+ void addTypedef(TypeDefinitionBuilder typedefBuilder);
SchemaPath getPath();
/**
* Interface for builders of 'grouping' statement.
*/
-public interface GroupingBuilder extends ChildNodeBuilder, SchemaNodeBuilder,
+public interface GroupingBuilder extends DataNodeContainerBuilder, SchemaNodeBuilder,
TypeDefinitionAwareBuilder {
String getDescription();
Set<GroupingBuilder> getGroupings();
- Set<TypeDefinitionBuilder> getTypedefs();
-
Set<UsesNodeBuilder> getUses();
}
package org.opendaylight.controller.yang.parser.builder.api;
import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
/**
QName getQName();
+ SchemaPath getPath();
+
TypeDefinition<?> getType();
TypeDefinitionBuilder getTypedef();
void setType(TypeDefinition<?> type);
- void setType(TypeDefinitionBuilder typedef);
+ void setTypedef(TypeDefinitionBuilder typedef);
}
import org.opendaylight.controller.yang.model.api.Status;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.util.YangParseException;
public final class AnyXmlBuilder implements DataSchemaNodeBuilder {
private boolean built;
private String reference;
private Status status = Status.CURRENT;
private boolean configuration;
+ private boolean augmenting;
public AnyXmlBuilder(final QName qname, final int line) {
this.qname = qname;
instance.setReference(reference);
instance.setStatus(status);
instance.setConfiguration(configuration);
+ instance.setAugmenting(augmenting);
// UNKNOWN NODES
final List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
@Override
public void setAugmenting(final boolean augmenting) {
- throw new YangParseException(line,
- "An anyxml node cannot be augmented.");
+ this.augmenting = augmenting;
}
public boolean isConfiguration() {
private Status status = Status.CURRENT;
private boolean configuration;
private ConstraintDefinition constraintsDef;
+ private boolean augmenting;
private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
private AnyXmlSchemaNodeImpl(final QName qname) {
@Override
public boolean isAugmenting() {
- return false;
+ return augmenting;
+ }
+
+ private void setAugmenting(boolean augmenting) {
+ this.augmenting = augmenting;
}
@Override
this.whenCondition = whenCondition;
}
+ @Override
+ public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ return Collections.emptySet();
+ }
+
@Override
public void addTypedef(TypeDefinitionBuilder type) {
throw new YangParseException(line,
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
-import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.controller.yang.parser.util.YangParseException;
-public final class ChoiceBuilder implements DataSchemaNodeBuilder,
- ChildNodeBuilder, AugmentationTargetBuilder {
+public final class ChoiceBuilder implements DataSchemaNodeBuilder, AugmentationTargetBuilder {
private boolean built;
private final ChoiceNodeImpl instance;
private final int line;
private boolean augmenting;
private boolean configuration;
private final ConstraintsBuilder constraints;
- // DataNodeContainer args
- private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
- private final Set<UsesNodeBuilder> addedUsesNodes = new HashSet<UsesNodeBuilder>();
// AugmentationTarget args
private final Set<AugmentationSchemaBuilder> addedAugmentations = new HashSet<AugmentationSchemaBuilder>();
// ChoiceNode args
return cases;
}
- @Override
public void addChildNode(DataSchemaNodeBuilder childNode) {
if (!(childNode instanceof ChoiceCaseBuilder)) {
ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(
return qname;
}
- /**
- * Choice can not contains grouping statements, so this method always
- * returns an empty set.
- *
- * @return empty set
- */
- public Set<GroupingBuilder> getGroupings() {
- return Collections.emptySet();
- }
-
- @Override
- public void addGrouping(GroupingBuilder groupingBuilder) {
- throw new YangParseException(line,
- "Can not add grouping to 'choice' node.");
- }
-
- public Set<TypeDefinitionBuilder> getTypedefs() {
- return addedTypedefs;
- }
-
- @Override
- public void addTypedef(final TypeDefinitionBuilder type) {
- addedTypedefs.add(type);
- }
-
public SchemaPath getPath() {
return schemaPath;
}
return constraints;
}
- public Set<UsesNodeBuilder> getUsesNodes() {
- return addedUsesNodes;
- }
-
- @Override
- public void addUsesNode(UsesNodeBuilder usesNodeBuilder) {
- addedUsesNodes.add(usesNodeBuilder);
- }
-
public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
return addedUnknownNodes;
}
this.defaultCase = defaultCase;
}
- @Override
- public Set<DataSchemaNodeBuilder> getChildNodes() {
- return new HashSet<DataSchemaNodeBuilder>(cases);
- }
private final class ChoiceNodeImpl implements ChoiceNode {
private final QName qname;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
-import org.opendaylight.controller.yang.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
import org.opendaylight.controller.yang.parser.util.YangParseException;
-public final class ChoiceCaseBuilder extends AbstractChildNodeBuilder implements
+public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder implements
DataSchemaNodeBuilder {
private final ChoiceCaseNodeImpl instance;
private final int line;
addedUsesNodes.add(usesNodeBuilder);
}
+ @Override
+ public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ return Collections.emptySet();
+ }
+
@Override
public void addTypedef(TypeDefinitionBuilder typedefBuilder) {
throw new YangParseException(line,
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
-import org.opendaylight.controller.yang.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
-public final class ContainerSchemaNodeBuilder extends AbstractChildNodeBuilder
+public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
implements TypeDefinitionAwareBuilder, AugmentationTargetBuilder,
DataSchemaNodeBuilder {
private boolean isBuilt;
return line;
}
- public Set<TypeDefinitionBuilder> getTypedefs() {
+ @Override
+ public Set<TypeDefinitionBuilder> getTypeDefinitions() {
return addedTypedefs;
}
addedUnknownNodes.add(unknownNode);
}
+ @Override
+ public String toString() {
+ return "container " + getQName().getLocalName();
+ }
+
private final class ContainerSchemaNodeImpl implements ContainerSchemaNode {
private final QName qname;
private SchemaPath path;
}
@Override
- public Set<TypeDefinitionBuilder> getTypedefs() {
+ public Set<TypeDefinitionBuilder> getTypeDefinitions() {
return addedTypedefs;
}
}
@Override
- public void setType(final TypeDefinitionBuilder tdb) {
+ public void setTypedef(final TypeDefinitionBuilder tdb) {
throw new YangParseException(line, "Can not set type to " + NAME);
}
this.unitsStr = unitsStr;
}
+ @Override
+ public String toString() {
+ return "leaf " + qname.getLocalName();
+ }
+
private final class LeafSchemaNodeImpl implements LeafSchemaNode {
private final QName qname;
private SchemaPath path;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
-import org.opendaylight.controller.yang.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
-public final class ListSchemaNodeBuilder extends AbstractChildNodeBuilder
+public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilder
implements DataSchemaNodeBuilder, AugmentationTargetBuilder,
TypeDefinitionAwareBuilder {
private boolean isBuilt;
return line;
}
- public Set<TypeDefinitionBuilder> getTypedefs() {
+ @Override
+ public Set<TypeDefinitionBuilder> getTypeDefinitions() {
return addedTypedefs;
}
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
-import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
- /**
- * All nodes, that can contain other nodes
- */
- private final Map<List<String>, Builder> moduleNodes = new HashMap<List<String>, Builder>();
-
/**
* Holds all child (DataSchemaNode) nodes: anyxml, choice, case, container,
* list, leaf, leaf-list.
*/
- private final Map<List<String>, DataSchemaNodeBuilder> addedChilds = new HashMap<List<String>, DataSchemaNodeBuilder>();
+ private final Map<List<String>, DataSchemaNodeBuilder> childNodes = new HashMap<List<String>, DataSchemaNodeBuilder>();
private final Map<List<String>, GroupingBuilder> addedGroupings = new HashMap<List<String>, GroupingBuilder>();
private final List<AugmentationSchemaBuilder> addedAugments = new ArrayList<AugmentationSchemaBuilder>();
private final Map<List<String>, UsesNodeBuilder> addedUsesNodes = new HashMap<List<String>, UsesNodeBuilder>();
+ //private final Map<List<String>, RefineHolder> addedRefines = new HashMap<List<String>, RefineHolder>();
private final Map<List<String>, RpcDefinitionBuilder> addedRpcs = new HashMap<List<String>, RpcDefinitionBuilder>();
private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();
private final Map<List<String>, FeatureBuilder> addedFeatures = new HashMap<List<String>, FeatureBuilder>();
- private final Map<String, DeviationBuilder> addedDeviations = new HashMap<String, DeviationBuilder>();
+ private final Map<List<String>, DeviationBuilder> addedDeviations = new HashMap<List<String>, DeviationBuilder>();
private final Map<List<String>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
+ private final Map<List<String>, UnionTypeBuilder> addedUnionTypes = new HashMap<List<String>, UnionTypeBuilder>();
private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
private final Set<UnknownSchemaNodeBuilder> addedUnknownNodes = new HashSet<UnknownSchemaNodeBuilder>();
private final Map<List<String>, TypeAwareBuilder> dirtyNodes = new HashMap<List<String>, TypeAwareBuilder>();
+ private final LinkedList<Builder> actualPath = new LinkedList<Builder>();
+
public ModuleBuilder(final String name) {
this.name = name;
instance = new ModuleImpl(name);
instance.setTypeDefinitions(typedefs);
// CHILD NODES
- final Map<QName, DataSchemaNode> childNodes = buildModuleChildNodes(addedChilds);
- instance.setChildNodes(childNodes);
+ final Map<QName, DataSchemaNode> children = buildModuleChildNodes(childNodes);
+ instance.setChildNodes(children);
// GROUPINGS
final Set<GroupingDefinition> groupings = buildModuleGroupings(addedGroupings);
// DEVIATIONS
final Set<Deviation> deviations = new HashSet<Deviation>();
- for (Map.Entry<String, DeviationBuilder> entry : addedDeviations
+ for (Map.Entry<List<String>, DeviationBuilder> entry : addedDeviations
.entrySet()) {
deviations.add(entry.getValue().build());
}
return 0;
}
- public Builder getNode(final List<String> path) {
- return moduleNodes.get(path);
+ public void enterNode(final Builder node) {
+ actualPath.push(node);
+ }
+
+ public void exitNode() {
+ actualPath.pop();
+ }
+
+ public Builder getModuleNode(final List<String> path) {
+ return childNodes.get(path);
+ }
+
+ public GroupingBuilder getGrouping(final List<String> path) {
+ return addedGroupings.get(path);
+ }
+
+ public Builder getModuleTypedef(final List<String> path) {
+ return addedTypedefs.get(path);
}
public Set<DataSchemaNodeBuilder> getChildNodes() {
- final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
- for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
+ final Set<DataSchemaNodeBuilder> children = new HashSet<DataSchemaNodeBuilder>();
+ for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : childNodes
.entrySet()) {
- List<String> path = entry.getKey();
- DataSchemaNodeBuilder child = entry.getValue();
+ final List<String> path = entry.getKey();
+ final DataSchemaNodeBuilder child = entry.getValue();
if (path.size() == 2) {
- childNodes.add(child);
+ children.add(child);
}
}
- return childNodes;
+ return children;
}
public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
return dirtyNodes;
}
- public List<AugmentationSchemaBuilder> getAddedAugments() {
+ public List<AugmentationSchemaBuilder> getAugments() {
return addedAugments;
}
- public Set<IdentitySchemaNodeBuilder> getAddedIdentities() {
+ public Set<IdentitySchemaNodeBuilder> getIdentities() {
return addedIdentities;
}
- public Map<List<String>, UsesNodeBuilder> getAddedUsesNodes() {
+ public Map<List<String>, UsesNodeBuilder> getUsesNodes() {
return addedUsesNodes;
}
- public Set<UnknownSchemaNodeBuilder> getAddedUnknownNodes() {
+ public Set<UnknownSchemaNodeBuilder> getUnknownNodes() {
return addedUnknownNodes;
}
public Set<TypeDefinitionBuilder> getModuleTypedefs() {
- Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
+ final Set<TypeDefinitionBuilder> typedefs = new HashSet<TypeDefinitionBuilder>();
for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
.entrySet()) {
if (entry.getKey().size() == 2) {
public void addDirtyNode(final List<String> path) {
final List<String> dirtyNodePath = new ArrayList<String>(path);
- final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
- .get(dirtyNodePath);
+ final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) actualPath
+ .getFirst();
dirtyNodes.put(dirtyNodePath, nodeBuilder);
}
final List<String> pathToNode = new ArrayList<String>(parentPath);
final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(
containerName, line);
- final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
- .get(pathToNode);
- if (parent != null) {
- if (parent instanceof AugmentationSchemaBuilder) {
- containerBuilder.setAugmenting(true);
- }
- parent.addChildNode(containerBuilder);
- }
+ updateParent(containerBuilder, line, "container");
pathToNode.add(containerName.getLocalName());
- moduleNodes.put(pathToNode, containerBuilder);
- addedChilds.put(pathToNode, containerBuilder);
+ childNodes.put(pathToNode, containerBuilder);
return containerBuilder;
}
final List<String> pathToNode = new ArrayList<String>(parentPath);
final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(
listName, line);
- final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
- .get(pathToNode);
- if (parent != null) {
- if (parent instanceof AugmentationSchemaBuilder) {
- listBuilder.setAugmenting(true);
- }
- parent.addChildNode(listBuilder);
- }
+ updateParent(listBuilder, line, "list");
pathToNode.add(listName.getLocalName());
- moduleNodes.put(pathToNode, listBuilder);
- addedChilds.put(pathToNode, listBuilder);
+ childNodes.put(pathToNode, listBuilder);
return listBuilder;
}
final List<String> pathToNode = new ArrayList<String>(parentPath);
final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(
leafName, line);
- final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
- .get(pathToNode);
- if (parent != null) {
- if (parent instanceof AugmentationSchemaBuilder) {
- leafBuilder.setAugmenting(true);
- }
- parent.addChildNode(leafBuilder);
- }
+ updateParent(leafBuilder, line, "leaf");
pathToNode.add(leafName.getLocalName());
- addedChilds.put(pathToNode, leafBuilder);
- moduleNodes.put(pathToNode, leafBuilder);
+ childNodes.put(pathToNode, leafBuilder);
return leafBuilder;
}
- public LeafListSchemaNodeBuilder addLeafListNode(final QName leafListName,
+ public LeafListSchemaNodeBuilder addLeafListNode(final QName qname,
final List<String> parentPath, final int line) {
final List<String> pathToNode = new ArrayList<String>(parentPath);
final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(
- leafListName, line);
- final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
- .get(pathToNode);
- if (parent != null) {
- if (parent instanceof AugmentationSchemaBuilder) {
- leafListBuilder.setAugmenting(true);
- }
- parent.addChildNode(leafListBuilder);
- }
+ qname, line);
+ updateParent(leafListBuilder, line, "leaf-list");
- pathToNode.add(leafListName.getLocalName());
- addedChilds.put(pathToNode, leafListBuilder);
- moduleNodes.put(pathToNode, leafListBuilder);
+ pathToNode.add(qname.getLocalName());
+ childNodes.put(pathToNode, leafListBuilder);
return leafListBuilder;
}
final List<String> parentPath, final int line) {
final List<String> pathToGroup = new ArrayList<String>(parentPath);
final GroupingBuilder builder = new GroupingBuilderImpl(qname, line);
- final ChildNodeBuilder parentNodeBuilder = (ChildNodeBuilder) moduleNodes
- .get(pathToGroup);
- if (parentNodeBuilder != null) {
- parentNodeBuilder.addGrouping(builder);
+
+ if (!(actualPath.isEmpty())) {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof DataNodeContainerBuilder) {
+ ((DataNodeContainerBuilder) parent).addGrouping(builder);
+ } else {
+ throw new YangParseException(name, line,
+ "Unresolved parent of grouping " + qname.getLocalName());
+ }
}
- pathToGroup.add("grouping");
pathToGroup.add(qname.getLocalName());
- moduleNodes.put(pathToGroup, builder);
addedGroupings.put(pathToGroup, builder);
return builder;
name, line);
// augment can only be in 'module' or 'uses' statement
- final UsesNodeBuilder parent = addedUsesNodes.get(pathToAugment);
- if (parent != null) {
- parent.addAugment(builder);
+ if (!(actualPath.isEmpty())) {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof UsesNodeBuilder) {
+ ((UsesNodeBuilder) parent).addAugment(builder);
+ } else {
+ throw new YangParseException(this.name, line,
+ "Unresolved parent of augment " + name);
+ }
}
pathToAugment.add(name);
- moduleNodes.put(pathToAugment, builder);
addedAugments.add(builder);
return builder;
final List<String> pathToUses = new ArrayList<String>(parentPath);
final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(
groupingPathStr, line);
- final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
- .get(pathToUses);
- if (parent != null) {
- parent.addUsesNode(usesBuilder);
+
+ if (!(actualPath.isEmpty())) {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof DataNodeContainerBuilder) {
+ if (parent instanceof AugmentationSchemaBuilder) {
+ usesBuilder.setAugmenting(true);
+ }
+ ((DataNodeContainerBuilder) parent).addUsesNode(usesBuilder);
+ } else {
+ throw new YangParseException(name, line,
+ "Unresolved parent of uses " + groupingPathStr);
+ }
}
pathToUses.add(groupingPathStr);
addedUsesNodes.put(pathToUses, usesBuilder);
- moduleNodes.put(pathToUses, usesBuilder);
return usesBuilder;
}
public void addRefine(final RefineHolder refine,
final List<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());
+
+ if (actualPath.isEmpty()) {
+ throw new YangParseException(name, refine.getLine(),
+ "refine can be defined only in uses statement");
+ } else {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof UsesNodeBuilder) {
+ ((UsesNodeBuilder) parent).addRefine(refine);
+ } else {
+ throw new YangParseException(name, refine.getLine(),
+ "refine can be defined only in uses statement");
+ }
}
- UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent;
- usesBuilder.addRefine(refine);
+
path.add(refine.getName());
- moduleNodes.put(path, refine);
}
public RpcDefinitionBuilder addRpc(final QName qname,
final List<String> parentPath, final int line) {
+
+ if (!(actualPath.isEmpty())) {
+ throw new YangParseException(name, line,
+ "rpc can be defined only in module or submodule");
+ }
+
final List<String> pathToRpc = new ArrayList<String>(parentPath);
final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname,
line);
pathToRpc.add(qname.getLocalName());
addedRpcs.put(pathToRpc, rpcBuilder);
- final QName inputQName = new QName(qname.getNamespace(),
- qname.getRevision(), qname.getPrefix(), "input");
+ return rpcBuilder;
+ }
+
+ public ContainerSchemaNodeBuilder addRpcInput(final QName inputQName,
+ final int line) {
+ final Builder parent = actualPath.getFirst();
+ if (!(parent instanceof RpcDefinitionBuilder)) {
+ throw new YangParseException(name, line,
+ "input can be defined only in rpc statement");
+ }
+ final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
+
final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
inputQName, line);
- final List<String> pathToInput = new ArrayList<String>(pathToRpc);
- pathToInput.add("input");
- moduleNodes.put(pathToInput, inputBuilder);
- rpcBuilder.setInput(inputBuilder);
+ rpc.setInput(inputBuilder);
+ return inputBuilder;
+ }
+
+ public ContainerSchemaNodeBuilder addRpcOutput(final QName outputQName,
+ final int line) {
+ final Builder parent = actualPath.getFirst();
+ if (!(parent instanceof RpcDefinitionBuilder)) {
+ throw new YangParseException(name, line,
+ "output can be defined only in rpc statement");
+ }
+ final RpcDefinitionBuilder rpc = (RpcDefinitionBuilder) parent;
- final QName outputQName = new QName(qname.getNamespace(),
- qname.getRevision(), qname.getPrefix(), "output");
final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
outputQName, line);
- final List<String> pathToOutput = new ArrayList<String>(pathToRpc);
- pathToOutput.add("output");
- moduleNodes.put(pathToOutput, outputBuilder);
- rpcBuilder.setOutput(outputBuilder);
-
- return rpcBuilder;
+ rpc.setOutput(outputBuilder);
+ return outputBuilder;
}
public NotificationBuilder addNotification(final QName notificationName,
final List<String> parentPath, final int line) {
- final List<String> pathToNotification = new ArrayList<String>(
- parentPath);
+ if (!(actualPath.isEmpty())) {
+ throw new YangParseException(name, line,
+ "notification can be defined only in module or submodule");
+ }
- NotificationBuilder builder = new NotificationBuilder(notificationName,
- line);
+ final NotificationBuilder builder = new NotificationBuilder(
+ notificationName, line);
- pathToNotification.add(notificationName.getLocalName());
- moduleNodes.put(pathToNotification, builder);
+ final List<String> notificationPath = new ArrayList<String>(parentPath);
+ notificationPath.add(notificationName.getLocalName());
addedNotifications.add(builder);
return builder;
public FeatureBuilder addFeature(final QName featureName,
final List<String> parentPath, final int line) {
- List<String> pathToFeature = new ArrayList<String>(parentPath);
+ if (!(actualPath.isEmpty())) {
+ throw new YangParseException(name, line,
+ "feature can be defined only in module or submodule");
+ }
+
+ final List<String> pathToFeature = new ArrayList<String>(parentPath);
pathToFeature.add(featureName.getLocalName());
- FeatureBuilder builder = new FeatureBuilder(featureName, line);
+ final FeatureBuilder builder = new FeatureBuilder(featureName, line);
addedFeatures.put(pathToFeature, builder);
return builder;
}
public ChoiceBuilder addChoice(final QName choiceName,
final List<String> parentPath, final int line) {
- List<String> pathToChoice = new ArrayList<String>(parentPath);
- ChoiceBuilder builder = new ChoiceBuilder(choiceName, line);
-
- final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
- .get(pathToChoice);
- if (parent != null) {
- if (parent instanceof AugmentationSchemaBuilder) {
- builder.setAugmenting(true);
+ final List<String> pathToChoice = new ArrayList<String>(parentPath);
+ final ChoiceBuilder builder = new ChoiceBuilder(choiceName, line);
+
+ if (!(actualPath.isEmpty())) {
+ Builder parent = actualPath.getFirst();
+ if (parent instanceof DataNodeContainerBuilder) {
+ if (parent instanceof AugmentationSchemaBuilder) {
+ builder.setAugmenting(true);
+ }
+ ((DataNodeContainerBuilder) parent).addChildNode(builder);
+ } else {
+ throw new YangParseException(name, line,
+ "Unresolved parent of choice "
+ + choiceName.getLocalName());
}
- parent.addChildNode(builder);
}
pathToChoice.add(choiceName.getLocalName());
- addedChilds.put(pathToChoice, builder);
- moduleNodes.put(pathToChoice, builder);
+ childNodes.put(pathToChoice, builder);
return builder;
}
public ChoiceCaseBuilder addCase(final QName caseName,
final List<String> parentPath, final int line) {
- List<String> pathToCase = new ArrayList<String>(parentPath);
- ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line);
-
- final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
- .get(pathToCase);
- if (parent != null) {
- if (parent instanceof AugmentationSchemaBuilder) {
+ final List<String> pathToCase = new ArrayList<String>(parentPath);
+ final ChoiceCaseBuilder builder = new ChoiceCaseBuilder(caseName, line);
+
+ if (actualPath.isEmpty()) {
+ throw new YangParseException(name, line, "'case' parent not found");
+ } else {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof ChoiceBuilder) {
+ ((ChoiceBuilder) parent).addChildNode(builder);
+ } else if (parent instanceof AugmentationSchemaBuilder) {
builder.setAugmenting(true);
+ ((AugmentationSchemaBuilder) parent).addChildNode(builder);
+ } else {
+ throw new YangParseException(name, line,
+ "Unresolved parent of 'case' "
+ + caseName.getLocalName());
}
- parent.addChildNode(builder);
}
pathToCase.add(caseName.getLocalName());
- moduleNodes.put(pathToCase, builder);
+ childNodes.put(pathToCase, builder);
return builder;
}
public AnyXmlBuilder addAnyXml(final QName anyXmlName,
final List<String> parentPath, final int line) {
- List<String> pathToAnyXml = new ArrayList<String>(parentPath);
- AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
-
- final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
- .get(pathToAnyXml);
- if (parent != null) {
- if (parent instanceof AugmentationSchemaBuilder) {
- throw new YangParseException(
- "An anyxml node cannot be augmented.");
- }
- parent.addChildNode(builder);
- }
+ final List<String> pathToAnyXml = new ArrayList<String>(parentPath);
+ final AnyXmlBuilder builder = new AnyXmlBuilder(anyXmlName, line);
+ updateParent(builder, line, "anyxml");
pathToAnyXml.add(anyXmlName.getLocalName());
- addedChilds.put(pathToAnyXml, builder);
- moduleNodes.put(pathToAnyXml, builder);
+ childNodes.put(pathToAnyXml, builder);
return builder;
}
- public TypedefBuilder addTypedef(final QName typeDefName,
+ public TypeDefinitionBuilderImpl addTypedef(final QName typeDefName,
final List<String> parentPath, final int line) {
- List<String> pathToType = new ArrayList<String>(parentPath);
- TypedefBuilder builder = new TypedefBuilder(typeDefName, line);
- TypeDefinitionAwareBuilder parent = (TypeDefinitionAwareBuilder) moduleNodes
- .get(pathToType);
- if (parent != null) {
- parent.addTypedef(builder);
+ final List<String> pathToType = new ArrayList<String>(parentPath);
+ final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(
+ typeDefName, line);
+
+ if (!(actualPath.isEmpty())) {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof TypeDefinitionAwareBuilder) {
+ ((TypeDefinitionAwareBuilder) parent).addTypedef(builder);
+ } else {
+ throw new YangParseException(name, line,
+ "Unresolved parent of typedef "
+ + typeDefName.getLocalName());
+ }
}
+
pathToType.add(typeDefName.getLocalName());
addedTypedefs.put(pathToType, builder);
- moduleNodes.put(pathToType, builder);
return builder;
}
- public void setType(TypeDefinition<?> type, List<String> parentPath) {
- TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
- .get(parentPath);
- if (parent == null) {
- throw new YangParseException("Failed to set type '"
- + type.getQName().getLocalName()
- + "'. Parent node not found.");
+ public void setType(final TypeDefinition<?> type,
+ final List<String> parentPath) {
+
+ if (!(actualPath.isEmpty())) {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof TypeAwareBuilder) {
+ ((TypeAwareBuilder) parent).setType(type);
+ } else {
+ throw new YangParseException("Failed to set type '"
+ + type.getQName().getLocalName()
+ + "'. Unknown parent node: " + parent);
+ }
}
- parent.setType(type);
}
- public UnionTypeBuilder addUnionType(final List<String> actualPath,
+ public UnionTypeBuilder addUnionType(final List<String> currentPath,
final URI namespace, final Date revision, final int line) {
- List<String> pathToUnion = new ArrayList<String>(actualPath);
- TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
- .get(pathToUnion);
- UnionTypeBuilder union = new UnionTypeBuilder(line);
- parent.setType(union);
+ final List<String> pathToUnion = new ArrayList<String>(currentPath);
+ final UnionTypeBuilder union = new UnionTypeBuilder(line);
+
+ if (actualPath.isEmpty()) {
+ throw new YangParseException(line, "union error");
+ } else {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof TypeAwareBuilder) {
- List<String> path = new ArrayList<String>(pathToUnion);
- path.add("union");
+ ((TypeAwareBuilder) parent).setTypedef(union);
- moduleNodes.put(path, union);
- return union;
+ final List<String> path = new ArrayList<String>(pathToUnion);
+ path.add("union");
+
+ addedUnionTypes.put(path, union);
+ return union;
+ } else {
+ throw new YangParseException(name, line,
+ "Unresolved parent of union type.");
+ }
+ }
}
public void addIdentityrefType(final String baseString,
final List<String> parentPath, final SchemaPath schemaPath,
final int line) {
- List<String> pathToIdentityref = new ArrayList<String>(parentPath);
- TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
- .get(pathToIdentityref);
- IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
+ final List<String> pathToIdentityref = new ArrayList<String>(parentPath);
+ final IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
baseString, schemaPath, line);
- parent.setType(identityref);
- dirtyNodes.put(pathToIdentityref, parent);
+
+ if (actualPath.isEmpty()) {
+ throw new YangParseException(line, "identityref error");
+ } else {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof TypeAwareBuilder) {
+ final TypeAwareBuilder typeParent = (TypeAwareBuilder) parent;
+ typeParent.setTypedef(identityref);
+ dirtyNodes.put(pathToIdentityref, typeParent);
+ } else {
+ throw new YangParseException(name, line,
+ "Unresolved parent of identityref type.");
+ }
+ }
}
public DeviationBuilder addDeviation(final String targetPath,
final List<String> parentPath, final int line) {
+ if (!(actualPath.isEmpty())) {
+ throw new YangParseException(name, line,
+ "deviation can be defined only in module or submodule");
+ }
+
final List<String> pathToDeviation = new ArrayList<String>(parentPath);
pathToDeviation.add(targetPath);
- DeviationBuilder builder = new DeviationBuilder(targetPath, line);
- addedDeviations.put(targetPath, builder);
- moduleNodes.put(pathToDeviation, builder);
+ final DeviationBuilder builder = new DeviationBuilder(targetPath, line);
+ addedDeviations.put(pathToDeviation, builder);
return builder;
}
public IdentitySchemaNodeBuilder addIdentity(final QName qname,
final List<String> parentPath, final int line) {
+ if (!(actualPath.isEmpty())) {
+ throw new YangParseException(name, line,
+ "identity can be defined only in module or submodule");
+ }
+
final List<String> pathToIdentity = new ArrayList<String>(parentPath);
final IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(
qname, line);
pathToIdentity.add(qname.getLocalName());
- moduleNodes.put(pathToIdentity, builder);
addedIdentities.add(builder);
return builder;
}
- public void addConfiguration(boolean configuration, List<String> parentPath) {
- Builder builder = moduleNodes.get(parentPath);
- // current api did not support adding config to deviate
- if (!(builder instanceof DeviationBuilder)) {
- if(builder instanceof RefineHolder) {
- ((RefineHolder)builder).setConfig(configuration);
+ public void addConfiguration(final boolean configuration,
+ final List<String> parentPath, final int line) {
+ if (actualPath.isEmpty()) {
+ throw new YangParseException(name, line,
+ "Parent node of config statement not found.");
+ } else {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof DataSchemaNodeBuilder) {
+ ((DataSchemaNodeBuilder) parent)
+ .setConfiguration(configuration);
+ } else if (parent instanceof RefineHolder) {
+ ((RefineHolder) parent).setConfig(configuration);
+ } else if (parent instanceof DeviationBuilder) {
+ // skip: set config to deviation (deviate stmt) not supported by
+ // current api
+ return;
} else {
- ((DataSchemaNodeBuilder)builder).setConfiguration(configuration);
+ throw new YangParseException(name, line,
+ "Unresolved parent of config statement.");
}
}
}
public UnknownSchemaNodeBuilder addUnknownSchemaNode(final QName qname,
final List<String> parentPath, final int line) {
- final List<String> pathToUnknown = new ArrayList<String>(parentPath);
final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(
qname, line);
- final Builder parent = moduleNodes.get(pathToUnknown);
- if (parent instanceof RefineHolder) {
- ((RefineHolder) parent).addUnknownSchemaNode(builder);
- } else if (parent instanceof SchemaNodeBuilder) {
- ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
+
+ if (!(actualPath.isEmpty())) {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof SchemaNodeBuilder) {
+ ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
+ } else if (parent instanceof RefineHolder) {
+ ((RefineHolder) parent).addUnknownSchemaNode(builder);
+ } else {
+ throw new YangParseException(name, line,
+ "Unresolved parent of unknown node '"
+ + qname.getLocalName() + "'");
+ }
}
+
addedUnknownNodes.add(builder);
return builder;
}
}
}
+ private void updateParent(DataSchemaNodeBuilder nodeBuilder, int line,
+ String nodeTypeName) {
+ if (!(actualPath.isEmpty())) {
+ final Builder parent = actualPath.getFirst();
+ if (parent instanceof DataNodeContainerBuilder) {
+ if (parent instanceof AugmentationSchemaBuilder) {
+ nodeBuilder.setAugmenting(true);
+ }
+ ((DataNodeContainerBuilder) parent)
+ .addChildNode(nodeBuilder);
+ } else if (parent instanceof ChoiceBuilder) {
+ ((ChoiceBuilder) parent).addChildNode(nodeBuilder);
+ } else {
+ throw new YangParseException(name, line,
+ "Unresolved parent of " + nodeTypeName + " "
+ + nodeBuilder.getQName().getLocalName());
+ }
+ }
+ }
+
private ModuleImport createModuleImport(final String moduleName,
final Date revision, final String prefix) {
ModuleImport moduleImport = new ModuleImport() {
final Set<GroupingDefinition> groupings = new HashSet<GroupingDefinition>();
for (Map.Entry<List<String>, GroupingBuilder> entry : addedGroupings
.entrySet()) {
- if (entry.getKey().size() == 3) {
+ if (entry.getKey().size() == 2) {
groupings.add(entry.getValue().build());
}
}
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.model.api.UsesNode;
-import org.opendaylight.controller.yang.parser.builder.api.AbstractChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.AbstractDataNodeContainerBuilder;
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.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
-public final class NotificationBuilder extends AbstractChildNodeBuilder
+public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
implements TypeDefinitionAwareBuilder, SchemaNodeBuilder {
private boolean isBuilt;
private final NotificationDefinitionImpl instance;
return line;
}
+ @Override
+ public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ return addedTypedefs;
+ }
+
@Override
public void addTypedef(final TypeDefinitionBuilder type) {
addedTypedefs.add(type);
addedUnknownNodes.add(unknownNode);
}
+ @Override
+ public String toString() {
+ return "notification " + getQName().getLocalName();
+ }
+
private final class NotificationDefinitionImpl implements NotificationDefinition {
private final QName qname;
private SchemaPath path;
this.outputBuilder = outputBuilder;
}
+ public Set<TypeDefinitionBuilder> getTypeDefinitions() {
+ return addedTypedefs;
+ }
+
@Override
public void addTypedef(final TypeDefinitionBuilder type) {
addedTypedefs.add(type);
}
+ public void addGrouping(GroupingBuilder grouping) {
+ addedGroupings.add(grouping);
+ }
+
@Override
public SchemaPath getPath() {
return schemaPath;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.util.YangParseException;
-public final class TypedefBuilder extends AbstractTypeAwareBuilder implements
- TypeDefinitionBuilder {
+public final class TypeDefinitionBuilderImpl extends AbstractTypeAwareBuilder
+ implements TypeDefinitionBuilder {
private final int line;
private final QName qname;
private SchemaPath schemaPath;
private String units;
private Object defaultValue;
- public TypedefBuilder(final QName qname, final int line) {
+ public TypeDefinitionBuilderImpl(final QName qname, final int line) {
this.qname = qname;
this.line = line;
}
}
@Override
- public void setType(final TypeDefinitionBuilder tdb) {
+ public void setTypedef(final TypeDefinitionBuilder tdb) {
typedefs.add(tdb);
}
@Override
public SchemaPath getPath() {
- return null;
+ return path;
}
@Override
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
-import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeAwareBuilder;
import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.TypedefBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.RpcDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.util.ModuleDependencySort;
resolveAugments(modules);
// build
- // Linked Hash Set MUST be used otherwise the Set will not maintain
+ // LinkedHashSet MUST be used otherwise the Set will not maintain
// order!
// http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHashSet.html
final Set<Module> result = new LinkedHashSet<Module>();
final ModuleBuilder builder) {
resolveDirtyNodes(modules, builder);
resolveIdentities(modules, builder);
- resolveUses(modules, builder);
+ resolveUsesRefines(modules, builder);
resolveUnknownNodes(modules, builder);
}
final UnknownType unknownType = (UnknownType) td;
final TypeDefinitionBuilder resolvedType = resolveTypeUnion(
nodeToResolve, unknownType, modules, module);
- union.setType(resolvedType);
+ union.setTypedef(resolvedType);
toRemove.add(unknownType);
}
}
unionTypes.removeAll(toRemove);
} else if (nodeToResolve.getTypedef() instanceof IdentityrefTypeBuilder) {
+ // different handling for identityref types
IdentityrefTypeBuilder idref = (IdentityrefTypeBuilder) nodeToResolve
.getTypedef();
nodeToResolve.setType(new IdentityrefType(findFullQName(
} else {
final TypeDefinitionBuilder resolvedType = resolveType(
nodeToResolve, modules, module);
- nodeToResolve.setType(resolvedType);
+ nodeToResolve.setTypedef(resolvedType);
}
}
}
}
private TypeDefinitionBuilder resolveType(
- final TypeAwareBuilder typeToResolve,
+ final TypeAwareBuilder nodeToResolve,
final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder builder) {
final TypeConstraints constraints = new TypeConstraints();
- final TypeDefinitionBuilder targetType = getTypedefBuilder(
- typeToResolve, modules, builder);
- final TypeConstraints tConstraints = findConstraints(typeToResolve,
+ final TypeDefinitionBuilder targetTypeBuilder = getTypeDefinitionBuilderFromDirtyNode(
+ nodeToResolve, modules, builder);
+ final TypeConstraints tConstraints = findConstraints(nodeToResolve,
constraints, modules, builder);
- targetType.setRanges(tConstraints.getRange());
- targetType.setLengths(tConstraints.getLength());
- targetType.setPatterns(tConstraints.getPatterns());
- targetType.setFractionDigits(tConstraints.getFractionDigits());
+ targetTypeBuilder.setRanges(tConstraints.getRange());
+ targetTypeBuilder.setLengths(tConstraints.getLength());
+ targetTypeBuilder.setPatterns(tConstraints.getPatterns());
+ targetTypeBuilder.setFractionDigits(tConstraints.getFractionDigits());
- return targetType;
+ return targetTypeBuilder;
}
private TypeDefinitionBuilder resolveTypeUnion(
final ModuleBuilder builder) {
final TypeConstraints constraints = new TypeConstraints();
- final TypeDefinitionBuilder targetType = getUnionBuilder(typeToResolve,
- unknownType, modules, builder);
+ final TypeDefinitionBuilder targetTypeBuilder = getUnionBuilder(
+ typeToResolve, unknownType, modules, builder);
final TypeConstraints tConstraints = findConstraints(typeToResolve,
constraints, modules, builder);
- targetType.setRanges(tConstraints.getRange());
- targetType.setLengths(tConstraints.getLength());
- targetType.setPatterns(tConstraints.getPatterns());
- targetType.setFractionDigits(tConstraints.getFractionDigits());
+ targetTypeBuilder.setRanges(tConstraints.getRange());
+ targetTypeBuilder.setLengths(tConstraints.getLength());
+ targetTypeBuilder.setPatterns(tConstraints.getPatterns());
+ targetTypeBuilder.setFractionDigits(tConstraints.getFractionDigits());
- return targetType;
+ return targetTypeBuilder;
}
- private TypeDefinitionBuilder getTypedefBuilder(
+ private TypeDefinitionBuilder getTypeDefinitionBuilderFromDirtyNode(
final TypeAwareBuilder nodeToResolve,
final Map<String, TreeMap<Date, ModuleBuilder>> modules,
- final ModuleBuilder builder) {
-
- final TypeDefinition<?> nodeToResolveBase = nodeToResolve.getType();
- if (nodeToResolveBase != null
- && !(nodeToResolveBase instanceof UnknownType)) {
- return (TypeDefinitionBuilder) nodeToResolve;
- }
+ final ModuleBuilder module) {
final UnknownType unknownType = (UnknownType) nodeToResolve.getType();
final QName unknownTypeQName = unknownType.getQName();
// search for module which contains referenced typedef
final ModuleBuilder dependentModule = findDependentModule(modules,
- builder, unknownTypeQName.getPrefix(), nodeToResolve.getLine());
- final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
- dependentModule, unknownTypeQName.getLocalName(),
- builder.getName(), nodeToResolve.getLine());
+ module, unknownTypeQName.getPrefix(), nodeToResolve.getLine());
+
+ final TypeDefinitionBuilder lookedUpBuilder = findTypeDefinitionBuilder(
+ nodeToResolve.getPath(), dependentModule,
+ unknownTypeQName.getLocalName(), module.getName(),
+ nodeToResolve.getLine());
final TypeDefinitionBuilder lookedUpBuilderCopy = copyTypedefBuilder(
lookedUpBuilder, nodeToResolve instanceof TypeDefinitionBuilder);
// search for module which contains referenced typedef
final ModuleBuilder dependentModule = findDependentModule(modules,
module, unknownTypeQName.getPrefix(), nodeToResolve.getLine());
- final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
- dependentModule, unknownTypeQName.getLocalName(),
- module.getName(), nodeToResolve.getLine());
+ final TypeDefinitionBuilder lookedUpBuilder = findTypeDefinitionBuilder(
+ nodeToResolve.getPath(), dependentModule,
+ unknownTypeQName.getLocalName(), module.getName(),
+ nodeToResolve.getLine());
final TypeDefinitionBuilder lookedUpBuilderCopy = copyTypedefBuilder(
lookedUpBuilder, nodeToResolve instanceof TypeDefinitionBuilder);
final TypeDefinitionBuilder old, final boolean seekByTypedefBuilder) {
if (old instanceof UnionTypeBuilder) {
final UnionTypeBuilder oldUnion = (UnionTypeBuilder) old;
- final UnionTypeBuilder newUnion = new UnionTypeBuilder(old.getLine());
+ final UnionTypeBuilder newUnion = new UnionTypeBuilder(
+ old.getLine());
for (TypeDefinition<?> td : oldUnion.getTypes()) {
newUnion.setType(td);
}
for (TypeDefinitionBuilder tdb : oldUnion.getTypedefs()) {
- newUnion.setType(copyTypedefBuilder(tdb, true));
+ newUnion.setTypedef(copyTypedefBuilder(tdb, true));
}
newUnion.setPath(old.getPath());
return newUnion;
final QName newName = new QName(oldName.getNamespace(),
oldName.getRevision(), oldName.getPrefix(),
oldName.getLocalName());
- final TypeDefinitionBuilder tdb = new TypedefBuilder(newName,
- old.getLine());
+ final TypeDefinitionBuilder tdb = new TypeDefinitionBuilderImpl(
+ newName, old.getLine());
tdb.setRanges(old.getRanges());
tdb.setLengths(old.getLengths());
final TypeDefinition<?> oldType = old.getType();
if (oldType == null) {
- tdb.setType(old.getTypedef());
+ tdb.setTypedef(old.getTypedef());
} else {
tdb.setType(oldType);
}
final UnknownType unknownType = (UnknownType) td;
final TypeDefinitionBuilder resolvedType = resolveTypeUnion(
union, unknownType, modules, builder);
- union.setType(resolvedType);
+ union.setTypedef(resolvedType);
toRemove.add(unknownType);
}
}
final String unknownTypePrefix = unknownTypeQName.getPrefix();
final ModuleBuilder dependentModule = findDependentModule(modules,
builder, unknownTypePrefix, copy.getLine());
- final TypeDefinitionBuilder utBuilder = getTypedefBuilder(copy,
- modules, dependentModule);
- copy.setType(utBuilder);
+ final TypeDefinitionBuilder utBuilder = getTypeDefinitionBuilderFromDirtyNode(
+ copy, modules, dependentModule);
+ copy.setTypedef(utBuilder);
return copy;
} else if (base == null && baseTdb != null) {
// make a copy of baseTypeDef and call again
baseTdb, true);
final TypeDefinitionBuilder baseTdbCopyResolved = resolveCopiedBuilder(
baseTdbCopy, modules, builder);
- copy.setType(baseTdbCopyResolved);
+ copy.setTypedef(baseTdbCopyResolved);
return copy;
} else {
- throw new IllegalStateException("Failed to resolve type "
- + copy.getQName().getLocalName());
+ throw new YangParseException(copy.getLine(),
+ "Failed to resolve type " + copy.getQName().getLocalName());
}
}
- private TypeDefinitionBuilder findTypedefBuilder(
- final QName unknownTypeQName,
- final Map<String, TreeMap<Date, ModuleBuilder>> modules,
- final ModuleBuilder builder, int line) {
- // search for module which contains referenced typedef
- final ModuleBuilder dependentModule = findDependentModule(modules,
- builder, unknownTypeQName.getPrefix(), line);
- final TypeDefinitionBuilder lookedUpBuilder = findTypedefBuilderByName(
- dependentModule, unknownTypeQName.getLocalName(),
- builder.getName(), line);
- return copyTypedefBuilder(lookedUpBuilder, true);
- }
-
private TypeConstraints findConstraints(
final TypeAwareBuilder nodeToResolve,
final TypeConstraints constraints,
fractionDigits = ext.getFractionDigits();
constraints.setFractionDigits(fractionDigits);
return findConstraints(
- findTypedefBuilder(ext.getQName(), modules, builder,
+ findTypeDefinitionBuilder(nodeToResolve.getPath(), builder,
+ ext.getQName().getLocalName(), builder.getName(),
nodeToResolve.getLine()), constraints, modules,
builder);
} else if (referencedType instanceof UnknownType) {
final ModuleBuilder dependentModule = findDependentModule(modules,
builder, unknown.getQName().getPrefix(),
nodeToResolve.getLine());
- final TypeDefinitionBuilder utBuilder = findTypedefBuilder(
- unknown.getQName(), modules, builder,
+ final TypeDefinitionBuilder utBuilder = findTypeDefinitionBuilder(
+ nodeToResolve.getPath(), dependentModule, unknown
+ .getQName().getLocalName(), builder.getName(),
nodeToResolve.getLine());
return findConstraints(utBuilder, constraints, modules,
dependentModule);
/**
* Search for type definition builder by name.
*
+ * @param dirtyNodeSchemaPath
+ * schema path of node which contains unresolved type
* @param dependentModule
- * module to search
- * @param name
+ * module which should contains referenced type
+ * @param typeName
* name of type definition
* @param currentModuleName
- * current module name
+ * name of current module
* @param line
* current line in yang model
* @return
*/
- private TypeDefinitionBuilder findTypedefBuilderByName(
- final ModuleBuilder dependentModule, final String name,
+ private TypeDefinitionBuilder findTypeDefinitionBuilder(
+ SchemaPath dirtyNodeSchemaPath,
+ final ModuleBuilder dependentModule, final String typeName,
final String currentModuleName, final int line) {
- final Set<TypeDefinitionBuilder> typedefs = dependentModule
+ final List<QName> path = dirtyNodeSchemaPath.getPath();
+ TypeDefinitionBuilder result = null;
+
+ Set<TypeDefinitionBuilder> typedefs = dependentModule
.getModuleTypedefs();
- for (TypeDefinitionBuilder td : typedefs) {
+ result = findTdb(typedefs, typeName);
+
+ if (result == null) {
+ Builder currentNode = null;
+ final List<String> currentPath = new ArrayList<String>();
+ currentPath.add(dependentModule.getName());
+
+ for (int i = 0; i < path.size(); i++) {
+ QName qname = path.get(i);
+ currentPath.add(qname.getLocalName());
+ currentNode = dependentModule.getModuleNode(currentPath);
+
+ if (currentNode instanceof RpcDefinitionBuilder) {
+ typedefs = ((RpcDefinitionBuilder) currentNode)
+ .getTypeDefinitions();
+ } else if (currentNode instanceof DataNodeContainerBuilder) {
+ typedefs = ((DataNodeContainerBuilder) currentNode)
+ .getTypeDefinitions();
+ } else {
+ typedefs = Collections.emptySet();
+ }
+
+ result = findTdb(typedefs, typeName);
+ if (result != null) {
+ break;
+ }
+ }
+ }
+
+ if (result != null) {
+ return result;
+ }
+ throw new YangParseException(currentModuleName, line,
+ "Referenced type '" + typeName + "' not found.");
+ }
+
+ private TypeDefinitionBuilder findTdb(Set<TypeDefinitionBuilder> types,
+ String name) {
+ for (TypeDefinitionBuilder td : types) {
if (td.getQName().getLocalName().equals(name)) {
return td;
}
}
- throw new YangParseException(currentModuleName, line, "Target module '"
- + dependentModule.getName() + "' does not contain typedef '"
- + name + "'.");
+ return null;
}
/**
// while all augments are not resolved
final Iterator<ModuleBuilder> allModulesIterator = allModulesSet
.iterator();
- while (!(module.getAugmentsResolved() == module.getAddedAugments()
+ while (!(module.getAugmentsResolved() == module.getAugments()
.size())) {
ModuleBuilder nextModule = null;
// try resolve other module augments
private void resolveAugment(
final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module) {
- if (module.getAugmentsResolved() < module.getAddedAugments().size()) {
+ if (module.getAugmentsResolved() < module.getAugments().size()) {
for (AugmentationSchemaBuilder augmentBuilder : module
- .getAddedAugments()) {
+ .getAugments()) {
if (!augmentBuilder.isResolved()) {
final SchemaPath augmentTargetSchemaPath = augmentBuilder
}
}
+ if (currentParent == null) {
+ continue;
+ }
+
for (int i = 1; i < path.size(); i++) {
final QName currentQName = path.get(i);
DataSchemaNodeBuilder newParent = null;
- for (DataSchemaNodeBuilder child : ((ChildNodeBuilder) currentParent)
+ for (DataSchemaNodeBuilder child : ((DataNodeContainerBuilder) currentParent)
.getChildNodes()) {
final QName childQName = child.getQName();
if (childQName.getLocalName().equals(
.get(path.size() - 1);
if (currentQName.getLocalName().equals(
lastAugmentPathElement.getLocalName())) {
- ParserUtils.fillAugmentTarget(augmentBuilder,
- (ChildNodeBuilder) currentParent);
+
+ if(currentParent instanceof ChoiceBuilder) {
+ ParserUtils.fillAugmentTarget(augmentBuilder,
+ (ChoiceBuilder) currentParent);
+ } else {
+ ParserUtils.fillAugmentTarget(augmentBuilder,
+ (DataNodeContainerBuilder) currentParent);
+ }
((AugmentationTargetBuilder) currentParent)
.addAugmentation(augmentBuilder);
SchemaPath oldPath = currentParent.getPath();
final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module) {
final Set<IdentitySchemaNodeBuilder> identities = module
- .getAddedIdentities();
+ .getIdentities();
for (IdentitySchemaNodeBuilder identity : identities) {
final String baseIdentityName = identity.getBaseIdentityName();
if (baseIdentityName != null) {
modules, module, baseIdentityPrefix, identity.getLine());
final Set<IdentitySchemaNodeBuilder> dependentModuleIdentities = dependentModule
- .getAddedIdentities();
+ .getIdentities();
for (IdentitySchemaNodeBuilder idBuilder : dependentModuleIdentities) {
if (idBuilder.getQName().getLocalName()
.equals(baseIdentityLocalName)) {
* @param module
* module being resolved
*/
- private void resolveUses(
+ private void resolveUsesRefines(
final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module) {
final Map<List<String>, UsesNodeBuilder> moduleUses = module
- .getAddedUsesNodes();
+ .getUsesNodes();
for (Map.Entry<List<String>, UsesNodeBuilder> entry : moduleUses
.entrySet()) {
final List<String> key = entry.getKey();
final String groupingName = key.get(key.size() - 1);
for (RefineHolder refine : usesNode.getRefines()) {
- Builder refineTarget = getRefineNodeBuilderCopy(groupingName,
- refine, modules, module);
+ SchemaNodeBuilder refineTarget = getRefineNodeBuilderCopy(
+ groupingName, refine, modules, module);
+ ParserUtils.checkRefine(refineTarget, refine);
ParserUtils.refineDefault(refineTarget, refine, line);
if (refineTarget instanceof LeafSchemaNodeBuilder) {
final LeafSchemaNodeBuilder leaf = (LeafSchemaNodeBuilder) refineTarget;
final AnyXmlBuilder anyXml = (AnyXmlBuilder) refineTarget;
ParserUtils.refineAnyxml(anyXml, refine, line);
usesNode.addRefineNode(anyXml);
- } else if(refineTarget instanceof GroupingBuilder) {
- usesNode.addRefineNode((GroupingBuilder)refineTarget);
- } else if(refineTarget instanceof TypedefBuilder) {
- usesNode.addRefineNode((TypedefBuilder)refineTarget);
+ } else if (refineTarget instanceof GroupingBuilder) {
+ usesNode.addRefineNode(refineTarget);
+ } else if (refineTarget instanceof TypeDefinitionBuilder) {
+ usesNode.addRefineNode(refineTarget);
}
}
}
/**
* Find original builder of node to refine and return copy of this builder.
* <p>
- * We must make a copy of builder to preserve original builder, because this
- * object will be refined (modified) and later added to
+ * We must create and use a copy of builder to preserve original builder
+ * state, because this object will be refined (modified) and later added to
* {@link UsesNodeBuilder}.
* </p>
*
* @return copy of node to be refined if it is present in grouping, null
* otherwise
*/
- private Builder getRefineNodeBuilderCopy(final String groupingPath,
- final RefineHolder refine,
+ private SchemaNodeBuilder getRefineNodeBuilderCopy(
+ final String groupingPath, final RefineHolder refine,
final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module) {
Builder result = null;
.copyGroupingBuilder((GroupingBuilder) lookedUpBuilder);
} else if (lookedUpBuilder instanceof TypeDefinitionBuilder) {
result = ParserUtils
- .copyTypedefBuilder((TypedefBuilder) lookedUpBuilder);
+ .copyTypedefBuilder((TypeDefinitionBuilderImpl) lookedUpBuilder);
} else {
throw new YangParseException(module.getName(), refine.getLine(),
"Target '" + refine.getName() + "' can not be refined");
}
- return result;
+ return (SchemaNodeBuilder) result;
}
/**
final ModuleBuilder dependentModule = findDependentModule(modules,
module, prefix, refine.getLine());
- builderPath.add(0, "grouping");
builderPath.add(0, dependentModule.getName());
- final GroupingBuilder builder = (GroupingBuilder) dependentModule
- .getNode(builderPath);
+ final GroupingBuilder builder = dependentModule
+ .getGrouping(builderPath);
Builder result = builder.getChildNode(refineNodeName);
- if(result == null) {
+ if (result == null) {
Set<GroupingBuilder> grps = builder.getGroupings();
- for(GroupingBuilder gr : grps) {
- if(gr.getQName().getLocalName().equals(refineNodeName)) {
+ for (GroupingBuilder gr : grps) {
+ if (gr.getQName().getLocalName().equals(refineNodeName)) {
result = gr;
break;
}
}
}
- if(result == null) {
- Set<TypeDefinitionBuilder> typedefs = builder.getTypedefs();
- for(TypeDefinitionBuilder typedef : typedefs) {
- if(typedef.getQName().getLocalName().equals(refineNodeName)) {
+ if (result == null) {
+ Set<TypeDefinitionBuilder> typedefs = builder.getTypeDefinitions();
+ for (TypeDefinitionBuilder typedef : typedefs) {
+ if (typedef.getQName().getLocalName().equals(refineNodeName)) {
result = typedef;
break;
}
private void resolveUnknownNodes(
final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module) {
- for (UnknownSchemaNodeBuilder usnb : module.getAddedUnknownNodes()) {
+ for (UnknownSchemaNodeBuilder usnb : module.getUnknownNodes()) {
QName nodeType = usnb.getNodeType();
if (nodeType.getNamespace() == null
|| nodeType.getRevision() == null) {
* current module
* @param prefix
* target module prefix
+ * @param line
+ * current line in yang model
* @return
*/
private ModuleBuilder findDependentModule(
import org.opendaylight.controller.yang.model.util.YangTypesConverter;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ChoiceCaseBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.NotificationBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.RpcDefinitionBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.TypedefBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.util.RefineHolder;
final String augmentPath = stringFromNode(ctx);
AugmentationSchemaBuilder builder = moduleBuilder.addAugment(
augmentPath, actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(augmentPath);
for (int i = 0; i < ctx.getChildCount(); i++) {
public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) {
final String augment = actualPath.pop();
logger.debug("exiting augment " + augment);
+ moduleBuilder.exitNode();
}
@Override
final String typedefName = stringFromNode(ctx);
QName typedefQName = new QName(namespace, revision, yangModelPrefix,
typedefName);
- TypedefBuilder builder = moduleBuilder.addTypedef(typedefQName,
+ TypeDefinitionBuilder builder = moduleBuilder.addTypedef(typedefQName,
actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(typedefName);
builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
public void exitTypedef_stmt(YangParser.Typedef_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
List<String> typePath = new ArrayList<String>(actualPath);
typePath.add(typeName);
- SchemaPath p = createActualSchemaPath(typePath, namespace, revision, yangModelPrefix);
- UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(actualPath, namespace, revision,
- line);
+ SchemaPath p = createActualSchemaPath(typePath, namespace,
+ revision, yangModelPrefix);
+ UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(
+ actualPath, namespace, revision, line);
+ moduleBuilder.enterNode(unionBuilder);
unionBuilder.setPath(p);
} else if ("identityref".equals(typeName)) {
SchemaPath path = createActualSchemaPath(actualPath,
public void exitType_stmt(YangParser.Type_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+
+ final String typeName = stringFromNode(ctx);
+ if ("union".equals(typeName)) {
+ moduleBuilder.exitNode();
+ }
}
@Override
final String groupName = stringFromNode(ctx);
QName groupQName = new QName(namespace, revision, yangModelPrefix,
groupName);
- GroupingBuilder groupBuilder = moduleBuilder.addGrouping(groupQName,
+ GroupingBuilder builder = moduleBuilder.addGrouping(groupQName,
actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath("grouping");
updatePath(groupName);
- parseSchemaNodeArgs(ctx, groupBuilder);
+ parseSchemaNodeArgs(ctx, builder);
}
@Override
String actContainer = actualPath.pop();
actContainer += "-" + actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
final String containerName = stringFromNode(ctx);
QName containerQName = new QName(namespace, revision, yangModelPrefix,
containerName);
- ContainerSchemaNodeBuilder containerBuilder = moduleBuilder
- .addContainerNode(containerQName, actualPath, ctx.getStart().getLine());
+ ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(
+ containerQName, actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(containerName);
- containerBuilder.setPath(createActualSchemaPath(actualPath, namespace,
- revision, yangModelPrefix));
- parseSchemaNodeArgs(ctx, containerBuilder);
- parseConstraints(ctx, containerBuilder.getConstraints());
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
+ parseConstraints(ctx, builder.getConstraints());
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree childNode = ctx.getChild(i);
if (childNode instanceof Presence_stmtContext) {
- containerBuilder.setPresence(true);
+ builder.setPresence(true);
break;
}
}
public void exitContainer_stmt(Container_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
final String leafName = stringFromNode(ctx);
QName leafQName = new QName(namespace, revision, yangModelPrefix,
leafName);
- LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode(
- leafQName, actualPath, ctx.getStart().getLine());
+ LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(leafQName,
+ actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(leafName);
- leafBuilder.setPath(createActualSchemaPath(actualPath, namespace,
- revision, yangModelPrefix));
- parseSchemaNodeArgs(ctx, leafBuilder);
- parseConstraints(ctx, leafBuilder.getConstraints());
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
+ parseConstraints(ctx, builder.getConstraints());
String defaultStr = null;
String unitsStr = null;
unitsStr = stringFromNode(child);
}
}
- leafBuilder.setDefaultStr(defaultStr);
- leafBuilder.setUnits(unitsStr);
+ builder.setDefaultStr(defaultStr);
+ builder.setUnits(unitsStr);
}
@Override
public void exitLeaf_stmt(YangParser.Leaf_stmtContext ctx) {
final String actLeaf = actualPath.pop();
logger.debug("exiting " + actLeaf);
+ moduleBuilder.exitNode();
}
@Override
public void enterUses_stmt(YangParser.Uses_stmtContext ctx) {
final String groupingPathStr = stringFromNode(ctx);
- moduleBuilder.addUsesNode(groupingPathStr, actualPath, ctx.getStart()
- .getLine());
+ UsesNodeBuilder builder = moduleBuilder.addUsesNode(groupingPathStr,
+ actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(groupingPathStr);
}
public void exitUses_stmt(YangParser.Uses_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
String refineString = stringFromNode(ctx);
RefineHolder refine = parseRefine(ctx);
moduleBuilder.addRefine(refine, actualPath);
+ moduleBuilder.enterNode(refine);
updatePath(refineString);
}
public void exitRefine_stmt(YangParser.Refine_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
final String leafListName = stringFromNode(ctx);
QName leafListQName = new QName(namespace, revision, yangModelPrefix,
leafListName);
- LeafListSchemaNodeBuilder leafListBuilder = moduleBuilder
- .addLeafListNode(leafListQName, actualPath, ctx.getStart()
- .getLine());
+ LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(
+ leafListQName, actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(leafListName);
- parseSchemaNodeArgs(ctx, leafListBuilder);
- parseConstraints(ctx, leafListBuilder.getConstraints());
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
+ parseConstraints(ctx, builder.getConstraints());
for (int i = 0; i < ctx.getChildCount(); ++i) {
final ParseTree childNode = ctx.getChild(i);
if (childNode instanceof Ordered_by_stmtContext) {
final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode;
final boolean userOrdered = parseUserOrdered(orderedBy);
- leafListBuilder.setUserOrdered(userOrdered);
+ builder.setUserOrdered(userOrdered);
break;
}
}
public void exitLeaf_list_stmt(YangParser.Leaf_list_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
final String containerName = stringFromNode(ctx);
QName containerQName = new QName(namespace, revision, yangModelPrefix,
containerName);
- ListSchemaNodeBuilder listBuilder = moduleBuilder.addListNode(
+ ListSchemaNodeBuilder builder = moduleBuilder.addListNode(
containerQName, actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(containerName);
- listBuilder.setPath(createActualSchemaPath(actualPath, namespace,
- revision, yangModelPrefix));
- parseSchemaNodeArgs(ctx, listBuilder);
- parseConstraints(ctx, listBuilder.getConstraints());
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
+ parseConstraints(ctx, builder.getConstraints());
String keyDefinition = "";
for (int i = 0; i < ctx.getChildCount(); ++i) {
if (childNode instanceof Ordered_by_stmtContext) {
final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode;
final boolean userOrdered = parseUserOrdered(orderedBy);
- listBuilder.setUserOrdered(userOrdered);
+ builder.setUserOrdered(userOrdered);
} else if (childNode instanceof Key_stmtContext) {
keyDefinition = stringFromNode(childNode);
List<QName> key = createListKey(keyDefinition, namespace,
revision, yangModelPrefix);
- listBuilder.setKeyDefinition(key);
+ builder.setKeyDefinition(key);
}
}
}
public void exitList_stmt(List_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
final String anyXmlName = stringFromNode(ctx);
QName anyXmlQName = new QName(namespace, revision, yangModelPrefix,
anyXmlName);
- AnyXmlBuilder anyXmlBuilder = moduleBuilder.addAnyXml(anyXmlQName,
+ AnyXmlBuilder builder = moduleBuilder.addAnyXml(anyXmlQName,
actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(anyXmlName);
- anyXmlBuilder.setPath(createActualSchemaPath(actualPath, namespace,
- revision, yangModelPrefix));
- parseSchemaNodeArgs(ctx, anyXmlBuilder);
- parseConstraints(ctx, anyXmlBuilder.getConstraints());
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
+ parseConstraints(ctx, builder.getConstraints());
}
@Override
public void exitAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
final String choiceName = stringFromNode(ctx);
QName choiceQName = new QName(namespace, revision, yangModelPrefix,
choiceName);
- ChoiceBuilder choiceBuilder = moduleBuilder.addChoice(choiceQName,
+ ChoiceBuilder builder = moduleBuilder.addChoice(choiceQName,
actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(choiceName);
- choiceBuilder.setPath(createActualSchemaPath(actualPath, namespace,
- revision, yangModelPrefix));
- parseSchemaNodeArgs(ctx, choiceBuilder);
- parseConstraints(ctx, choiceBuilder.getConstraints());
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
+ parseConstraints(ctx, builder.getConstraints());
// set 'default' case
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof Default_stmtContext) {
String defaultCase = stringFromNode(child);
- choiceBuilder.setDefaultCase(defaultCase);
+ builder.setDefaultCase(defaultCase);
break;
}
}
public void exitChoice_stmt(YangParser.Choice_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
final String caseName = stringFromNode(ctx);
QName choiceQName = new QName(namespace, revision, yangModelPrefix,
caseName);
- ChoiceCaseBuilder caseBuilder = moduleBuilder.addCase(choiceQName,
+ ChoiceCaseBuilder builder = moduleBuilder.addCase(choiceQName,
actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(caseName);
- caseBuilder.setPath(createActualSchemaPath(actualPath, namespace,
- revision, yangModelPrefix));
- parseSchemaNodeArgs(ctx, caseBuilder);
- parseConstraints(ctx, caseBuilder.getConstraints());
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
+ parseConstraints(ctx, builder.getConstraints());
}
@Override
public void exitCase_stmt(YangParser.Case_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
final String notificationName = stringFromNode(ctx);
QName notificationQName = new QName(namespace, revision,
yangModelPrefix, notificationName);
- NotificationBuilder notificationBuilder = moduleBuilder
- .addNotification(notificationQName, actualPath, ctx.getStart()
- .getLine());
+ NotificationBuilder builder = moduleBuilder.addNotification(
+ notificationQName, actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(notificationName);
- notificationBuilder.setPath(createActualSchemaPath(actualPath,
- namespace, revision, yangModelPrefix));
- parseSchemaNodeArgs(ctx, notificationBuilder);
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
}
@Override
public void exitNotification_stmt(YangParser.Notification_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
// Unknown types
builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
+ moduleBuilder.enterNode(builder);
}
@Override
public void exitIdentifier_stmt(YangParser.Identifier_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
rpcName);
RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(rpcQName,
actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(rpcBuilder);
updatePath(rpcName);
rpcBuilder.setPath(createActualSchemaPath(actualPath, namespace,
public void exitRpc_stmt(YangParser.Rpc_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
public void enterInput_stmt(YangParser.Input_stmtContext ctx) {
- updatePath("input");
+ final String input = "input";
+ QName rpcQName = new QName(namespace, revision, yangModelPrefix, input);
+ ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(
+ rpcQName, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
+ updatePath(input);
+
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
+ parseConstraints(ctx, builder.getConstraints());
}
@Override
public void exitInput_stmt(YangParser.Input_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
public void enterOutput_stmt(YangParser.Output_stmtContext ctx) {
- updatePath("output");
+ final String output = "output";
+ QName rpcQName = new QName(namespace, revision, yangModelPrefix, output);
+ ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(
+ rpcQName, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
+ updatePath(output);
+
+ builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
+ yangModelPrefix));
+ parseSchemaNodeArgs(ctx, builder);
+ parseConstraints(ctx, builder.getConstraints());
}
@Override
public void exitOutput_stmt(YangParser.Output_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
featureName);
FeatureBuilder featureBuilder = moduleBuilder.addFeature(featureQName,
actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(featureBuilder);
updatePath(featureName);
featureBuilder.setPath(createActualSchemaPath(actualPath, namespace,
public void exitFeature_stmt(YangParser.Feature_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
String deviate = null;
DeviationBuilder builder = moduleBuilder.addDeviation(targetPath,
actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(targetPath);
for (int i = 0; i < ctx.getChildCount(); i++) {
public void exitDeviation_stmt(YangParser.Deviation_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
@Override
public void enterConfig_stmt(YangParser.Config_stmtContext ctx) {
boolean configuration = parseConfig(ctx);
- moduleBuilder.addConfiguration(configuration, actualPath);
+ moduleBuilder.addConfiguration(configuration, actualPath, ctx
+ .getStart().getLine());
}
@Override
yangModelPrefix, identityName);
IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity(
identityQName, actualPath, ctx.getStart().getLine());
+ moduleBuilder.enterNode(builder);
updatePath(identityName);
builder.setPath(createActualSchemaPath(actualPath, namespace, revision,
public void exitIdentity_stmt(YangParser.Identity_stmtContext ctx) {
final String actContainer = actualPath.pop();
logger.debug("exiting " + actContainer);
+ moduleBuilder.exitNode();
}
public ModuleBuilder getModuleBuilder() {
import org.opendaylight.controller.yang.model.util.UnionType;
import org.opendaylight.controller.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.parser.builder.api.Builder;
-import org.opendaylight.controller.yang.parser.builder.api.ChildNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.api.DataNodeContainerBuilder;
import org.opendaylight.controller.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
import org.opendaylight.controller.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.LeafSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ListSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ModuleBuilder;
-import org.opendaylight.controller.yang.parser.builder.impl.TypedefBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.UsesNodeBuilderImpl;
*/
public static void fillAugmentTarget(
final AugmentationSchemaBuilder augment,
- final ChildNodeBuilder target) {
+ final DataNodeContainerBuilder target) {
for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
builder.setAugmenting(true);
correctAugmentChildPath(augment, target.getPath());
}
}
- private static void correctAugmentChildPath(final ChildNodeBuilder node,
+ public static void fillAugmentTarget(
+ final AugmentationSchemaBuilder augment,
+ final ChoiceBuilder target) {
+ for (DataSchemaNodeBuilder builder : augment.getChildNodes()) {
+ builder.setAugmenting(true);
+ correctAugmentChildPath(augment, target.getPath());
+ target.addChildNode(builder);
+ }
+ }
+
+ private static void correctAugmentChildPath(final DataNodeContainerBuilder node,
final SchemaPath parentSchemaPath) {
for (DataSchemaNodeBuilder builder : node.getChildNodes()) {
targetNodePath.add(builder.getQName());
builder.setPath(new SchemaPath(targetNodePath, true));
- if (builder instanceof ChildNodeBuilder) {
- ChildNodeBuilder cnb = (ChildNodeBuilder) builder;
+ if (builder instanceof DataNodeContainerBuilder) {
+ DataNodeContainerBuilder cnb = (DataNodeContainerBuilder) builder;
correctAugmentChildPath(cnb, builder.getPath());
}
// if child can contains type, correct path for this type too
- if(builder instanceof TypeAwareBuilder) {
- TypeAwareBuilder nodeBuilder = (TypeAwareBuilder)builder;
+ if (builder instanceof TypeAwareBuilder) {
+ TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) builder;
QName nodeBuilderQName = nodeBuilder.getQName();
TypeDefinition<?> nodeBuilderType = nodeBuilder.getType();
- if(nodeBuilderType != null) {
- TypeDefinition<?> newType = createCorrectTypeDefinition(parentSchemaPath, nodeBuilderQName, nodeBuilderType);
+ if (nodeBuilderType != null) {
+ TypeDefinition<?> newType = createCorrectTypeDefinition(
+ parentSchemaPath, nodeBuilderQName, nodeBuilderType);
nodeBuilder.setType(newType);
} else {
- TypeDefinitionBuilder nodeBuilderTypedef = nodeBuilder.getTypedef();
- SchemaPath newSchemaPath = createNewSchemaPath(nodeBuilderTypedef.getPath(), nodeBuilderQName, nodeBuilderTypedef.getQName());
+ TypeDefinitionBuilder nodeBuilderTypedef = nodeBuilder
+ .getTypedef();
+ SchemaPath newSchemaPath = createNewSchemaPath(
+ nodeBuilderTypedef.getPath(), nodeBuilderQName,
+ nodeBuilderTypedef.getQName());
nodeBuilderTypedef.setPath(newSchemaPath);
}
}
}
}
- private static TypeDefinition<?> createCorrectTypeDefinition(SchemaPath parentSchemaPath, QName nodeQName, TypeDefinition<?> nodeType) {
+ private static TypeDefinition<?> createCorrectTypeDefinition(
+ SchemaPath parentSchemaPath, QName nodeQName,
+ TypeDefinition<?> nodeType) {
TypeDefinition<?> result = null;
SchemaPath newSchemaPath = null;
- if(nodeType != null) {
- if(nodeType instanceof BinaryTypeDefinition) {
- BinaryTypeDefinition binType = (BinaryTypeDefinition)nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, binType.getQName());
- List<Byte> bytes = (List<Byte>)binType.getDefaultValue();
- result = new BinaryType(newSchemaPath, bytes, binType.getLengthConstraints(), binType.getUnits());
- } else if(nodeType instanceof BitsTypeDefinition) {
- BitsTypeDefinition bitsType = (BitsTypeDefinition)nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeType.getQName());
- result = new BitsType(newSchemaPath, bitsType.getBits(), bitsType.getUnits());
- } else if(nodeType instanceof BooleanTypeDefinition) {
- BooleanTypeDefinition booleanType = (BooleanTypeDefinition)nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, booleanType.getQName());
- result = new BooleanType(newSchemaPath, (Boolean)booleanType.getDefaultValue(), booleanType.getUnits());
- } else if(nodeType instanceof DecimalTypeDefinition) {
- DecimalTypeDefinition decimalType = (DecimalTypeDefinition)nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, decimalType.getQName());
- BigDecimal defaultValue = (BigDecimal)decimalType.getDefaultValue();
- result = new Decimal64(newSchemaPath, decimalType.getUnits(), defaultValue, decimalType.getRangeStatements(), decimalType.getFractionDigits());
- } else if(nodeType instanceof EmptyTypeDefinition) {
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeType.getQName());
+ if (nodeType != null) {
+ if (nodeType instanceof BinaryTypeDefinition) {
+ BinaryTypeDefinition binType = (BinaryTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, binType.getQName());
+ List<Byte> bytes = (List<Byte>) binType.getDefaultValue();
+ result = new BinaryType(newSchemaPath, bytes,
+ binType.getLengthConstraints(), binType.getUnits());
+ } else if (nodeType instanceof BitsTypeDefinition) {
+ BitsTypeDefinition bitsType = (BitsTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, nodeType.getQName());
+ result = new BitsType(newSchemaPath, bitsType.getBits(),
+ bitsType.getUnits());
+ } else if (nodeType instanceof BooleanTypeDefinition) {
+ BooleanTypeDefinition booleanType = (BooleanTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, booleanType.getQName());
+ result = new BooleanType(newSchemaPath,
+ (Boolean) booleanType.getDefaultValue(),
+ booleanType.getUnits());
+ } else if (nodeType instanceof DecimalTypeDefinition) {
+ DecimalTypeDefinition decimalType = (DecimalTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, decimalType.getQName());
+ BigDecimal defaultValue = (BigDecimal) decimalType
+ .getDefaultValue();
+ result = new Decimal64(newSchemaPath, decimalType.getUnits(),
+ defaultValue, decimalType.getRangeStatements(),
+ decimalType.getFractionDigits());
+ } else if (nodeType instanceof EmptyTypeDefinition) {
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, nodeType.getQName());
result = new EmptyType(newSchemaPath);
- } else if(nodeType instanceof EnumTypeDefinition) {
- EnumTypeDefinition enumType = (EnumTypeDefinition)nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, enumType.getQName());
- result = new EnumerationType(newSchemaPath, (EnumPair)enumType.getDefaultValue(), enumType.getValues(), enumType.getUnits());
- } else if(nodeType instanceof IdentityrefTypeDefinition) {
- IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition)nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, idrefType.getQName());
- result = new IdentityrefType(idrefType.getIdentity(), newSchemaPath);
- } else if(nodeType instanceof InstanceIdentifierTypeDefinition) {
- InstanceIdentifierTypeDefinition instIdType = (InstanceIdentifierTypeDefinition)nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, instIdType.getQName());
- return new InstanceIdentifier(newSchemaPath, instIdType.getPathStatement(), instIdType.requireInstance());
- } else if(nodeType instanceof StringTypeDefinition) {
- result = copyStringType(parentSchemaPath, nodeQName, (StringTypeDefinition)nodeType);
- } else if(nodeType instanceof IntegerTypeDefinition) {
- result = copyIntType(parentSchemaPath, nodeQName, (IntegerTypeDefinition)nodeType);
- } else if(nodeType instanceof UnsignedIntegerTypeDefinition) {
- result = copyUIntType(parentSchemaPath, nodeQName, (UnsignedIntegerTypeDefinition)nodeType);
- } else if(nodeType instanceof LeafrefTypeDefinition) {
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, nodeType.getQName());
- result = new Leafref(newSchemaPath, ((LeafrefTypeDefinition)nodeType).getPathStatement());
- } else if(nodeType instanceof UnionTypeDefinition) {
- UnionTypeDefinition unionType = (UnionTypeDefinition)nodeType;
- newSchemaPath = createNewSchemaPath(parentSchemaPath, nodeQName, unionType.getQName());
+ } else if (nodeType instanceof EnumTypeDefinition) {
+ EnumTypeDefinition enumType = (EnumTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, enumType.getQName());
+ result = new EnumerationType(newSchemaPath,
+ (EnumPair) enumType.getDefaultValue(),
+ enumType.getValues(), enumType.getUnits());
+ } else if (nodeType instanceof IdentityrefTypeDefinition) {
+ IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, idrefType.getQName());
+ result = new IdentityrefType(idrefType.getIdentity(),
+ newSchemaPath);
+ } else if (nodeType instanceof InstanceIdentifierTypeDefinition) {
+ InstanceIdentifierTypeDefinition instIdType = (InstanceIdentifierTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, instIdType.getQName());
+ return new InstanceIdentifier(newSchemaPath,
+ instIdType.getPathStatement(),
+ instIdType.requireInstance());
+ } else if (nodeType instanceof StringTypeDefinition) {
+ result = copyStringType(parentSchemaPath, nodeQName,
+ (StringTypeDefinition) nodeType);
+ } else if (nodeType instanceof IntegerTypeDefinition) {
+ result = copyIntType(parentSchemaPath, nodeQName,
+ (IntegerTypeDefinition) nodeType);
+ } else if (nodeType instanceof UnsignedIntegerTypeDefinition) {
+ result = copyUIntType(parentSchemaPath, nodeQName,
+ (UnsignedIntegerTypeDefinition) nodeType);
+ } else if (nodeType instanceof LeafrefTypeDefinition) {
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, nodeType.getQName());
+ result = new Leafref(newSchemaPath,
+ ((LeafrefTypeDefinition) nodeType).getPathStatement());
+ } else if (nodeType instanceof UnionTypeDefinition) {
+ UnionTypeDefinition unionType = (UnionTypeDefinition) nodeType;
+ newSchemaPath = createNewSchemaPath(parentSchemaPath,
+ nodeQName, unionType.getQName());
return new UnionType(newSchemaPath, unionType.getTypes());
}
}
return result;
}
- private static TypeDefinition<?> copyStringType(SchemaPath schemaPath, QName nodeQName, StringTypeDefinition nodeType) {
+ private static TypeDefinition<?> copyStringType(SchemaPath schemaPath,
+ QName nodeQName, StringTypeDefinition nodeType) {
List<QName> path = schemaPath.getPath();
List<QName> newPath = new ArrayList<QName>(path);
newPath.add(nodeQName);
newPath.add(nodeType.getQName());
- SchemaPath newSchemaPath = new SchemaPath(newPath, schemaPath.isAbsolute());
+ SchemaPath newSchemaPath = new SchemaPath(newPath,
+ schemaPath.isAbsolute());
String newDefault = nodeType.getDefaultValue().toString();
String newUnits = nodeType.getUnits();
List<LengthConstraint> lengths = nodeType.getLengthStatements();
List<PatternConstraint> patterns = nodeType.getPatterns();
- return new StringType(newSchemaPath, newDefault, lengths, patterns, newUnits);
+ return new StringType(newSchemaPath, newDefault, lengths, patterns,
+ newUnits);
}
- private static TypeDefinition<?> copyIntType(SchemaPath schemaPath, QName nodeQName, IntegerTypeDefinition type) {
+ private static TypeDefinition<?> copyIntType(SchemaPath schemaPath,
+ QName nodeQName, IntegerTypeDefinition type) {
QName typeQName = type.getQName();
- SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName, typeQName);
+ SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
+ typeQName);
String localName = typeQName.getLocalName();
List<RangeConstraint> ranges = type.getRangeStatements();
String units = type.getUnits();
- if("int8".equals(localName)) {
- Byte defaultValue = (Byte)type.getDefaultValue();
+ if ("int8".equals(localName)) {
+ Byte defaultValue = (Byte) type.getDefaultValue();
return new Int8(newSchemaPath, ranges, units, defaultValue);
- } else if("int16".equals(localName)) {
- Short defaultValue = (Short)type.getDefaultValue();
+ } else if ("int16".equals(localName)) {
+ Short defaultValue = (Short) type.getDefaultValue();
return new Int16(newSchemaPath, ranges, units, defaultValue);
- } else if("int32".equals(localName)) {
- Integer defaultValue = (Integer)type.getDefaultValue();
+ } else if ("int32".equals(localName)) {
+ Integer defaultValue = (Integer) type.getDefaultValue();
return new Int32(newSchemaPath, ranges, units, defaultValue);
- } else if("int64".equals(localName)) {
- Long defaultValue = (Long)type.getDefaultValue();
+ } else if ("int64".equals(localName)) {
+ Long defaultValue = (Long) type.getDefaultValue();
return new Int64(newSchemaPath, ranges, units, defaultValue);
} else {
return null;
}
}
- private static TypeDefinition<?> copyUIntType(SchemaPath schemaPath, QName nodeQName, UnsignedIntegerTypeDefinition type) {
+ private static TypeDefinition<?> copyUIntType(SchemaPath schemaPath,
+ QName nodeQName, UnsignedIntegerTypeDefinition type) {
QName typeQName = type.getQName();
- SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName, typeQName);
+ SchemaPath newSchemaPath = createNewSchemaPath(schemaPath, nodeQName,
+ typeQName);
String localName = typeQName.getLocalName();
List<RangeConstraint> ranges = type.getRangeStatements();
String units = type.getUnits();
- if("uint8".equals(localName)) {
- Byte defaultValue = (Byte)type.getDefaultValue();
+ if ("uint8".equals(localName)) {
+ Byte defaultValue = (Byte) type.getDefaultValue();
return new Int8(newSchemaPath, ranges, units, defaultValue);
- } else if("uint16".equals(localName)) {
- Short defaultValue = (Short)type.getDefaultValue();
+ } else if ("uint16".equals(localName)) {
+ Short defaultValue = (Short) type.getDefaultValue();
return new Int16(newSchemaPath, ranges, units, defaultValue);
- } else if("uint32".equals(localName)) {
- Integer defaultValue = (Integer)type.getDefaultValue();
+ } else if ("uint32".equals(localName)) {
+ Integer defaultValue = (Integer) type.getDefaultValue();
return new Int32(newSchemaPath, ranges, units, defaultValue);
- } else if("uint64".equals(localName)) {
- Long defaultValue = (Long)type.getDefaultValue();
+ } else if ("uint64".equals(localName)) {
+ Long defaultValue = (Long) type.getDefaultValue();
return new Int64(newSchemaPath, ranges, units, defaultValue);
} else {
return null;
}
}
- private static SchemaPath createNewSchemaPath(SchemaPath schemaPath, QName currentQName, QName qname) {
+ private static SchemaPath createNewSchemaPath(SchemaPath schemaPath,
+ QName currentQName, QName qname) {
List<QName> newPath = new ArrayList<QName>(schemaPath.getPath());
newPath.add(currentQName);
newPath.add(qname);
}
}
+ public static void checkRefine(SchemaNodeBuilder node, RefineHolder refine) {
+ String name = node.getQName().getLocalName();
+ int line = refine.getLine();
+
+ String defaultStr = refine.getDefaultStr();
+ Boolean mandatory = refine.isMandatory();
+ Boolean presence = refine.isPresence();
+ MustDefinition must = refine.getMust();
+ Integer min = refine.getMinElements();
+ Integer max = refine.getMaxElements();
+
+ if (node instanceof AnyXmlBuilder) {
+ checkRefineDefault(node, defaultStr, line);
+ checkRefinePresence(node, presence, line);
+ checkRefineMinMax(name, line, min, max);
+ } else if (node instanceof ChoiceBuilder) {
+ checkRefinePresence(node, presence, line);
+ checkRefineMust(node, must, line);
+ checkRefineMinMax(name, line, min, max);
+ } else if (node instanceof ContainerSchemaNodeBuilder) {
+ checkRefineDefault(node, defaultStr, line);
+ checkRefineMandatory(node, mandatory, line);
+ checkRefineMust(node, must, line);
+ checkRefineMinMax(name, line, min, max);
+ } else if (node instanceof LeafSchemaNodeBuilder) {
+ checkRefinePresence(node, presence, line);
+ checkRefineMinMax(name, line, min, max);
+ } else if (node instanceof LeafListSchemaNodeBuilder
+ || node instanceof ListSchemaNodeBuilder) {
+ checkRefineDefault(node, defaultStr, line);
+ checkRefinePresence(node, presence, line);
+ checkRefineMandatory(node, mandatory, line);
+ } else if (node instanceof GroupingBuilder
+ || node instanceof TypeDefinitionBuilder
+ || node instanceof UsesNodeBuilder) {
+ checkRefineDefault(node, defaultStr, line);
+ checkRefinePresence(node, presence, line);
+ checkRefineMandatory(node, mandatory, line);
+ checkRefineMust(node, must, line);
+ checkRefineMinMax(name, line, min, max);
+ }
+ }
+
+ private static void checkRefineDefault(SchemaNodeBuilder node,
+ String defaultStr, int line) {
+ if (defaultStr != null) {
+ throw new YangParseException(line, "Can not refine 'default' for '"
+ + node.getQName().getLocalName() + "'.");
+ }
+ }
+
+ private static void checkRefineMandatory(SchemaNodeBuilder node,
+ Boolean mandatory, int line) {
+ if (mandatory != null) {
+ throw new YangParseException(line,
+ "Can not refine 'mandatory' for '"
+ + node.getQName().getLocalName() + "'.");
+ }
+ }
+
+ private static void checkRefinePresence(SchemaNodeBuilder node,
+ Boolean presence, int line) {
+ if (presence != null) {
+ throw new YangParseException(line,
+ "Can not refine 'presence' for '"
+ + node.getQName().getLocalName() + "'.");
+ }
+ }
+
+ private static void checkRefineMust(SchemaNodeBuilder node,
+ MustDefinition must, int line) {
+ if (must != null) {
+ throw new YangParseException(line, "Can not refine 'must' for '"
+ + node.getQName().getLocalName() + "'.");
+ }
+ }
+
+ private static void checkRefineMinMax(String refineTargetName,
+ int refineLine, Integer min, Integer max) {
+ if (min != null || max != null) {
+ throw new YangParseException(refineLine,
+ "Can not refine 'min-elements' or 'max-elements' for '"
+ + refineTargetName + "'.");
+ }
+ }
+
/**
* Perform refine operation of following parameters:
* <ul>
final TypeDefinition<?> type = old.getType();
if (type == null) {
- copy.setType(old.getTypedef());
+ copy.setTypedef(old.getTypedef());
} else {
copy.setType(type);
}
for (GroupingBuilder grouping : old.getGroupings()) {
copy.addGrouping(grouping);
}
- for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
+ for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
copy.addTypedef(typedef);
}
for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
for (GroupingBuilder grouping : old.getGroupings()) {
copy.addGrouping(grouping);
}
- for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
+ for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
copy.addTypedef(typedef);
}
for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
copyConstraints(old, copy);
final TypeDefinition<?> type = old.getType();
if (type == null) {
- copy.setType(old.getTypedef());
+ copy.setTypedef(old.getTypedef());
} else {
copy.setType(type);
}
for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
copy.addUnknownSchemaNode(unknown);
}
- for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
- copy.addTypedef(typedef);
- }
- for (UsesNodeBuilder use : old.getUsesNodes()) {
- copy.addUsesNode(use);
- }
copy.setDefaultCase(old.getDefaultCase());
copy.setDescription(old.getDescription());
copy.setReference(old.getReference());
for (GroupingBuilder grouping : old.getGroupings()) {
copy.addGrouping(grouping);
}
- for (TypeDefinitionBuilder typedef : old.getTypedefs()) {
+ for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
copy.addTypedef(typedef);
}
for (UsesNodeBuilder use : old.getUses()) {
return copy;
}
- public static TypedefBuilder copyTypedefBuilder(TypedefBuilder old) {
- final TypedefBuilder copy = new TypedefBuilder(old.getQName(),
- old.getLine());
+ public static TypeDefinitionBuilderImpl copyTypedefBuilder(
+ TypeDefinitionBuilderImpl old) {
+ final TypeDefinitionBuilderImpl copy = new TypeDefinitionBuilderImpl(
+ old.getQName(), old.getLine());
copy.setPath(old.getPath());
copy.setDefaultValue(old.getDefaultValue());
copy.setUnits(old.getUnits());
copy.setFractionDigits(old.getFractionDigits());
TypeDefinition<?> type = old.getType();
- if(type == null) {
- copy.setType(old.getTypedef());
+ if (type == null) {
+ copy.setTypedef(old.getTypedef());
} else {
copy.setType(old.getType());
}
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
return parser.parseYangModels(testFiles);
}
+ public static Set<Module> loadModules(String... pathToYangFile) throws IOException {
+ YangModelParser parser = new YangParserImpl();
+ List<InputStream> input = new ArrayList<InputStream>();
+ for(String path : pathToYangFile) {
+ input.add(TestUtils.class.getResourceAsStream(path));
+ }
+ Set<Module> modules = parser.parseYangModelsFromStreams(input);
+ for(InputStream stream : input) {
+ stream.close();
+ }
+ return modules;
+ }
+
+ public static Module loadModule(String pathToYangFile) throws IOException {
+ YangModelParser parser = new YangParserImpl();
+ InputStream stream = TestUtils.class.getResourceAsStream(pathToYangFile);
+ List<InputStream> input = Collections.singletonList(stream);
+ Set<Module> modules = parser.parseYangModelsFromStreams(input);
+ stream.close();
+ return modules.iterator().next();
+ }
+
public static Module findModule(Set<Module> modules, String moduleName) {
Module result = null;
for (Module module : modules) {
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.opendaylight.controller.yang.parser.util.YangParseException;
+import org.opendaylight.controller.yang.parser.util.YangValidationException;
+
+public class YangParserNegativeTest {
+
+ @Test
+ public void testInvalidImport() throws IOException {
+ try {
+ TestUtils.loadModule("/negative-scenario/testfile1.yang");
+ fail("ValidationException should by thrown");
+ } catch(YangValidationException e) {
+ assertTrue(e.getMessage().contains("Not existing module imported"));
+ }
+ }
+
+ @Test
+ public void testTypeNotFound() throws IOException {
+ try {
+ TestUtils.loadModule("/negative-scenario/testfile2.yang");
+ fail("YangParseException should by thrown");
+ } catch(YangParseException e) {
+ assertTrue(e.getMessage().contains("Error in module 'test2' on line 24: Referenced type 'int-ext' not found."));
+ }
+ }
+
+ @Test
+ public void testInvalidAugmentTarget() throws IOException {
+ try {
+ TestUtils.loadModules("/negative-scenario/testfile0.yang", "/negative-scenario/testfile3.yang");
+ fail("YangParseException should by thrown");
+ } catch(YangParseException e) {
+ assertTrue(e.getMessage().contains("Failed to resolve augments in module 'test3'."));
+ }
+ }
+
+ @Test
+ public void testInvalidRefine() throws IOException {
+ try {
+ TestUtils.loadModule("/negative-scenario/testfile4.yang");
+ fail("YangParseException should by thrown");
+ } catch(YangParseException e) {
+ assertTrue(e.getMessage().contains("Can not refine 'presence' for 'node'."));
+ }
+ }
+
+}
assertNotNull(refineContainer);
Set<MustDefinition> mustConstraints = refineContainer.getConstraints()
.getMustConstraints();
- assertEquals(1, mustConstraints.size());
- MustDefinition must = mustConstraints.iterator().next();
- assertEquals("must-condition", must.toString());
- assertEquals("An error message test", must.getErrorMessage());
- assertEquals(("An error app tag test"), must.getErrorAppTag());
+ assertTrue(mustConstraints.isEmpty());
assertEquals("description of port defined by refine",
refineContainer.getDescription());
assertEquals("port reference added by refine",
}
}
}
-
+
+ container mycont {
+ container innercont {
+ typedef mytype {
+ type string;
+ }
+
+ leaf myleaf {
+ type mytype;
+ }
+ }
+ }
+
}
}
}
refine port {
- must "must-condition" {
- error-message "An error message test";
- error-app-tag "An error app tag test";
- }
description "description of port defined by refine";
reference "port reference added by refine";
config false;
--- /dev/null
+module test0 {
+ yang-version 1;
+ namespace "urn:simple.container.demo";
+ prefix "t1";
+
+ container interfaces {
+
+ }
+}
--- /dev/null
+module test1 {
+ yang-version 1;
+ namespace "urn:simple.container.demo";
+ prefix "t1";
+
+ import some-module {
+ prefix "data";
+ revision-date 2013-02-27;
+ }
+
+}
--- /dev/null
+module test2 {
+ yang-version 1;
+ namespace "urn:simple.types.data.demo";
+ prefix "t2";
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org/";
+
+ description "This is types-data test description";
+
+ revision "2013-02-27" {
+ reference " WILL BE DEFINED LATER";
+ }
+
+ container c1 {
+ typedef int-ext {
+ type int32 {
+ range "10..20";
+ }
+ }
+ }
+
+ container top {
+ leaf id {
+ type int-ext;
+ }
+ }
+
+}
--- /dev/null
+module test3 {
+ yang-version 1;
+ namespace "urn:simple.container.demo";
+ prefix "t1";
+
+ import test0 {
+ prefix "data";
+ }
+
+ augment "/data:unknown" {
+ when "if:ifType='ds0'";
+ leaf interface-id {
+ type leafref {
+ path "/if:interfaces/if:interface/if:name";
+ }
+ }
+ }
+
+}
--- /dev/null
+module test4 {
+ yang-version 1;
+ namespace "urn:simple.container.demo";
+ prefix "t1";
+
+ grouping tree {
+ leaf-list node {
+ type string;
+ }
+ container holder {
+
+ }
+ }
+
+ container schema {
+ uses tree {
+ refine node {
+ presence "true";
+ }
+ refine holder {
+ default "one";
+ }
+ }
+ }
+
+}
.getGlobalInstance(IUserManager.class, this);
if (userManager != null) {
return userManager.getPassword(username);
- } else
+ } else {
throw new RuntimeException("User Manager reference is null");
+ }
}
@Override
IUserManager userManager = (IUserManager) ServiceHelper
.getGlobalInstance(IUserManager.class, this);
if (userManager != null) {
- final List<String> levels = new ArrayList<String>();
- UserLevel level = userManager.getUserLevel(username);
- if (level == null) level = UserLevel.NOUSER;
- levels.add(level.toString());
- return new GenericPrincipal(username, "", levels);
- } else
+ List<String> controllerRoles = new ArrayList<String>();
+ for (UserLevel level : userManager.getUserLevels(username)) {
+ controllerRoles.add(level.toString());
+ }
+ return new GenericPrincipal(username, "", controllerRoles);
+ } else {
throw new RuntimeException("User Manager reference is null");
-
+ }
}
@Override
logger.error("Authentication failed for user " + username);
return null;
}
- } else
+ } else {
throw new RuntimeException("User Manager reference is null");
+ }
}
}
@Override
public byte[] getNodeMAC(Node node) {
- MacAddress mac = (MacAddress) nodeProps.get(MacAddress.name);
+ MacAddress mac = (MacAddress) this.getNodeProp(node,
+ MacAddress.name);
return (mac != null) ? mac.getMacAddress() : null;
}
/**
* Returns the list of roles associated to the passed user name
- *
+ *
* @param userName
* @return the role associated to the user name
*/
/**
* Authenticate user with AAA server and return authentication and
* authorization info
- *
+ *
* @param username
* the username
* @param password
/**
* Add/remove AAA server
- *
+ *
* @param configObject
* {@link org.opendaylight.controller.usermanager.internal.ServerConfig}
* Server Configuration
/**
* Remove AAA server
- *
+ *
* @param configObject
* refer to
* {@link org.opendaylight.controller.usermanager.internal.ServerConfig}
/**
* Add a local user
- *
+ *
* @param configObject
* {@link org.opendaylight.controller.usermanager.internal.UserConfig}
* User Configuration
/**
* Remove a local user
- *
+ *
* @param configObject
* {@link org.opendaylight.controller.usermanager.internal.UserConfig}
* UserConfig
/**
* Remove a local user
- *
+ *
* @param userName
* the user name
* @return {@link org.opendaylight.controller.sal.utils.Status}
/**
* Add the authorization information for a user that gets authenticated
* remotely
- *
+ *
* @param AAAconf
* {@link org.opendaylight.controller.usermanager.internal.AuthorizationConfig}
* Authorization Resources
/**
* Remove the authorization information for a user that gets authenticated
* remotely
- *
+ *
* @param AAAconf
* {@link org.opendaylight.controller.usermanager.internal.AuthorizationConfig}
* Authorization Resource
/**
* Return the list of authorization resources
- *
+ *
* @return {@link org.opendaylight.controller.usermanager.internal.AuthorizationConfig}
* List of Authorization Resource
*/
/**
* Returns a list of AAA Providers.
- *
+ *
* @return Set of provider names.
*/
public Set<String> getAAAProviderNames();
/**
* Change the current password for a locally configured user
- *
+ *
* @param user
* the username
* @param curPasssword
/**
* Return a list of AAA servers currently configured
- *
+ *
* @return {@link org.opendaylight.controller.usermanager.internal.ServerConfig}
* List of ServerConfig
*/
/**
* Return a list of local users
- *
+ *
* @return {@link org.opendaylight.controller.usermanager.internal.UserConfig}
* List of UserConfig
*/
/**
* Save the local users to disk
- *
+ *
* @return {@link org.opendaylight.controller.sal.utils.Status}
* status of this action
*/
/**
* Save the AAA server configurations to disk
- *
+ *
* @return {@link org.opendaylight.controller.sal.utils.Status}
* status of this action
*/
/**
* Save the Authorization configurations to disk
- *
+ *
* @return {@link org.opendaylight.controller.sal.utils.Status}
* status code
*/
/**
* Remove user profile when user logs out
- *
+ *
* @param username
* the user name
*/
/**
* Remove user profile when user times out
- *
+ *
* @param username
* the user name
*/
/**
* Get the list of users currently logged in
- *
+ *
* @return the list of users along with their administrative roles
*/
public Map<String, List<String>> getUserLoggedIn();
/**
* Get date and time user was successfully authenticated
- *
+ *
* @param user
* @return Date in String format
*/
public String getAccessDate(String user);
/**
- * Returns the user level for the passed user name. It checks the roles
+ * Returns the highest user level for the passed user name. It checks the roles
* assigned to this user and checks against the well known Controller user
* roles to determines the highest user level associated with the user
- *
+ *
* @param userName
* the user name
* @return {@link org.opendaylight.controller.sal.authorization.UserLevel}
*/
public UserLevel getUserLevel(String userName);
+ /**
+ * Returns the list of user level for the passed user name. It checks the roles
+ * assigned to this user and checks against the well known Controller user
+ * roles to determines the corresponding list of user level associated with the user
+ *
+ * @param userName
+ * the user name
+ * @return
+ * the list of user level for this user
+ */
+ public List<UserLevel> getUserLevels(String userName);
+
/**
* Returns the Security Context
- *
+ *
* @returns {@link org.springframework.security.web.context.SecurityContextRepository}
* Security Context
*/
/**
* Returns the Session Manager Interface Handler
- *
+ *
* @return {@link org.opendaylight.controller.usermanager.ISessionManager}
* session manager interface handler
*/
/* non-Javadoc
* Returns the password for a given user
- *
+ *
* @param username
* the user name
* @return password for the username
private ConcurrentMap<String, UserConfig> localUserConfigList;
private ConcurrentMap<String, ServerConfig> remoteServerConfigList;
// local authorization info for remotely authenticated users
- private ConcurrentMap<String, AuthorizationConfig> authorizationConfList;
+ private ConcurrentMap<String, AuthorizationConfig> authorizationConfList;
private ConcurrentMap<String, AuthenticatedUser> activeUsers;
private ConcurrentMap<String, IAAAProvider> authProviders;
private ConcurrentMap<Long, String> localUserListSaveConfigEvent,
- remoteServerSaveConfigEvent, authorizationSaveConfigEvent;
+ remoteServerSaveConfigEvent, authorizationSaveConfigEvent;
private IClusterGlobalServices clusterGlobalService = null;
private SecurityContextRepository securityContextRepo = new UserSecurityContextRepository();
private IContainerAuthorization containerAuthorizationClient;
return authProviders.get(name);
}
+ @Override
public Set<String> getAAAProviderNames() {
return authProviders.keySet();
}
} else if (rcResponse.getStatus() == AuthResultEnum.AUTH_REJECT) {
logger.info(
"Remote Authentication Rejected User: \"{}\", from Server: {}, Reason:{}",
- new Object[] {userName, aaaServer.getAddress(),
- rcResponse.getStatus().toString()});
+ new Object[] { userName, aaaServer.getAddress(),
+ rcResponse.getStatus().toString() });
} else {
logger.info(
"Remote Authentication Failed for User: \"{}\", from Server: {}, Reason:{}",
- new Object[] {userName, aaaServer.getAddress(),
- rcResponse.getStatus().toString()});
+ new Object[] { userName, aaaServer.getAddress(),
+ rcResponse.getStatus().toString() });
}
}
}
putUserInActiveList(userName, result);
if (authorized) {
logger.info("User \"{}\" authorized for the following role(s): {}",
- userName, result.getUserRoles());
+ userName, result.getUserRoles());
} else {
logger.info("User \"{}\" Not Authorized for any role ", userName);
}
activeUsers.remove(user);
}
+ @Override
public Status saveLocalUserList() {
// Publish the save config event to the cluster nodes
localUserListSaveConfigEvent.put(new Date().getTime(), SAVE);
localUserConfigList), usersFileName);
}
+ @Override
public Status saveAAAServerList() {
// Publish the save config event to the cluster nodes
remoteServerSaveConfigEvent.put(new Date().getTime(), SAVE);
remoteServerConfigList), serversFileName);
}
+ @Override
public Status saveAuthorizationList() {
// Publish the save config event to the cluster nodes
authorizationSaveConfigEvent.put(new Date().getTime(), SAVE);
return status;
}
// Trigger cluster update
- localUserConfigList.put(user, targetConfigEntry);
+ localUserConfigList.put(user, targetConfigEntry);
logger.info("Password changed for User \"{}\"", user);
String userName = ci.nextArgument();
String password = ci.nextArgument();
String role = ci.nextArgument();
-
+
List<String> roles = new ArrayList<String>();
while (role != null) {
if (!role.trim().isEmpty()) {
if (target == null) {
ci.println("User not found");
return;
- }
+ }
ci.println(this.removeLocalUser(target));
}
/**
* Function called by the dependency manager when all the required
* dependencies are satisfied
- *
+ *
*/
void init() {
}
* Function called by the dependency manager when at least one dependency
* become unsatisfied or when the component is shutting down because for
* example bundle is being stopped.
- *
+ *
*/
void destroy() {
}
/**
* Function called by dependency manager after "init ()" is called and after
* the services provided by the class are registered in the service registry
- *
+ *
*/
void start() {
authProviders = new ConcurrentHashMap<String, IAAAProvider>();
* Function called by the dependency manager before the services exported by
* the component are unregistered, this will be followed by a "destroy ()"
* calls
- *
+ *
*/
void stop() {
}
return UserLevel.NOUSER;
}
+
+ @Override
+ public List<UserLevel> getUserLevels(String username) {
+ // Returns the controller well-know user levels for the passed user
+ List<String> rolesNames = null;
+ List<UserLevel> levels = new ArrayList<UserLevel>();
+
+ if (activeUsers.containsKey(username)) {
+ List<String> roles = activeUsers.get(username).getUserRoles();
+ rolesNames = (roles == null || roles.isEmpty()) ? null : roles;
+ } else if (localUserConfigList.containsKey(username)) {
+ UserConfig config = localUserConfigList.get(username);
+ rolesNames = (config == null) ? null : config.getRoles();
+ }
+
+ if (rolesNames == null) {
+ return levels;
+ }
+
+ // Check against the well known controller roles first
+ if (rolesNames.contains(UserLevel.SYSTEMADMIN.toString())) {
+ levels.add(UserLevel.SYSTEMADMIN);
+ }
+ if (rolesNames.contains(UserLevel.NETWORKADMIN.toString())) {
+ levels.add(UserLevel.NETWORKADMIN);
+ }
+ if (rolesNames.contains(UserLevel.NETWORKOPERATOR.toString())) {
+ levels.add(UserLevel.NETWORKOPERATOR);
+ }
+ // Check if container user now
+ if (containerAuthorizationClient != null) {
+ for (String roleName : rolesNames) {
+ if (containerAuthorizationClient.isApplicationRole(roleName)) {
+ levels.add(UserLevel.CONTAINERUSER);
+ break;
+ }
+ }
+ }
+ // Finally check if application user
+ if (applicationAuthorizationClients != null) {
+ for (String roleName : rolesNames) {
+ for (IResourceAuthorization client : this.applicationAuthorizationClients) {
+ if (client.isApplicationRole(roleName)) {
+ levels.add(UserLevel.APPUSER);
+ break;
+ }
+ }
+ }
+ }
+ return levels;
+ }
+
@Override
public Status saveConfiguration() {
boolean success = true;
.getPassword(), enabled, accountNonExpired,
credentialsNonExpired, accountNonLocked,
user.getGrantedAuthorities(getUserLevel(username)));
- } else
+ } else {
throw new UsernameNotFoundException("User not found " + username);
+ }
}
@Override
.getName())));
return authentication;
- } else
+ } else {
throw new BadCredentialsException(
"Username or credentials did not match");
+ }
}
this.sessionMgr = sessionMgr;
}
+ @Override
public String getPassword(String username) {
return localUserConfigList.get(username).getPassword();
}