import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
-import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private Type javaTypeForLeafrefOrIdentityRef(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode) {
if (typeDefinition instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
- if (isLeafRefSelfReference(leafref, parentNode)) {
- throw new YangValidationException("Leafref " + leafref.toString() + " is referencing itself, incoming" +
- " StackOverFlowError detected.");
- }
+ Preconditions.checkArgument(!isLeafRefSelfReference(leafref, parentNode),
+ "Leafref %s is referencing itself, incoming StackOverFlowError detected.", leafref);
return provideTypeForLeafref(leafref, parentNode);
} else if (typeDefinition instanceof IdentityrefTypeDefinition) {
- final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) typeDefinition;
- return provideTypeForIdentityref(idref);
- } else {
- return null;
+ return provideTypeForIdentityref((IdentityrefTypeDefinition) typeDefinition);
}
+
+ return null;
}
/**
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.IdentityrefTypeBuilder;
-import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class TypeProviderImplTest {
- @Test (expected = YangValidationException.class)
+ @Test (expected = IllegalArgumentException.class)
public void testLeafRefRelativeSelfReference() throws Exception {
File relative = new File(getClass().getResource("/leafref/leafref-relative-invalid.yang").toURI());
final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(relative);
- final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrr")).iterator().next();
+ final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrr")).iterator()
+ .next();
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
final QName listNode = QName.create(moduleRelative.getQNameModule(), "neighbor");
assertNotNull(leafrefResolvedType);
}
- @Test (expected = YangValidationException.class)
+ @Test (expected = IllegalArgumentException.class)
public void testLeafRefAbsoluteSelfReference() throws Exception {
File relative = new File(getClass().getResource("/leafref/leafref-absolute-invalid.yang").toURI());
final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(relative);
- final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lra")).iterator().next();
+ final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lra")).iterator()
+ .next();
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
final QName listNode = QName.create(moduleRelative.getQNameModule(), "neighbor");
File valid = new File(getClass().getResource("/leafref/leafref-valid.yang").toURI());
final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(valid);
- final Module moduleValid = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrv")).iterator().next();
+ final Module moduleValid = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrv")).iterator()
+ .next();
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor");
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
final SchemaPath refTypePath = SchemaPath.create(true, QName.create("cont1"), QName.create("list1"));
- final GeneratedTypeBuilderImpl refType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "TestType");
+ final GeneratedTypeBuilderImpl refType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test",
+ "TestType");
typeProvider.putReferencedType(refTypePath, refType);
final StringTypeDefinition stringType = BaseTypes.stringType();
assertEquals("java.lang.Boolean.FALSE", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "false"));
// decimal type
- final DecimalTypeDefinition decimalType = BaseTypes.decimalTypeBuilder(refTypePath).setFractionDigits(4).build();
+ final DecimalTypeDefinition decimalType = BaseTypes.decimalTypeBuilder(refTypePath).setFractionDigits(4)
+ .build();
reset(leafSchemaNode);
doReturn(decimalType).when(leafSchemaNode).getType();
doReturn(SchemaPath.ROOT).when(leafSchemaNode).getPath();
doReturn(QName.create("Cont1")).when(leafSchemaNode).getQName();
- assertEquals("new java.math.BigDecimal(\"111\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "111"));
+ assertEquals("new java.math.BigDecimal(\"111\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode,
+ "111"));
// empty type
final EmptyTypeDefinition emptyType = BaseTypes.emptyType();
doReturn(SchemaPath.ROOT).when(leafSchemaNode).getPath();
doReturn(QName.create("Cont1")).when(leafSchemaNode).getQName();
- assertEquals("java.lang.Boolean.valueOf(\"default value\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value"));
+ assertEquals("java.lang.Boolean.valueOf(\"default value\")", typeProvider.getTypeDefaultConstruction(
+ leafSchemaNode, "default value"));
// enum type
final EnumTypeDefinition enumType = BaseTypes.enumerationTypeBuilder(refTypePath).build();
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.opendaylight.yangtools.util.TopologicalSort;
+import org.opendaylight.yangtools.util.TopologicalSort.Node;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
-import org.opendaylight.yangtools.yang.parser.util.NodeWrappedType;
-import org.opendaylight.yangtools.yang.parser.util.TopologicalSort;
-import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
public class GroupingDefinitionDependencySort {
/**
- * Sorts set <code>groupingDefinitions</code> according to the mutual
- * dependencies.<br>
+ * Sorts set <code>groupingDefinitions</code> according to the mutual dependencies.<br>
*
- * Elements of <code>groupingDefinitions</code> are firstly transformed to
- * {@link org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node
- * Node} interfaces and then are sorted by
- * {@link org.opendaylight.yangtools.yang.parser.util.TopologicalSort#sort(Set)
- * sort()} method of <code>TopologicalSort</code>.<br>
+ * Elements of <code>groupingDefinitions</code> are firstly transformed to {@link Node} interfaces and then are
+ * sorted by {@link TopologicalSort#sort(Set)} method.
* <br>
*
- *
* <i>Definition of dependency relation:<br>
* The first <code>GroupingDefinition</code> object (in this context)
* depends on second <code>GroupingDefinition</code> object if the first one
throw new IllegalArgumentException("Set of Type Definitions " + "cannot be NULL!");
}
- final List<GroupingDefinition> resultGroupingDefinitions = new ArrayList<GroupingDefinition>();
+ final List<GroupingDefinition> resultGroupingDefinitions = new ArrayList<>();
final Set<Node> unsorted = groupingDefinitionsToNodes(groupingDefinitions);
final List<Node> sortedNodes = TopologicalSort.sort(unsorted);
for (Node node : sortedNodes) {
NodeWrappedType nodeWrappedType = (NodeWrappedType) node;
- resultGroupingDefinitions.add((GroupingDefinition) (nodeWrappedType.getWrappedType()));
+ resultGroupingDefinitions.add((GroupingDefinition) nodeWrappedType.getWrappedType());
}
return resultGroupingDefinitions;
--- /dev/null
+/*
+ * Copyright (c) 2014 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.mdsal.binding.javav2.generator.yang.types;
+
+import org.opendaylight.yangtools.util.TopologicalSort.NodeImpl;
+
+public final class NodeWrappedType extends NodeImpl {
+ /**
+ * The payload which is saved inside Node
+ */
+ private final Object wrappedType;
+
+ /**
+ * Create new instance of class <code>NodeWrappedType</code>.
+ *
+ * @param wrappedType
+ * object with payload data
+ */
+ NodeWrappedType(Object wrappedType) {
+ this.wrappedType = wrappedType;
+ }
+
+ /**
+ * Gets payload from class
+ *
+ * @return object with <code>wrappedType</code>
+ */
+ Object getWrappedType() {
+ return wrappedType;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof NodeWrappedType)) {
+ return false;
+ }
+ NodeWrappedType nodeWrappedType = (NodeWrappedType) o;
+ if (!wrappedType.equals(nodeWrappedType.wrappedType)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return wrappedType.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "NodeWrappedType{" + "wrappedType=" + wrappedType + '}';
+ }
+
+}
import org.opendaylight.yangtools.yang.model.util.ModuleDependencySort;
import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
-import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
ModuleContext context) {
if (typeDefinition instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
- if (isLeafRefSelfReference(leafref, parentNode, schemaContext)) {
- throw new YangValidationException("Leafref " + leafref.toString() + " is referencing itself, incoming" +
- " StackOverFlowError detected.");
- }
+ Preconditions.checkArgument(!isLeafRefSelfReference(leafref, parentNode, schemaContext),
+ "Leafref %s is referencing itself, incoming StackOverFlowError detected.", leafref);
return provideTypeForLeafref(leafref, parentNode, schemaContext, genTypeDefsContextMap, context);
} else if (typeDefinition instanceof IdentityrefTypeDefinition) {
final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) typeDefinition;