import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
import org.opendaylight.controller.yang.model.api.FeatureDefinition;
import org.opendaylight.controller.yang.model.api.GroupingDefinition;
+import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.api.ModuleImport;
import org.opendaylight.controller.yang.model.api.NotificationDefinition;
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.YangParseException;
/**
* This builder builds Module object. If this module is dependent on external
private final Map<List<String>, UsesNodeBuilder> addedUsesNodes = new HashMap<List<String>, UsesNodeBuilder>();
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>, TypeDefinitionBuilder> addedTypedefs = new HashMap<List<String>, TypeDefinitionBuilder>();
}
-
/**
* Build new Module object based on this builder.
*/
instance.setGroupings(groupings);
// USES
- final Set<UsesNode> usesNodeDefinitions = buildUsesNodes(addedUsesNodes);
- instance.setUses(usesNodeDefinitions);
+ final Set<UsesNode> usesDefinitions = buildUsesNodes(addedUsesNodes);
+ instance.setUses(usesDefinitions);
// FEATURES
final Set<FeatureDefinition> features = buildModuleFeatures(addedFeatures);
}
instance.setExtensionSchemaNodes(extensions);
+ // IDENTITIES
+ final Set<IdentitySchemaNode> identities = new HashSet<IdentitySchemaNode>();
+ for(IdentitySchemaNodeBuilder idBuilder : addedIdentities) {
+ identities.add(idBuilder.build());
+ }
+ instance.setIdentities(identities);
+
return instance;
}
return dirtyNodes;
}
+ public Set<AugmentationSchemaBuilder> getAddedAugments() {
+ return addedAugments;
+ }
+
+ public Set<IdentitySchemaNodeBuilder> getAddedIdentities() {
+ return addedIdentities;
+ }
+
public String getName() {
return name;
}
return revision;
}
- public Set<AugmentationSchemaBuilder> getAddedAugments() {
- return addedAugments;
- }
-
public void addDirtyNode(List<String> path) {
List<String> dirtyNodePath = new ArrayList<String>(path);
TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) moduleNodes
}
public ExtensionBuilder addExtension(QName qname) {
- ExtensionBuilder builder = new ExtensionBuilder(qname);
- return builder;
+ return new ExtensionBuilder(qname);
}
public ContainerSchemaNodeBuilder addContainerNode(QName containerName,
ChildNodeBuilder parent = (ChildNodeBuilder) moduleNodes.get(pathToUses);
if (parent != null) {
- if(parent instanceof AugmentationSchemaBuilder) {
- usesBuilder.setAugmenting(true);
- }
parent.addUsesNode(usesBuilder);
}
List<String> parentPath) {
List<String> pathToNotification = new ArrayList<String>(parentPath);
- NotificationBuilder notificationBuilder = new NotificationBuilder(
+ NotificationBuilder builder = new NotificationBuilder(
notificationName);
pathToNotification.add(notificationName.getLocalName());
- moduleNodes.put(pathToNotification, notificationBuilder);
- addedNotifications.add(notificationBuilder);
+ moduleNodes.put(pathToNotification, builder);
+ addedNotifications.add(builder);
- return notificationBuilder;
+ return builder;
}
public FeatureBuilder addFeature(QName featureName, List<String> parentPath) {
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.");
+ }
parent.setType(type);
}
+ public void addUnionType(List<String> parentPath) {
+ TypeAwareBuilder parent = (TypeAwareBuilder) moduleNodes.get(parentPath);
+ UnionTypeBuilder union = new UnionTypeBuilder();
+ parent.setType(union);
+
+ List<String> path = new ArrayList<String>(parentPath);
+ path.add("union");
+
+ moduleNodes.put(path, union);
+ }
+
public DeviationBuilder addDeviation(String targetPath) {
DeviationBuilder builder = new DeviationBuilder(targetPath);
addedDeviations.put(targetPath, builder);
return builder;
}
+ public IdentitySchemaNodeBuilder addIdentity(QName qname) {
+ IdentitySchemaNodeBuilder builder = new IdentitySchemaNodeBuilder(qname);
+ addedIdentities.add(builder);
+ return builder;
+ }
+
public void addConfiguration(boolean configuration, List<String> parentPath) {
Builder builder = moduleNodes.get(parentPath);
if (builder instanceof DeviationBuilder) {
}
public UnknownSchemaNodeBuilder addUnknownSchemaNode(QName qname, List<String> parentPath) {
- UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(qname);
- return builder;
+ return new UnknownSchemaNodeBuilder(qname);
}
private Map<QName, DataSchemaNode> childNodes = Collections.emptyMap();
private Set<GroupingDefinition> groupings = Collections.emptySet();
private Set<UsesNode> uses = Collections.emptySet();
- private List<ExtensionDefinition> extensionSchemaNodes = Collections.emptyList();
+ private List<ExtensionDefinition> extensionNodes = Collections.emptyList();
+ private Set<IdentitySchemaNode> identities = Collections.emptySet();
private ModuleImpl(String name) {
this.name = name;
}
private void setImports(Set<ModuleImport> imports) {
- this.imports = imports;
+ if(imports != null) {
+ this.imports = imports;
+ }
}
@Override
}
private void setFeatures(Set<FeatureDefinition> features) {
- this.features = features;
+ if(features != null) {
+ this.features = features;
+ }
}
@Override
}
private void setTypeDefinitions(Set<TypeDefinition<?>> typeDefinitions) {
- this.typeDefinitions = typeDefinitions;
+ if(typeDefinitions != null) {
+ this.typeDefinitions = typeDefinitions;
+ }
}
@Override
}
private void setNotifications(Set<NotificationDefinition> notifications) {
- this.notifications = notifications;
+ if(notifications != null) {
+ this.notifications = notifications;
+ }
}
@Override
}
private void setAugmentations(Set<AugmentationSchema> augmentations) {
- this.augmentations = augmentations;
+ if(augmentations != null) {
+ this.augmentations = augmentations;
+ }
}
@Override
}
private void setRpcs(Set<RpcDefinition> rpcs) {
- this.rpcs = rpcs;
+ if(rpcs != null) {
+ this.rpcs = rpcs;
+ }
}
@Override
}
private void setDeviations(Set<Deviation> deviations) {
- this.deviations = deviations;
+ if(deviations != null) {
+ this.deviations = deviations;
+ }
}
@Override
}
private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
- this.childNodes = childNodes;
+ if(childNodes != null) {
+ this.childNodes = childNodes;
+ }
}
@Override
}
private void setGroupings(Set<GroupingDefinition> groupings) {
- this.groupings = groupings;
+ if(groupings != null) {
+ this.groupings = groupings;
+ }
}
@Override
}
private void setUses(Set<UsesNode> uses) {
- this.uses = uses;
+ if(uses != null) {
+ this.uses = uses;
+ }
}
@Override
public List<ExtensionDefinition> getExtensionSchemaNodes() {
- return extensionSchemaNodes;
+ return extensionNodes;
}
private void setExtensionSchemaNodes(List<ExtensionDefinition> extensionSchemaNodes) {
if(extensionSchemaNodes != null) {
- this.extensionSchemaNodes = extensionSchemaNodes;
+ this.extensionNodes = extensionSchemaNodes;
+ }
+ }
+
+ @Override
+ public Set<IdentitySchemaNode> getIdentities() {
+ return identities;
+ }
+
+ private void setIdentities(Set<IdentitySchemaNode> identities) {
+ if(identities != null) {
+ this.identities = identities;
}
}
result = prime * result + ((revision == null) ? 0 : revision.hashCode());
result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
- result = prime * result + ((description == null) ? 0 : description.hashCode());
- result = prime * result + ((reference == null) ? 0 : reference.hashCode());
-
- result = prime * result + ((organization == null) ? 0 : organization.hashCode());
- result = prime * result + ((contact == null) ? 0 : contact.hashCode());
- result = prime * result + ((imports == null) ? 0 : imports.hashCode());
- result = prime * result + ((features == null) ? 0 : features.hashCode());
- result = prime * result + ((typeDefinitions == null) ? 0 : typeDefinitions.hashCode());
- result = prime * result + ((notifications == null) ? 0 : notifications.hashCode());
- result = prime * result + ((augmentations == null) ? 0 : augmentations.hashCode());
- result = prime * result + ((rpcs == null) ? 0 : rpcs.hashCode());
- result = prime * result + ((deviations == null) ? 0 : deviations.hashCode());
- result = prime * result + ((childNodes == null) ? 0 : childNodes.hashCode());
- result = prime * result + ((groupings == null) ? 0 : groupings.hashCode());
- result = prime * result + ((uses == null) ? 0 : uses.hashCode());
return result;
}
} else if (!yangVersion.equals(other.yangVersion)) {
return false;
}
- if (description == null) {
- if (other.description != null) {
- return false;
- }
- } else if (!description.equals(other.description)) {
- return false;
- }
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
- return false;
- }
- if (organization == null) {
- if (other.organization != null) {
- return false;
- }
- } else if (!organization.equals(other.organization)) {
- return false;
- }
- if (contact == null) {
- if (other.contact != null) {
- return false;
- }
- } else if (!contact.equals(other.contact)) {
- return false;
- }
- if (imports == null) {
- if (other.imports != null) {
- return false;
- }
- } else if (!imports.equals(other.imports)) {
- return false;
- }
- if (features == null) {
- if (other.features != null) {
- return false;
- }
- } else if (!features.equals(other.features)) {
- return false;
- }
- if (typeDefinitions == null) {
- if (other.typeDefinitions != null) {
- return false;
- }
- } else if (!typeDefinitions.equals(other.typeDefinitions)) {
- return false;
- }
- if (notifications == null) {
- if (other.notifications != null) {
- return false;
- }
- } else if (!notifications.equals(other.notifications)) {
- return false;
- }
- if (augmentations == null) {
- if (other.augmentations != null) {
- return false;
- }
- } else if (!augmentations.equals(other.augmentations)) {
- return false;
- }
- if (rpcs == null) {
- if (other.rpcs != null) {
- return false;
- }
- } else if (!rpcs.equals(other.rpcs)) {
- return false;
- }
- if (deviations == null) {
- if (other.deviations != null) {
- return false;
- }
- } else if (!deviations.equals(other.deviations)) {
- return false;
- }
- if (childNodes == null) {
- if (other.childNodes != null) {
- return false;
- }
- } else if (!childNodes.equals(other.childNodes)) {
- return false;
- }
- if (groupings == null) {
- if (other.groupings != null) {
- return false;
- }
- } else if (!groupings.equals(other.groupings)) {
- return false;
- }
- if (uses == null) {
- if (other.uses != null) {
- return false;
- }
- } else if (!uses.equals(other.uses)) {
- return false;
- }
return true;
}
private Map<QName, DataSchemaNode> buildModuleChildNodes(
Map<List<String>, DataSchemaNodeBuilder> addedChilds) {
final Map<QName, DataSchemaNode> childNodes = new HashMap<QName, DataSchemaNode>();
- for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds
- .entrySet()) {
- if (entry.getKey().size() == 2) {
- DataSchemaNode node = entry.getValue().build();
- QName qname = entry.getValue().getQName();
+ for (Map.Entry<List<String>, DataSchemaNodeBuilder> entry : addedChilds.entrySet()) {
+ List<String> path = entry.getKey();
+ DataSchemaNodeBuilder child = entry.getValue();
+ if (path.size() == 2) {
+ DataSchemaNode node = child.build();
+ QName qname = node.getQName();
childNodes.put(qname, node);
}
}
private Set<TypeDefinition<?>> buildModuleTypedefs(
Map<List<String>, TypeDefinitionBuilder> addedTypedefs) {
Set<TypeDefinition<?>> typedefs = new HashSet<TypeDefinition<?>>();
- for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs
- .entrySet()) {
- if (entry.getKey().size() == 2) {
- TypeDefinition<? extends TypeDefinition<?>> node = entry
- .getValue().build();
+ for (Map.Entry<List<String>, TypeDefinitionBuilder> entry : addedTypedefs.entrySet()) {
+ List<String> key = entry.getKey();
+ TypeDefinitionBuilder typedefBuilder = entry.getValue();
+ if (key.size() == 2) {
+ TypeDefinition<? extends TypeDefinition<?>> node = typedefBuilder.build();
typedefs.add(node);
}
}