*/
public class UnionTypeBuilder extends AbstractTypeAwareBuilder implements
TypeDefinitionBuilder, Builder {
+ private final static String CLASS_NAME = UnionTypeBuilder.class
+ .getSimpleName();
+
private final int line;
private final List<TypeDefinition<?>> types;
private final List<TypeDefinitionBuilder> typedefs;
private final UnionType instance;
+ private boolean built;
private final List<String> actualPath;
private final URI namespace;
@Override
public UnionType build() {
- for (TypeDefinitionBuilder tdb : typedefs) {
- types.add(tdb.build());
+ if (built) {
+ return instance;
+ } else {
+ for (TypeDefinitionBuilder tdb : typedefs) {
+ types.add(tdb.build());
+ }
+ built = true;
+ return instance;
}
- return instance;
}
@Override
public void setPath(final SchemaPath schemaPath) {
- throw new IllegalStateException("Can not set path to "
- + UnionTypeBuilder.class.getSimpleName());
+ throw new IllegalStateException("Can not set path to " + CLASS_NAME);
}
@Override
public void setDescription(final String description) {
throw new IllegalStateException("Can not set description to "
- + UnionTypeBuilder.class.getSimpleName());
+ + CLASS_NAME);
}
@Override
public void setReference(final String reference) {
throw new IllegalStateException("Can not set reference to "
- + UnionTypeBuilder.class.getSimpleName());
+ + CLASS_NAME);
}
@Override
public void setStatus(final Status status) {
- throw new IllegalStateException("Can not set status to "
- + UnionTypeBuilder.class.getSimpleName());
+ throw new IllegalStateException("Can not set status to " + CLASS_NAME);
}
@Override
public void addUnknownSchemaNode(final UnknownSchemaNodeBuilder unknownNode) {
throw new IllegalStateException("Can not add unknown node to "
- + UnionTypeBuilder.class.getSimpleName());
+ + CLASS_NAME);
}
@Override
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
private Map<String, TreeMap<Date, ModuleBuilder>> resolveModuleBuilders(
final List<InputStream> yangFileStreams) {
- final Map<String, TreeMap<Date, ModuleBuilder>> modules = new HashMap<String, TreeMap<Date, ModuleBuilder>>();
+ final Map<String, TreeMap<Date, ModuleBuilder>> modules = new LinkedHashMap<String, TreeMap<Date, ModuleBuilder>>();
final ParseTreeWalker walker = new ParseTreeWalker();
final List<ParseTree> trees = parseStreams(yangFileStreams);
final ModuleBuilder[] builders = new ModuleBuilder[trees.size()];
// module dependency graph sorted
List<ModuleSimple> sorted = new ModuleDependencySort(builders).sort();
- for (ModuleBuilder builder : builders) {
+ // TODO FIX THIS ASAP!
+ // FIXME this is just temp workaround the ModuleDependencySort MUST
+ // RETURN ordered List
+ // of SORTED and DEPENDECNY RESOLVED MODULE BUILDERS!!!!!!
+ final List<ModuleBuilder> orderedBuilders = new ArrayList<ModuleBuilder>();
+ for (final ModuleSimple ms : sorted) {
+ for (int i = 0; i < builders.length; ++i) {
+ if (ms.getName().equals(builders[i].getName())
+ && ms.getRevision().equals(builders[i].getRevision())) {
+ orderedBuilders.add(builders[i]);
+ }
+ }
+ }
+ // FIXME END OF WORKAROUND
+
+ for (ModuleBuilder builder : orderedBuilders) {
final String builderName = builder.getName();
Date builderRevision = builder.getRevision();
if (builderRevision == null) {
resolveAugments(modules);
// build
- final Set<Module> result = new HashSet<Module>();
+ final Set<Module> result = new LinkedHashSet<Module>();
for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules
.entrySet()) {
final Map<Date, Module> modulesByRevision = new HashMap<Date, Module>();
List<PatternConstraint> patterns = Collections.emptyList();
Integer fractionDigits = null;
if (referencedType == null) {
- final TypeDefinitionBuilder tdb = (TypeDefinitionBuilder) nodeToResolve;
+ final TypeDefinitionBuilder tdb = nodeToResolve.getTypedef();
ranges = tdb.getRanges();
constraints.addRanges(ranges);
lengths = tdb.getLengths();
for (AugmentationSchemaBuilder augmentBuilder : module
.getAddedAugments()) {
- if(!augmentBuilder.isResolved()) {
+ if (!augmentBuilder.isResolved()) {
final SchemaPath augmentTargetSchemaPath = augmentBuilder
.getTargetPath();
final List<QName> path = augmentTargetSchemaPath.getPath();
for (DataSchemaNodeBuilder child : dependentModule
.getChildNodes()) {
final QName childQName = child.getQName();
- if (childQName.getLocalName().equals(qname.getLocalName())) {
+ if (childQName.getLocalName().equals(
+ qname.getLocalName())) {
currentParent = child;
i++;
break;
}
final QName currentQName = currentParent.getQName();
- final QName lastAugmentPathElement = path.get(path.size() - 1);
+ final QName lastAugmentPathElement = path
+ .get(path.size() - 1);
if (currentQName.getLocalName().equals(
lastAugmentPathElement.getLocalName())) {
ParserUtils.fillAugmentTarget(augmentBuilder,
((AugmentationTargetBuilder) currentParent)
.addAugmentation(augmentBuilder);
SchemaPath oldPath = currentParent.getPath();
- augmentBuilder.setTargetPath(new SchemaPath(oldPath.getPath(), oldPath.isAbsolute()));
+ augmentBuilder.setTargetPath(new SchemaPath(oldPath
+ .getPath(), oldPath.isAbsolute()));
augmentBuilder.setResolved(true);
module.augmentResolved();
}
}
-
}
}
}
@Override
public Module findModuleByName(final String name, final Date revision) {
- if ((name != null) && (revision != null)) {
+ if (name != null) {
for (final Module module : modules) {
- if (module.getName().equals(name)
+ if (revision == null) {
+ if (module.getName().equals(name)) {
+ return module;
+ }
+ } else if (module.getName().equals(name)
&& module.getRevision().equals(revision)) {
return module;
}