import org.opendaylight.controller.yang.model.api.ModuleImport;
import org.opendaylight.controller.yang.model.api.NotificationDefinition;
import org.opendaylight.controller.yang.model.api.RpcDefinition;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UsesNode;
import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionAwareBuilder;
import org.opendaylight.controller.yang.model.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder;
+import org.opendaylight.controller.yang.model.parser.util.RefineHolder;
import org.opendaylight.controller.yang.model.parser.util.YangParseException;
/**
public class ModuleBuilder implements Builder {
private final ModuleImpl instance;
private final String name;
+ private URI namespace;
private String prefix;
private Date revision;
+ private int augmentsResolved;
+
private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
/**
@Override
public Module build() {
instance.setImports(imports);
+ instance.setNamespace(namespace);
// TYPEDEFS
final Set<TypeDefinition<?>> typedefs = buildModuleTypedefs(addedTypedefs);
return moduleNodes.get(path);
}
+ public Set<DataSchemaNodeBuilder> getChildNodes() {
+ final Set<DataSchemaNodeBuilder> childNodes = new HashSet<DataSchemaNodeBuilder>();
+ for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
+ .entrySet()) {
+ List<String> path = entry.getKey();
+ DataSchemaNodeBuilder child = entry.getValue();
+ if (path.size() == 2) {
+ childNodes.add(child);
+ }
+ }
+ return childNodes;
+ }
+
public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
return dirtyNodes;
}
return name;
}
+ public URI getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(final URI namespace) {
+ this.namespace = namespace;
+ }
+
public String getPrefix() {
return prefix;
}
return revision;
}
+ public int getAugmentsResolved() {
+ return augmentsResolved;
+ }
+
+ public void augmentResolved() {
+ augmentsResolved++;
+ }
+
public void addDirtyNode(final List<String> path) {
final List<String> dirtyNodePath = new ArrayList<String>(path);
final TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
dirtyNodes.put(dirtyNodePath, nodeBuilder);
}
- public void setNamespace(final URI namespace) {
- instance.setNamespace(namespace);
- }
-
public void setRevision(final Date revision) {
this.revision = revision;
instance.setRevision(revision);
public UsesNodeBuilder addUsesNode(final String groupingPathStr,
final List<String> parentPath) {
final List<String> pathToUses = new ArrayList<String>(parentPath);
-
- UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(groupingPathStr);
-
- ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
+ final UsesNodeBuilder usesBuilder = new UsesNodeBuilderImpl(
+ groupingPathStr);
+ final ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes
.get(pathToUses);
if (parent != null) {
parent.addUsesNode(usesBuilder);
pathToUses.add(groupingPathStr);
addedUsesNodes.put(pathToUses, usesBuilder);
-
+ moduleNodes.put(pathToUses, usesBuilder);
return usesBuilder;
}
- public RpcDefinitionBuilder addRpc(final QName qname,
+ public void addRefine(final RefineHolder refine,
final List<String> parentPath) {
- List<String> pathToRpc = new ArrayList<String>(parentPath);
+ final List<String> path = new ArrayList<String>(parentPath);
+ final Builder parent = moduleNodes.get(path);
+ if (!(parent instanceof UsesNodeBuilder)) {
+ throw new YangParseException("Failed to parse refine "
+ + refine.getName());
+ }
+ UsesNodeBuilder usesBuilder = (UsesNodeBuilder) parent;
+ usesBuilder.addRefine(refine);
+ path.add(refine.getName());
+ moduleNodes.put(path, refine);
+ }
- RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname);
+ public RpcDefinitionBuilder addRpc(final QName qname,
+ final List<String> parentPath) {
+ final List<String> pathToRpc = new ArrayList<String>(parentPath);
+ final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(qname);
pathToRpc.add(qname.getLocalName());
addedRpcs.put(pathToRpc, rpcBuilder);
- QName inputQName = new QName(qname.getNamespace(), qname.getRevision(),
- qname.getPrefix(), "input");
- ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
+ final QName inputQName = new QName(qname.getNamespace(),
+ qname.getRevision(), qname.getPrefix(), "input");
+ final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(
inputQName);
- List<String> pathToInput = new ArrayList<String>(pathToRpc);
+ final List<String> pathToInput = new ArrayList<String>(pathToRpc);
pathToInput.add("input");
moduleNodes.put(pathToInput, inputBuilder);
rpcBuilder.setInput(inputBuilder);
- QName outputQName = new QName(qname.getNamespace(),
+ final QName outputQName = new QName(qname.getNamespace(),
qname.getRevision(), qname.getPrefix(), "output");
- ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
+ final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(
outputQName);
- List<String> pathToOutput = new ArrayList<String>(pathToRpc);
+ final List<String> pathToOutput = new ArrayList<String>(pathToRpc);
pathToOutput.add("output");
moduleNodes.put(pathToOutput, outputBuilder);
rpcBuilder.setOutput(outputBuilder);
parent.setType(type);
}
- public void addUnionType(List<String> parentPath) {
+ public void addUnionType(final List<String> actualPath,
+ final URI namespace, final Date revision) {
+ List<String> pathToUnion = new ArrayList<String>(actualPath);
TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
- .get(parentPath);
- UnionTypeBuilder union = new UnionTypeBuilder();
+ .get(pathToUnion);
+ UnionTypeBuilder union = new UnionTypeBuilder(pathToUnion, namespace,
+ revision);
parent.setType(union);
- List<String> path = new ArrayList<String>(parentPath);
+ List<String> path = new ArrayList<String>(pathToUnion);
path.add("union");
moduleNodes.put(path, union);
}
+ public void addIdentityrefType(String baseString, List<String> parentPath,
+ SchemaPath schemaPath) {
+ TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes
+ .get(parentPath);
+ IdentityrefTypeBuilder identityref = new IdentityrefTypeBuilder(
+ baseString, schemaPath);
+ parent.setType(identityref);
+ dirtyNodes.put(parentPath, parent);
+ }
+
public DeviationBuilder addDeviation(String targetPath,
List<String> parentPath) {
final List<String> pathToDeviation = new ArrayList<String>(parentPath);
return builder;
}
- public IdentitySchemaNodeBuilder addIdentity(QName qname) {
+ public IdentitySchemaNodeBuilder addIdentity(QName qname,
+ List<String> parentPath) {
+ List<String> pathToIdentity = new ArrayList<String>(parentPath);
IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname);
+ pathToIdentity.add(qname.getLocalName());
+ moduleNodes.put(pathToIdentity, builder);
addedIdentities.add(builder);
return builder;
}
final List<String> pathToUnknown = new ArrayList<String>(parentPath);
final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(
qname);
-
- final SchemaNodeBuilder parent = (SchemaNodeBuilder) moduleNodes
- .get(pathToUnknown);
- if (parent != null) {
- parent.addUnknownSchemaNode(builder);
+ final Builder parent = moduleNodes.get(pathToUnknown);
+ if (parent instanceof RefineHolder) {
+ ((RefineHolder) parent).addUnknownSchemaNode(builder);
+ } else if (parent instanceof SchemaNodeBuilder) {
+ ((SchemaNodeBuilder) parent).addUnknownSchemaNode(builder);
}
-
- return new UnknownSchemaNodeBuilder(qname);
+ return builder;
}
private class ModuleImpl implements Module {