- copy.setType(type);
- }
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- copy.setDefaultStr(old.getDefaultStr());
- copy.setUnits(old.getUnits());
- return copy;
- }
-
- public static ContainerSchemaNodeBuilder copyContainerBuilder(
- final ContainerSchemaNodeBuilder old) {
- final ContainerSchemaNodeBuilder copy = new ContainerSchemaNodeBuilder(
- old.getQName(), old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- for (DataSchemaNodeBuilder child : old.getChildNodes()) {
- copy.addChildNode(child);
- }
- for (GroupingBuilder grouping : old.getGroupings()) {
- copy.addGrouping(grouping);
- }
- for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
- copy.addTypedef(typedef);
- }
- for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- copy.addAugmentation(augment);
- }
- for (UsesNodeBuilder use : old.getUsesNodes()) {
- copy.addUsesNode(use);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- copy.setPresence(old.isPresence());
- return copy;
- }
-
- public static ListSchemaNodeBuilder copyListBuilder(
- final ListSchemaNodeBuilder old) {
- final ListSchemaNodeBuilder copy = new ListSchemaNodeBuilder(
- old.getQName(), old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- for (DataSchemaNodeBuilder child : old.getChildNodes()) {
- copy.addChildNode(child);
- }
- for (GroupingBuilder grouping : old.getGroupings()) {
- copy.addGrouping(grouping);
- }
- for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
- copy.addTypedef(typedef);
- }
- for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- copy.addAugmentation(augment);
- }
- for (UsesNodeBuilder use : old.getUsesNodes()) {
- copy.addUsesNode(use);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- copy.setUserOrdered(old.isUserOrdered());
- return copy;
- }
-
- public static LeafListSchemaNodeBuilder copyLeafListBuilder(
- final LeafListSchemaNodeBuilder old) {
- final LeafListSchemaNodeBuilder copy = new LeafListSchemaNodeBuilder(
- old.getQName(), old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- final TypeDefinition<?> type = old.getType();
- if (type == null) {
- copy.setTypedef(old.getTypedef());
- } else {
- copy.setType(type);
- }
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- copy.setUserOrdered(old.isUserOrdered());
- return copy;
- }
-
- public static ChoiceBuilder copyChoiceBuilder(final ChoiceBuilder old) {
- final ChoiceBuilder copy = new ChoiceBuilder(old.getQName(),
- old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (ChoiceCaseBuilder caseBuilder : old.getCases()) {
- copy.addChildNode(caseBuilder);
- }
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDefaultCase(old.getDefaultCase());
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setAugmenting(old.isAugmenting());
- copy.setConfiguration(old.isConfiguration());
- return copy;
- }
-
- public static AnyXmlBuilder copyAnyXmlBuilder(final AnyXmlBuilder old) {
- final AnyXmlBuilder copy = new AnyXmlBuilder(old.getQName(),
- old.getLine());
- copy.setPath(old.getPath());
- copyConstraints(old, copy);
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- copy.setConfiguration(old.isConfiguration());
- return copy;
- }
-
- public static GroupingBuilder copyGroupingBuilder(final GroupingBuilder old) {
- final GroupingBuilder copy = new GroupingBuilderImpl(old.getQName(),
- old.getLine());
- copy.setPath(old.getPath());
- for (DataSchemaNodeBuilder child : old.getChildNodes()) {
- copy.addChildNode(child);
- }
- for (GroupingBuilder grouping : old.getGroupings()) {
- copy.addGrouping(grouping);
- }
- for (TypeDefinitionBuilder typedef : old.getTypeDefinitions()) {
- copy.addTypedef(typedef);
- }
- for (UsesNodeBuilder use : old.getUses()) {
- copy.addUsesNode(use);
- }
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
- }
- copy.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
- return copy;
- }
-
- 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.setDescription(old.getDescription());
- copy.setReference(old.getReference());
- copy.setStatus(old.getStatus());
-
- copy.setRanges(old.getRanges());
- copy.setLengths(old.getLengths());
- copy.setPatterns(old.getPatterns());
- copy.setFractionDigits(old.getFractionDigits());
-
- TypeDefinition<?> type = old.getType();
- if (type == null) {
- copy.setTypedef(old.getTypedef());
- } else {
- copy.setType(old.getType());
- }
- copy.setUnits(old.getUnits());
- for (UnknownSchemaNodeBuilder unknown : old.getUnknownNodes()) {
- copy.addUnknownSchemaNode(unknown);
+ QName qname = type.getQName();
+ if (type instanceof UnknownType) {
+ ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, builder, qname.getPrefix(),
+ nodeToResolve.getLine());
+ if (dependentModuleBuilder == null) {
+ if (context == null) {
+ throw new YangParseException(builder.getName(), nodeToResolve.getLine(),
+ "Failed to resolved type constraints.");
+ }
+ Module dm = findModuleFromContext(context, builder, qname.getPrefix(), nodeToResolve.getLine());
+ TypeDefinition<?> t = findTypeByName(dm.getTypeDefinitions(), qname.getLocalName());
+ if (t instanceof ExtendedType) {
+ ExtendedType extType = (ExtendedType) t;
+ constraints.addFractionDigits(extType.getFractionDigits());
+ constraints.addLengths(extType.getLengths());
+ constraints.addPatterns(extType.getPatterns());
+ constraints.addRanges(extType.getRanges());
+ return constraints;
+ } else {
+ mergeConstraints(t, constraints);
+ return constraints;
+ }
+ } else {
+ TypeDefinitionBuilder tdb = findTypeDefinitionBuilder(nodeToResolve, dependentModuleBuilder,
+ qname.getLocalName(), builder.getName(), nodeToResolve.getLine());
+ return findConstraintsFromTypeBuilder(tdb, constraints, modules, dependentModuleBuilder, context);
+ }
+ } else if (type instanceof ExtendedType) {
+ ExtendedType extType = (ExtendedType) type;
+ constraints.addFractionDigits(extType.getFractionDigits());
+ constraints.addLengths(extType.getLengths());
+ constraints.addPatterns(extType.getPatterns());
+ constraints.addRanges(extType.getRanges());
+
+ TypeDefinition<?> base = extType.getBaseType();
+ if (base instanceof UnknownType) {
+ ModuleBuilder dependentModule = findDependentModuleBuilder(modules, builder, base.getQName()
+ .getPrefix(), nodeToResolve.getLine());
+ TypeDefinitionBuilder tdb = findTypeDefinitionBuilder(nodeToResolve, dependentModule, base
+ .getQName().getLocalName(), builder.getName(), nodeToResolve.getLine());
+ return findConstraintsFromTypeBuilder(tdb, constraints, modules, dependentModule, context);
+ } else {
+ // it has to be base yang type
+ mergeConstraints(type, constraints);
+ return constraints;
+ }
+ } else {
+ // it is base yang type
+ mergeConstraints(type, constraints);
+ return constraints;
+ }