import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.opendaylight.yangtools.sal.binding.generator.impl.YangTemplate;
import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
import org.opendaylight.yangtools.binding.generator.util.BindingTypes;
import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
- <version>5.7</version>
+ <version>6.1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.xml.sax.InputSource;
-
import com.google.common.collect.Lists;
import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
import com.puppycrawl.tools.checkstyle.api.AuditListener;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.Configuration;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.InputSource;
public class CheckstyleTest {
@Before
public void setup() throws CheckstyleException {
baos = new ByteArrayOutputStream();
- AuditListener listener = new DefaultLogger(baos, false);
+ final AuditListener listener = new DefaultLogger(baos, false);
- InputSource inputSource = new InputSource(CheckstyleTest.class.getClassLoader().getResourceAsStream(
+ final InputSource inputSource = new InputSource(CheckstyleTest.class.getClassLoader().getResourceAsStream(
"checkstyle-logging.xml"));
- Configuration configuration = ConfigurationLoader.loadConfiguration(inputSource,
+ final Configuration configuration = ConfigurationLoader.loadConfiguration(inputSource,
new PropertiesExpander(System.getProperties()), false);
checker = new Checker();
@Test
public void testCodingChecks() {
verify(CheckCodingStyleTestClass.class, false, "9: Line has Windows line delimiter.", "14: Wrong order for", "24:1: Line contains a tab character.",
- "22: Line has trailing spaces.", "22: ctor def child at indentation level 16 not at correct indentation, 8", "17:8: Unused import",
+ "22: Line has trailing spaces.", "22: 'ctor def' child have incorrect indentation level 16, expected level should be 8.", "17:8: Unused import",
"23: Line has trailing spaces.");
}
return delegate.getInput();
case "output":
return delegate.getOutput();
+ default:
+ return null;
}
- return null;
}
@Override
@Override
public Collection<DataSchemaNode> getChildNodes() {
- final ArrayList<DataSchemaNode> ret = new ArrayList<>();
+ final List<DataSchemaNode> ret = new ArrayList<>();
final ContainerSchemaNode input = getInput();
final ContainerSchemaNode output = getOutput();
if(input != null) {
*/
package org.opendaylight.yangtools.yang.data.impl.schema;
-import com.google.common.base.Preconditions;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
/**
}
void setResult(final NormalizedNode<?, ?> result) {
- Preconditions.checkState(!this.finished, "Result was already set.");
+ if (finished) {
+ throw new ResultAlreadySetException("Normalized Node result was already set.", this.result);
+ }
this.finished = true;
this.result = result;
}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.yangtools.yang.data.impl.schema;
+
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+public class ResultAlreadySetException extends IllegalStateException {
+ private final NormalizedNode<?, ?> resultData;
+
+ public ResultAlreadySetException(String message, NormalizedNode<?, ?> resultData) {
+ this(message, resultData, null);
+ }
+
+ public ResultAlreadySetException(String message, NormalizedNode<?, ?> resultData, Throwable cause) {
+ super(message, cause);
+ this.resultData = resultData;
+ }
+
+ public NormalizedNode<?, ?> getResultData() {
+ return resultData;
+ }
+}
import com.google.common.base.MoreObjects.ToStringHelper;
+// FIXME: are attributes part of hashCode/equals?
public abstract class AbstractImmutableDataContainerAttrNode<K extends YangInstanceIdentifier.PathArgument>
extends AbstractImmutableDataContainerNode<K>
implements AttributesContainer {
return super.addToStringAttributes(toStringHelper).add("attributes", attributes);
}
-// FIXME: are attributes part of hashCode/equals?
-// @Override
-// protected int valueHashCode() {
-// int result = super.valueHashCode();
-// for (final Entry<?, ?> a : attributes.entrySet()) {
-// result = 31 * result + a.hashCode();
-// }
-// return result;
-// }
-
- // FIXME: are attributes part of hashCode/equals?
-// @Override
-// protected boolean valueEquals(final NormalizedNode<?, ?> other) {
-// if (!super.valueEquals(other)) {
-// return false;
-// }
-// final Set<Entry<QName, String>> tas = getAttributes().entrySet();
-// final Set<Entry<QName, String>> oas = container.getAttributes().entrySet();
-//
-// return tas.containsAll(oas) && oas.containsAll(tas);
-// return true;
-// }
}
@Override
protected int valueHashCode() {
final int result = getValue() != null ? getValue().hashCode() : 1;
-// FIXME: are attributes part of hashCode/equals?
-// for (final Entry<?, ?> a : attributes.entrySet()) {
-// result = 31 * result + a.hashCode();
-// }
+ // FIXME: are attributes part of hashCode/equals?
return result;
}
}
// FIXME: are attributes part of hashCode/equals?
- // final Set<Entry<QName, String>> tas = getAttributes().entrySet();
- // final Set<Entry<QName, String>> oas =
- // container.getAttributes().entrySet();
- //
- // return tas.containsAll(oas) && oas.containsAll(tas);
return true;
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform;
+import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
/**
* @param schema
* @return NormalizedNode as a result of parsing list of E elements with schema S
*/
+ @Nullable
N parse(Iterable<E> xmlDom, S schema);
}
* @param <E> type of elements to be parsed
*/
public abstract class AugmentationNodeBaseParser<E> extends
- BaseDispatcherParser<E,AugmentationNode, AugmentationSchema> {
+ BaseDispatcherParser<E, YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode, AugmentationSchema> {
+
+ public AugmentationNodeBaseParser(final BuildingStrategy<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> buildingStrategy) {
+ super(buildingStrategy);
+ }
+
+ public AugmentationNodeBaseParser() {}
@Override
protected final DataContainerNodeBuilder<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> getBuilder(final AugmentationSchema schema) {
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.AttributesBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
/**
* Abstract(base) Parser for DataContainerNodes e.g. ContainerNode, AugmentationNode.
*/
-public abstract class BaseDispatcherParser<E, N extends DataContainerNode<?>, S>
- implements ToNormalizedNodeParser<E, N, S> {
+public abstract class BaseDispatcherParser<E, P extends YangInstanceIdentifier.PathArgument, N extends DataContainerNode<P>, S>
+ implements ExtensibleParser<P, E, N, S> {
+
+ private final BuildingStrategy<P, N> buildingStrategy;
+
+ public BaseDispatcherParser(final BuildingStrategy<P, N> buildingStrategy) {
+ this.buildingStrategy = buildingStrategy;
+ }
+
+ public BaseDispatcherParser() {
+ this.buildingStrategy = new SimpleBuildingStrategy<>();
+ }
/**
*
* @param schema
* @return New(empty) instance of a builder to build node identified by schema.
*/
- protected abstract DataContainerNodeBuilder<?, N> getBuilder(S schema);
+ protected abstract DataContainerNodeBuilder<P, N> getBuilder(S schema);
/**
*
*/
protected abstract NodeParserDispatcher<E> getDispatcher();
+ /**
+ * can return null only if you override ParsingStrategy and explicitely return null
+ * @param elements
+ * @param schema
+ * @return
+ */
+ @Nullable
@Override
public N parse(final Iterable<E> elements, final S schema) {
checkAtLeastOneNode(schema, elements);
- DataContainerNodeBuilder<?, N> containerBuilder = getBuilder(schema);
+ DataContainerNodeBuilder<P, N> containerBuilder = getBuilder(schema);
// Map child nodes to QName
LinkedListMultimap<QName, E> mappedChildElements = mapChildElements(elements);
Map<QName, ChoiceSchemaNode> mappedChoiceChildNodes = mapChildElementsFromChoices(schema);
LinkedListMultimap<ChoiceSchemaNode, E> choicesToElements = LinkedListMultimap.create();
+ Map<QName, String> attributes = getAttributes(elements.iterator().next());
+ if (containerBuilder instanceof AttributesBuilder) {
+ final int size = Iterables.size(elements);
+ Preconditions.checkArgument(size == 1, "Unexpected number of elements: %s, should be 1 for: %s",
+ size, schema);
+ ((AttributesBuilder<?>) containerBuilder).withAttributes(attributes);
+ }
+
+ //parse keys first
+ if (schema instanceof ListSchemaNode) {
+ for (QName qname : ((ListSchemaNode) schema).getKeyDefinition()) {
+ if(mappedChildElements.get(qname.withoutRevision()).isEmpty()) {
+ continue;
+ }
+
+ DataSchemaNode childSchema = getSchemaForChild(schema, qname);
+ List<E> childrenForQName = mappedChildElements.removeAll(qname.withoutRevision());
+
+
+ DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChildNode = getDispatcher()
+ .dispatchChildElement(childSchema, childrenForQName);
+ if (optionalChildNode != null) {
+ containerBuilder.withChild(optionalChildNode);
+ }
+ }
+ }
+
+ //stage attribues for strategy before going deeper in the recursion
+ buildingStrategy.prepareAttributes(attributes, containerBuilder);
+
// process Child nodes
for (QName childPartialQName : mappedChildElements.keySet()) {
DataSchemaNode childSchema = getSchemaForChild(schema, childPartialQName);
choicesToElements.putAll(choiceSchema, childrenForQName);
// Regular child nodes
} else {
- DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> builtChildNode = getDispatcher()
+ DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChildNode = getDispatcher()
.dispatchChildElement(childSchema, childrenForQName);
- containerBuilder.withChild(builtChildNode);
+ if (optionalChildNode != null) {
+ containerBuilder.withChild(optionalChildNode);
+ }
}
}
// TODO ordering is not preserved for choice and augment elements
for (ChoiceSchemaNode choiceSchema : choicesToElements.keySet()) {
- containerBuilder.withChild(getDispatcher().dispatchChildElement(choiceSchema,
- choicesToElements.get(choiceSchema)));
+ DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChild = getDispatcher()
+ .dispatchChildElement(choiceSchema, choicesToElements.get(choiceSchema));
+ if (optionalChild != null) {
+ containerBuilder.withChild(optionalChild);
+ }
}
for (AugmentationSchema augmentSchema : augmentsToElements.keySet()) {
Set<DataSchemaNode> realChildSchemas = getRealSchemasForAugment(schema, augmentSchema);
EffectiveAugmentationSchema augSchemaProxy = new EffectiveAugmentationSchema(augmentSchema, realChildSchemas);
- containerBuilder.withChild(getDispatcher().dispatchChildElement(augSchemaProxy, augmentsToElements.get(augmentSchema)));
+ DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> optionalChild = getDispatcher()
+ .dispatchChildElement(augSchemaProxy, augmentsToElements.get(augmentSchema));
+ if (optionalChild != null) {
+ containerBuilder.withChild(optionalChild);
+ }
}
- if (containerBuilder instanceof AttributesBuilder) {
- final int size = Iterables.size(elements);
- Preconditions.checkArgument(size == 1, "Unexpected number of elements: %s, should be 1 for: %s",
- size, schema);
- ((AttributesBuilder<?>) containerBuilder).withAttributes(getAttributes(elements.iterator().next()));
- }
+ return buildingStrategy.build(containerBuilder);
+ }
- return containerBuilder.build();
+ @Override
+ public BuildingStrategy<P, N> getBuildingStrategy() {
+ return buildingStrategy;
}
protected Map<QName, String> getAttributes(final E e) {
Preconditions.checkArgument(!Iterables.isEmpty(childNodes),
"Node detected 0 times, should be at least 1, identified by: %s, found: %s", schema, childNodes);
}
+
+ public static class SimpleBuildingStrategy<P extends YangInstanceIdentifier.PathArgument, N extends DataContainerNode<P>> implements BuildingStrategy<P, N> {
+ @Override
+ public N build(final NormalizedNodeBuilder<P, ?, N> builder) {
+ return builder.build();
+ }
+
+ @Override
+ public void prepareAttributes(final Map<QName, String> attributes, final NormalizedNodeBuilder<P, ?, N> containerBuilder) {
+ // NOOP
+ }
+ }
}
*
* @param <E> type of elements to be parsed
*/
-public abstract class ChoiceNodeBaseParser<E> extends BaseDispatcherParser<E, ChoiceNode, ChoiceSchemaNode> {
+public abstract class ChoiceNodeBaseParser<E> extends BaseDispatcherParser<E, YangInstanceIdentifier.NodeIdentifier, ChoiceNode, ChoiceSchemaNode> {
+
+ protected ChoiceNodeBaseParser() {}
+
+ protected ChoiceNodeBaseParser(final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, ChoiceNode> buildingStrategy) {
+ super(buildingStrategy);
+ }
@Override
protected final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ChoiceNode> getBuilder(
* @param <E> type of elements to be parsed
*/
public abstract class ContainerNodeBaseParser<E> extends
- BaseDispatcherParser<E, ContainerNode, ContainerSchemaNode> {
+ BaseDispatcherParser<E, YangInstanceIdentifier.NodeIdentifier, ContainerNode, ContainerSchemaNode> {
+
+ public ContainerNodeBaseParser() {}
+
+ public ContainerNodeBaseParser(final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, ContainerNode> buildingStrategy) {
+ super(buildingStrategy);
+ }
@Override
protected final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> getBuilder(
@Override
protected abstract Map<QName, String> getAttributes(E e);
+
}
--- /dev/null
+/*
+ * Copyright (c) 2015 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.yangtools.yang.data.impl.schema.transform.base.parser;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
+
+/**
+ * Extensible parser allows its subclasses to customize the building process of normalized nodes
+ *
+ * @param <P>
+ * @param <E>
+ * @param <N>
+ * @param <S>
+ */
+public interface ExtensibleParser<P extends YangInstanceIdentifier.PathArgument, E, N extends NormalizedNode<P, ?>, S>
+ extends ToNormalizedNodeParser<E, N, S> {
+
+ /**
+ * Provide building strategy
+ */
+ BuildingStrategy<P, N> getBuildingStrategy();
+
+ /**
+ * Building strategy serves as a set of hooks into the parsing process.
+ *
+ * @param <P>
+ * @param <N>
+ */
+ interface BuildingStrategy<P extends YangInstanceIdentifier.PathArgument, N extends NormalizedNode<P, ?>> {
+
+ /**
+ * Build normalized node from its builder
+ *
+ * @param builder filled builder for node
+ * @return built normalized node or null if the node should not be built
+ */
+ @Nullable N build(NormalizedNodeBuilder<P, ?, N> builder);
+
+ /**
+ * Hook for subclasses to handle attributes associated with current node. This is called before the build method
+ * and allows subclasses to react to node's attributes e.g. modification operation
+ *
+ * @param attributes attributes for node
+ * @param containerBuilder builder created for node. Can be modified according to attributes e.g. remove attribute
+ */
+ void prepareAttributes(Map<QName, String> attributes, NormalizedNodeBuilder<P, ?, N> containerBuilder);
+ }
+}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-
/**
* Abstract(base) parser for LeafNodes, parses elements of type E.
*
* @param <E> type of elements to be parsed
*/
-public abstract class LeafNodeBaseParser<E> implements
- ToNormalizedNodeParser<E, LeafNode<?>, LeafSchemaNode> {
+public abstract class LeafNodeBaseParser<E> implements ExtensibleParser<NodeIdentifier, E, LeafNode<?>, LeafSchemaNode> {
+
+ private final BuildingStrategy<NodeIdentifier, LeafNode<?>> buildingStrategy;
+
+ public LeafNodeBaseParser() {
+ buildingStrategy = new SimpleLeafBuildingStrategy();
+ }
+ public LeafNodeBaseParser(final BuildingStrategy<NodeIdentifier, LeafNode<?>> buildingStrategy) {
+ this.buildingStrategy = buildingStrategy;
+ }
+
+ @SuppressWarnings("unchecked")
@Override
public final LeafNode<?> parse(Iterable<E> elements, LeafSchemaNode schema) {
final int size = Iterables.size(elements);
final E e = elements.iterator().next();
Object value = parseLeaf(e, schema);
- NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier,Object,LeafNode<Object>> leafBuilder = Builders.leafBuilder(schema);
+ NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> leafBuilder =
+ Builders.leafBuilder(schema);
leafBuilder.withAttributes(getAttributes(e));
- return leafBuilder.withValue(value).build();
+ final BuildingStrategy rawBuildingStrat = buildingStrategy;
+ return (LeafNode<?>) rawBuildingStrat.build(leafBuilder.withValue(value));
}
/**
* @return attributes mapped to QNames
*/
protected abstract Map<QName, String> getAttributes(E e);
+
+ @Override
+ public BuildingStrategy<NodeIdentifier, LeafNode<?>> getBuildingStrategy() {
+ return buildingStrategy;
+ }
+
+ public static class SimpleLeafBuildingStrategy implements BuildingStrategy<NodeIdentifier, LeafNode<?>> {
+ @Override
+ public LeafNode<?> build(final NormalizedNodeBuilder<NodeIdentifier, ?, LeafNode<?>> builder) {
+ return builder.build();
+ }
+
+ @Override
+ public void prepareAttributes(final Map<QName, String> attributes, final NormalizedNodeBuilder<NodeIdentifier, ?, LeafNode<?>> containerBuilder) {
+ // NOOP
+ }
+ }
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-
/**
* Abstract(base) parser for LeafSetEntryNodes, parses elements of type E.
*
* @param <E> type of elements to be parsed
*/
-public abstract class LeafSetEntryNodeBaseParser<E> implements
- ToNormalizedNodeParser<E, LeafSetEntryNode<?>, LeafListSchemaNode> {
+public abstract class LeafSetEntryNodeBaseParser<E> implements ExtensibleParser<YangInstanceIdentifier.NodeWithValue, E, LeafSetEntryNode<?>, LeafListSchemaNode> {
+
+ private final BuildingStrategy<YangInstanceIdentifier.NodeWithValue, LeafSetEntryNode<?>> buildingStrategy;
+
+ public LeafSetEntryNodeBaseParser() {
+ buildingStrategy = new SimpleLeafSetEntryBuildingStrategy();
+ }
+ public LeafSetEntryNodeBaseParser(final BuildingStrategy<YangInstanceIdentifier.NodeWithValue, LeafSetEntryNode<?>> buildingStrategy) {
+ this.buildingStrategy = buildingStrategy;
+ }
+
+ @SuppressWarnings("unchecked")
@Override
- public final LeafSetEntryNode<Object> parse(Iterable<E> elements, LeafListSchemaNode schema) {
+ public final LeafSetEntryNode<?> parse(Iterable<E> elements, LeafListSchemaNode schema) {
final int size = Iterables.size(elements);
Preconditions.checkArgument(size == 1, "Xml elements mapped to leaf node illegal count: %s", size);
NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeWithValue, Object, LeafSetEntryNode<Object>> leafEntryBuilder = Builders
.leafSetEntryBuilder(schema);
leafEntryBuilder.withAttributes(getAttributes(e));
+ leafEntryBuilder.withValue(value);
+
+ final BuildingStrategy rawBuildingStrat = buildingStrategy;
+ return (LeafSetEntryNode<?>) rawBuildingStrat.build(leafEntryBuilder);
+ }
- return leafEntryBuilder.withValue(value).build();
+ @Override
+ public BuildingStrategy<NodeWithValue, LeafSetEntryNode<?>> getBuildingStrategy() {
+ return buildingStrategy;
}
/**
*/
protected abstract Map<QName, String> getAttributes(E e);
+ public static class SimpleLeafSetEntryBuildingStrategy implements BuildingStrategy<YangInstanceIdentifier.NodeWithValue, LeafSetEntryNode<?>> {
+
+ @Override
+ public LeafSetEntryNode<?> build(final NormalizedNodeBuilder<NodeWithValue, ?, LeafSetEntryNode<?>> builder) {
+ return builder.build();
+ }
+
+ @Override
+ public void prepareAttributes(final Map<QName, String> attributes, final NormalizedNodeBuilder<NodeWithValue, ?, LeafSetEntryNode<?>> containerBuilder) {
+ }
+ }
}
package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser;
import java.util.Collections;
-
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import java.util.Map;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
* @param <E>
* type of elements to be parsed
*/
-public abstract class ListEntryNodeBaseParser<E, N extends DataContainerNode<?>> extends
- BaseDispatcherParser<E, N, ListSchemaNode> {
+public abstract class ListEntryNodeBaseParser<P extends YangInstanceIdentifier.PathArgument, E, N extends DataContainerNode<P>> extends
+ BaseDispatcherParser<E, P, N, ListSchemaNode> {
+
+ public ListEntryNodeBaseParser(final BuildingStrategy<P, N> buildingStrategy) {
+ super(buildingStrategy);
+ }
+
+ public ListEntryNodeBaseParser() {
+ }
@Override
protected final Set<DataSchemaNode> getRealSchemasForAugment(final ListSchemaNode schema, final AugmentationSchema augmentSchema) {
package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser;
import java.util.Collections;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
* type of elements to be parsed
*/
public abstract class ListNodeBaseParser<E, N extends NormalizedNode<?, ?>, O extends NormalizedNode<YangInstanceIdentifier.NodeIdentifier, ?>, S extends ListSchemaNode>
- implements ToNormalizedNodeParser<E, O, S> {
+ implements ExtensibleParser<YangInstanceIdentifier.NodeIdentifier, E, O, S> {
+
+ private final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, O> buildingStrategy;
+
+ public ListNodeBaseParser() {
+ buildingStrategy = new SimpleListNodeBuildingStrategy<>();
+ }
+
+ public ListNodeBaseParser(final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, O> buildingStrategy) {
+ this.buildingStrategy = buildingStrategy;
+ }
@Override
- public final O parse(Iterable<E> childNodes, S schema) {
+ public O parse(Iterable<E> childNodes, S schema) {
CollectionNodeBuilder<N, O> listBuilder = provideBuilder(schema);
+
+ buildingStrategy.prepareAttributes(Collections.<QName, String>emptyMap(), listBuilder);
+
for (E childNode : childNodes) {
N listChild = getListEntryNodeParser().parse(Collections.singletonList(childNode), schema);
- listBuilder.withChild(listChild);
+ if (listChild != null) {
+ listBuilder.withChild(listChild);
+ }
}
- return listBuilder.build();
+ return buildingStrategy.build(listBuilder);
}
/**
* @return prepares builder which will contain entries of list according to concrete list type
*/
protected abstract CollectionNodeBuilder<N, O> provideBuilder(S schema);
+
+ @Override
+ public BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, O> getBuildingStrategy() {
+ return buildingStrategy;
+ }
+
+ public static class SimpleListNodeBuildingStrategy<O extends NormalizedNode<YangInstanceIdentifier.NodeIdentifier, ?>> implements BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, O> {
+ @Override
+ public O build(final NormalizedNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ?, O> builder) {
+ return builder.build();
+ }
+
+ @Override
+ public void prepareAttributes(final Map<QName, String> attributes, final NormalizedNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ?, O> containerBuilder) {
+ // NOOP
+ }
+ }
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
*/
public abstract class MapNodeBaseParser<E> extends ListNodeBaseParser<E, MapEntryNode, MapNode, ListSchemaNode> {
+ public MapNodeBaseParser() {
+ }
+
+ public MapNodeBaseParser(final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, MapNode> buildingStrategy) {
+ super(buildingStrategy);
+ }
+
protected CollectionNodeBuilder<MapEntryNode, MapNode> provideBuilder(ListSchemaNode schema) {
return Builders.mapBuilder(schema);
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
*/
public abstract class OrderedListNodeBaseParser<E> extends
ListNodeBaseParser<E, MapEntryNode, OrderedMapNode, ListSchemaNode> {
+
+ public OrderedListNodeBaseParser() {
+ }
+
+ public OrderedListNodeBaseParser(final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, OrderedMapNode> buildingStrategy) {
+ super(buildingStrategy);
+ }
+
@Override
protected CollectionNodeBuilder<MapEntryNode, OrderedMapNode> provideBuilder(ListSchemaNode schema) {
return Builders.orderedMapBuilder(schema);
}
+
}
*/
public abstract class UnkeyedListNodeBaseParser<E> extends
ListNodeBaseParser<E, UnkeyedListEntryNode, UnkeyedListNode, ListSchemaNode> {
+
+ public UnkeyedListNodeBaseParser(final BuildingStrategy<NodeIdentifier, UnkeyedListNode> buildingStrategy) {
+ super(buildingStrategy);
+ }
+
+ public UnkeyedListNodeBaseParser() {
+ }
+
@Override
protected CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> provideBuilder(ListSchemaNode schema) {
CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> listBuilder = Builders.unkeyedListBuilder();
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.LinkedListMultimap;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.AugmentationNodeBaseParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.NodeParserDispatcher;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils;
import org.w3c.dom.Element;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.LinkedListMultimap;
-
final class AugmentationNodeDomParser extends AugmentationNodeBaseParser<Element> {
private final NodeParserDispatcher<Element> dispatcher;
this.strictParsing = strictParsing;
}
+ public AugmentationNodeDomParser(final BuildingStrategy<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> buildingStrategy,
+ final NodeParserDispatcher<Element> dispatcher, final boolean strictParsing) {
+ super(buildingStrategy);
+ this.dispatcher = Preconditions.checkNotNull(dispatcher);
+ this.strictParsing = strictParsing;
+ }
+
@Override
protected LinkedListMultimap<QName, Element> mapChildElements(Iterable<Element> elements) {
return DomUtils.mapChildElements(elements);
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.LinkedListMultimap;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.ChoiceNodeBaseParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.NodeParserDispatcher;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils;
import org.w3c.dom.Element;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.LinkedListMultimap;
-
final class ChoiceNodeDomParser extends ChoiceNodeBaseParser<Element> {
private final NodeParserDispatcher<Element> dispatcher;
- ChoiceNodeDomParser(NodeParserDispatcher<Element> dispatcher) {
+ ChoiceNodeDomParser(final NodeParserDispatcher<Element> dispatcher) {
+ this.dispatcher = Preconditions.checkNotNull(dispatcher);
+ }
+
+ ChoiceNodeDomParser(final NodeParserDispatcher<Element> dispatcher, final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, ChoiceNode> buildingStrategy) {
+ super(buildingStrategy);
this.dispatcher = Preconditions.checkNotNull(dispatcher);
}
@Override
- protected LinkedListMultimap<QName, Element> mapChildElements(Iterable<Element> xml) {
+ protected LinkedListMultimap<QName, Element> mapChildElements(final Iterable<Element> xml) {
return DomUtils.mapChildElements(xml);
}
protected NodeParserDispatcher<Element> getDispatcher() {
return dispatcher;
}
+
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.LinkedListMultimap;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.ContainerNodeBaseParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.NodeParserDispatcher;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils;
import org.w3c.dom.Element;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.LinkedListMultimap;
-
final class ContainerNodeDomParser extends ContainerNodeBaseParser<Element> {
private final NodeParserDispatcher<Element> dispatcher;
ContainerNodeDomParser(final NodeParserDispatcher<Element> dispatcher) {
this.dispatcher = Preconditions.checkNotNull(dispatcher);
- this.strictParsing = super.strictParsing();
+ strictParsing = super.strictParsing();
+ }
+
+ public ContainerNodeDomParser(final NodeParserDispatcher<Element> dispatcher, final boolean strictParsing) {
+ this.dispatcher = dispatcher;
+ this.strictParsing = strictParsing;
}
- ContainerNodeDomParser(final NodeParserDispatcher<Element> dispatcher, final boolean strictParsing) {
+ ContainerNodeDomParser(final NodeParserDispatcher<Element> dispatcher, final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, ContainerNode> parsingStrategy, final boolean strictParsing) {
+ super(parsingStrategy);
this.dispatcher = Preconditions.checkNotNull(dispatcher);
this.strictParsing = strictParsing;
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlCodecProvider;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParserFactory;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.BaseDispatcherParser;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.ExtensibleParser;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.LeafNodeBaseParser;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.LeafSetEntryNodeBaseParser;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.ListNodeBaseParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.NodeParserDispatcher;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.w3c.dom.Element;
public final class DomToNormalizedNodeParserFactory implements ToNormalizedNodeParserFactory<Element> {
+
private final AugmentationNodeDomParser augmentationNodeParser;
private final ChoiceNodeDomParser choiceNodeParser;
private final ContainerNodeDomParser containerNodeParser;
augmentationNodeParser = new AugmentationNodeDomParser(dispatcher, strictParsing);
}
+ private DomToNormalizedNodeParserFactory(final XmlCodecProvider codecProvider, final SchemaContext schema,
+ final BuildingStrategyProvider buildingStratProvider, final boolean strictParsing) {
+ leafNodeParser = new LeafNodeDomParser(codecProvider, schema, buildingStratProvider.forLeaf());
+ leafSetEntryNodeParser = new LeafSetEntryNodeDomParser(codecProvider, schema, buildingStratProvider.forLeafSetEntry());
+
+ // no buildingStrategy for Augment (no use case for now)
+ leafSetNodeParser = new LeafSetNodeDomParser(leafSetEntryNodeParser);
+ // no buildingStrategy for anyXml (probably not necessary)
+ anyXmlNodeParser = new AnyXmlDomParser();
+
+ final NodeParserDispatcher<Element> dispatcher = new NodeParserDispatcher.BaseNodeParserDispatcher<Element>(this) {
+
+ };
+
+ containerNodeParser = new ContainerNodeDomParser(dispatcher, buildingStratProvider.forContainer(), strictParsing);
+ mapEntryNodeParser = new MapEntryNodeDomParser(dispatcher, buildingStratProvider.forMapEntry(), strictParsing);
+ mapNodeParser = new MapNodeDomParser(mapEntryNodeParser, buildingStratProvider.forMap());
+ orderedListNodeParser = new OrderedListNodeDomParser(mapEntryNodeParser, buildingStratProvider.forOrderedList());
+ unkeyedListEntryNodeParser = new UnkeyedListEntryNodeDomParser(buildingStratProvider.forUnkeyedListEntry(), dispatcher);
+ unkeyedListNodeParser = new UnkeyedListNodeDomParser(buildingStratProvider.forUnkeyedList(), unkeyedListEntryNodeParser);
+ choiceNodeParser = new ChoiceNodeDomParser(dispatcher, buildingStratProvider.forChoice());
+ // no buildingStrategy for Augment (no use case for now)
+ augmentationNodeParser = new AugmentationNodeDomParser(buildingStratProvider.forAugmentation(), dispatcher, strictParsing);
+ }
+
@Deprecated
private DomToNormalizedNodeParserFactory(final XmlCodecProvider codecProvider) {
leafNodeParser = new LeafNodeDomParser(codecProvider);
return new DomToNormalizedNodeParserFactory(codecProvider, schema, true);
}
+ public static DomToNormalizedNodeParserFactory getInstance(final XmlCodecProvider codecProvider, final SchemaContext schema,
+ final BuildingStrategyProvider buildingStratProvider) {
+ return new DomToNormalizedNodeParserFactory(codecProvider, schema, buildingStratProvider, true);
+ }
+
+ public static DomToNormalizedNodeParserFactory getInstance(final XmlCodecProvider codecProvider, final SchemaContext schema,
+ final BuildingStrategyProvider buildingStratProvider,
+ final boolean strictParsing) {
+ return new DomToNormalizedNodeParserFactory(codecProvider, schema, buildingStratProvider, strictParsing);
+ }
+
@Deprecated
public static DomToNormalizedNodeParserFactory getInstance(final XmlCodecProvider codecProvider) {
return new DomToNormalizedNodeParserFactory(codecProvider);
public ToNormalizedNodeParser<Element, AnyXmlNode, AnyXmlSchemaNode> getAnyXmlNodeParser() {
return anyXmlNodeParser;
}
+
+ /**
+ * Base provider of building strategies used for customizing parsing process
+ */
+ public static abstract class BuildingStrategyProvider {
+
+ protected ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.NodeIdentifier,LeafNode<?>> forLeaf() {
+ return new LeafNodeBaseParser.SimpleLeafBuildingStrategy();
+ }
+
+ protected ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.NodeWithValue,LeafSetEntryNode<?>> forLeafSetEntry() {
+ return new LeafSetEntryNodeBaseParser.SimpleLeafSetEntryBuildingStrategy();
+ }
+
+ protected ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.NodeIdentifier,ContainerNode> forContainer() {
+ return new BaseDispatcherParser.SimpleBuildingStrategy<>();
+ }
+
+ protected ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.NodeIdentifierWithPredicates,MapEntryNode> forMapEntry() {
+ return new BaseDispatcherParser.SimpleBuildingStrategy<>();
+ }
+
+ protected ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.NodeIdentifier,MapNode> forMap() {
+ return new ListNodeBaseParser.SimpleListNodeBuildingStrategy<>();
+ }
+
+ protected ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.NodeIdentifier,OrderedMapNode> forOrderedList() {
+ return new ListNodeBaseParser.SimpleListNodeBuildingStrategy<>();
+ }
+
+ protected ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.NodeIdentifier,UnkeyedListEntryNode> forUnkeyedListEntry() {
+ return new BaseDispatcherParser.SimpleBuildingStrategy<>();
+ }
+
+ protected ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.NodeIdentifier,UnkeyedListNode> forUnkeyedList() {
+ return new ListNodeBaseParser.SimpleListNodeBuildingStrategy<>();
+ }
+
+ protected ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.NodeIdentifier,ChoiceNode> forChoice() {
+ return new BaseDispatcherParser.SimpleBuildingStrategy<>();
+ }
+
+ public ExtensibleParser.BuildingStrategy<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> forAugmentation() {
+ return new BaseDispatcherParser.SimpleBuildingStrategy<>();
+ }
+ }
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser;
+import com.google.common.base.Preconditions;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlCodecProvider;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.LeafNodeBaseParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.w3c.dom.Element;
-import com.google.common.base.Preconditions;
-
final class LeafNodeDomParser extends LeafNodeBaseParser<Element> {
private final XmlCodecProvider codecProvider;
this.codecProvider = Preconditions.checkNotNull(codecProvider);
}
+ LeafNodeDomParser(XmlCodecProvider codecProvider, final SchemaContext schema, final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, LeafNode<?>> strategy) {
+ super(strategy);
+ this.ctx = schema;
+ this.codecProvider = Preconditions.checkNotNull(codecProvider);
+ }
+
@Deprecated
LeafNodeDomParser(XmlCodecProvider codecProvider) {
this(codecProvider, null);
protected Map<QName, String> getAttributes(Element element) {
return DomUtils.toAttributes(element.getAttributes());
}
+
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser;
+import com.google.common.base.Preconditions;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlCodecProvider;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.LeafSetEntryNodeBaseParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.w3c.dom.Element;
-import com.google.common.base.Preconditions;
-
final class LeafSetEntryNodeDomParser extends LeafSetEntryNodeBaseParser<Element> {
private final XmlCodecProvider codecProvider;
private final SchemaContext ctx;
- LeafSetEntryNodeDomParser(XmlCodecProvider codecProvider, final SchemaContext schema) {
- ctx = schema;
+ LeafSetEntryNodeDomParser(final XmlCodecProvider codecProvider, final SchemaContext schema) {
+ this.ctx = schema;
+ this.codecProvider = Preconditions.checkNotNull(codecProvider);
+ }
+
+ LeafSetEntryNodeDomParser(final XmlCodecProvider codecProvider, final SchemaContext schema, final BuildingStrategy<YangInstanceIdentifier.NodeWithValue, LeafSetEntryNode<?>> strategy) {
+ super(strategy);
+ this.ctx = schema;
this.codecProvider = Preconditions.checkNotNull(codecProvider);
}
protected Map<QName, String> getAttributes(Element element) {
return DomUtils.toAttributes(element.getAttributes());
}
+
}
import com.google.common.collect.LinkedListMultimap;
import java.util.Map;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.ListEntryNodeBaseParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.NodeParserDispatcher;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils;
import org.w3c.dom.Element;
-abstract class ListEntryNodeDomParser<N extends DataContainerNode<?>> extends ListEntryNodeBaseParser<Element, N> {
+abstract class ListEntryNodeDomParser<P extends YangInstanceIdentifier.PathArgument, N extends DataContainerNode<P>> extends ListEntryNodeBaseParser<P, Element, N> {
private final NodeParserDispatcher<Element> dispatcher;
this.dispatcher = Preconditions.checkNotNull(dispatcher);
}
+ ListEntryNodeDomParser(final BuildingStrategy<P, N> buildingStrategy, final NodeParserDispatcher<Element> dispatcher) {
+ super(buildingStrategy);
+ this.dispatcher = dispatcher;
+ }
+
@Override
protected LinkedListMultimap<QName, Element> mapChildElements(Iterable<Element> elements) {
return DomUtils.mapChildElementsForSingletonNode(elements.iterator().next());
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.w3c.dom.Element;
-final class MapEntryNodeDomParser extends ListEntryNodeDomParser<MapEntryNode> {
+final class MapEntryNodeDomParser extends ListEntryNodeDomParser<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> {
private final boolean strictParsing;
MapEntryNodeDomParser(final NodeParserDispatcher<Element> dispatcher) {
super(dispatcher);
+ // TODO strict parsing attribute should be injected into superclass via a constructor
+ // WIth current approach (getter) we have to call super.strictParsing in constructor and cannot reuse constructors
this.strictParsing = super.strictParsing();
}
this.strictParsing = strictParsing;
}
+ MapEntryNodeDomParser(final NodeParserDispatcher<Element> dispatcher, final BuildingStrategy<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> strategy,
+ final boolean strictParsing) {
+ super(strategy, dispatcher);
+ this.strictParsing = strictParsing;
+ }
+
@Override
protected final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> getBuilder(
ListSchemaNode schema) {
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.MapNodeBaseParser;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
private final MapEntryNodeDomParser mapEntryParser;
- MapNodeDomParser(MapEntryNodeDomParser mapEntryParser) {
+ MapNodeDomParser(final MapEntryNodeDomParser mapEntryParser) {
+ this.mapEntryParser = mapEntryParser;
+ }
+
+ MapNodeDomParser(MapEntryNodeDomParser mapEntryParser, final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, MapNode> strategy) {
+ super(strategy);
this.mapEntryParser = mapEntryParser;
}
protected ToNormalizedNodeParser<Element, MapEntryNode, ListSchemaNode> getListEntryNodeParser() {
return mapEntryParser;
}
+
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.OrderedListNodeBaseParser;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
private final MapEntryNodeDomParser mapEntryNodeParser;
- OrderedListNodeDomParser(MapEntryNodeDomParser mapEntryNodeParser) {
+ OrderedListNodeDomParser(final MapEntryNodeDomParser mapEntryNodeParser) {
+ this.mapEntryNodeParser = mapEntryNodeParser;
+ }
+
+ OrderedListNodeDomParser(MapEntryNodeDomParser mapEntryNodeParser, final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, OrderedMapNode> strategy) {
+ super(strategy);
this.mapEntryNodeParser = mapEntryNodeParser;
}
protected ToNormalizedNodeParser<Element, MapEntryNode, ListSchemaNode> getListEntryNodeParser() {
return mapEntryNodeParser;
}
+
}
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.w3c.dom.Element;
-final class UnkeyedListEntryNodeDomParser extends ListEntryNodeDomParser<UnkeyedListEntryNode> {
+final class UnkeyedListEntryNodeDomParser extends ListEntryNodeDomParser<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> {
UnkeyedListEntryNodeDomParser(final NodeParserDispatcher<Element> dispatcher) {
super(dispatcher);
}
+ UnkeyedListEntryNodeDomParser(final BuildingStrategy<NodeIdentifier, UnkeyedListEntryNode> buildingStrategy, final NodeParserDispatcher<Element> dispatcher) {
+ super(buildingStrategy, dispatcher);
+ }
+
@Override
protected final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> getBuilder(
ListSchemaNode schema) {
*/
package org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.UnkeyedListNodeBaseParser;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
this.unkeyedListEntryNodeParser = unkeyedListEntryNodeParser;
}
+ UnkeyedListNodeDomParser(final BuildingStrategy<YangInstanceIdentifier.NodeIdentifier, UnkeyedListNode> buildingStrategy, final UnkeyedListEntryNodeDomParser unkeyedListEntryNodeParser) {
+ super(buildingStrategy);
+ this.unkeyedListEntryNodeParser = unkeyedListEntryNodeParser;
+ }
+
@Override
protected ToNormalizedNodeParser<Element, UnkeyedListEntryNode, ListSchemaNode> getListEntryNodeParser() {
return unkeyedListEntryNodeParser;
}
+
}
Document currentConfigElement = readXmlToDocument(resourceAsStream);
Preconditions.checkNotNull(currentConfigElement);
- return Optional.of(DomToNormalizedNodeParserFactory.getInstance(DomUtils.defaultValueCodecProvider(), schema).getContainerNodeParser().parse(
+ return Optional.fromNullable(DomToNormalizedNodeParserFactory.getInstance(DomUtils.defaultValueCodecProvider(), schema).getContainerNodeParser().parse(
Collections.singletonList(currentConfigElement.getDocumentElement()), containerNode));
}
package org.opendaylight.yangtools.yang.model.api.stmt;
import javax.annotation.Nonnull;
+
+import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-public interface DeviateStatement extends DeclaredStatement<String> {
+public interface DeviateStatement extends DeclaredStatement<Deviation.Deviate> {
- @Nonnull String getValue();
+ @Nonnull
+ Deviation.Deviate getValue();
}
-
package org.opendaylight.yangtools.yang.parser.spi.meta;
import java.util.List;
-
import java.util.Map;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
+public interface StmtContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
-public interface StmtContext<A,D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
-
- @Nonnull StatementSource getStatementSource();
+ @Nonnull
+ StatementSource getStatementSource();
- @Nonnull StatementSourceReference getStatementSourceReference();
+ @Nonnull
+ StatementSourceReference getStatementSourceReference();
- @Nonnull StatementDefinition getPublicDefinition();
+ @Nonnull
+ StatementDefinition getPublicDefinition();
- @Nullable StmtContext<?,?,?> getParentContext();
+ @Nullable
+ StmtContext<?, ?, ?> getParentContext();
- @Nullable String rawStatementArgument();
+ @Nullable
+ String rawStatementArgument();
- @Nullable A getStatementArgument();
+ @Nullable
+ A getStatementArgument();
- @Nullable List<Object> getArgumentsFromRoot();
+ @Nullable
+ List<Object> getArgumentsFromRoot();
- //<K,VT, V extends VT,N extends IdentifierNamespace<K, V>>
- // <K, VT, V extends VT ,N extends IdentifierNamespace<K, V>> VT getFromNamespace(Class<N> type, K key)
- @Nonnull <K,V,N extends IdentifierNamespace<K, V>> V getFromNamespace(Class<N> type, K key) throws NamespaceNotAvailableException;
+ // <K,VT, V extends VT,N extends IdentifierNamespace<K, V>>
+ // <K, VT, V extends VT ,N extends IdentifierNamespace<K, V>> VT
+ // getFromNamespace(Class<N> type, K key)
+ @Nonnull
+ <K, V, N extends IdentifierNamespace<K, V>> V getFromNamespace(
+ Class<N> type, K key) throws NamespaceNotAvailableException;
- <K, V, N extends IdentifierNamespace<K, V>> Map<?, ?> getAllFromNamespace(Class<N> type);
+ <K, V, N extends IdentifierNamespace<K, V>> Map<?, ?> getAllFromNamespace(
+ Class<N> type);
- @Nonnull StmtContext<?,?,?> getRoot();
+ @Nonnull
+ StmtContext<?, ?, ?> getRoot();
- @Nonnull Collection<StatementContextBase<?,?,?>> declaredSubstatements();
+ @Nonnull
+ Collection<StatementContextBase<?, ?, ?>> declaredSubstatements();
public Collection<StatementContextBase<?, ?, ?>> effectiveSubstatements();
E buildEffective();
- public StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,StatementContextBase<?, ?, ?> newParent) throws SourceException;
+ public StatementContextBase<?, ?, ?> createCopy(QNameModule newQNameModule,
+ StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
+ throws SourceException;
+
+ public static enum TypeOfCopy {
+ ORIGINAL, ADDED_BY_USES, ADDED_BY_AUGMENTATION
+ }
+
+ public TypeOfCopy getTypeOfCopy();
+
+ public void setTypeOfCopy(TypeOfCopy typeOfCopy);
+
+ public StatementContextBase<?, ?, ?> getOriginalCtx();
- interface Mutable<A,D extends DeclaredStatement<A>,E extends EffectiveStatement<A, D>> extends StmtContext<A,D,E> {
+ public void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx);
+
+ public boolean isRootContext();
+
+ public void setCompletedPhase(ModelProcessingPhase completedPhase);
+
+ public ModelProcessingPhase getCompletedPhase();
+
+ interface Mutable<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+ extends StmtContext<A, D, E> {
@Override
- StmtContext.Mutable<?,?,?> getParentContext();
+ StmtContext.Mutable<?, ?, ?> getParentContext();
- //<K,V,VT extends V,N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, K key, VT value)
- <K,V,VT extends V,N extends IdentifierNamespace<K, V>> void addToNs(Class<N> type, K key, VT value) throws NamespaceNotAvailableException;
+ // <K,V,VT extends V,N extends IdentifierNamespace<K, V>> void
+ // addToNs(Class<N> type, K key, VT value)
+ <K, V, VT extends V, N extends IdentifierNamespace<K, V>> void addToNs(
+ Class<N> type, K key, VT value)
+ throws NamespaceNotAvailableException;
@Override
- StmtContext.Mutable<?,?,?> getRoot();
+ StmtContext.Mutable<?, ?, ?> getRoot();
ModelActionBuilder newInferenceAction(ModelProcessingPhase phase);
- <K,KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(Class<N> namespace, KT key,
- StmtContext<?, ?, ?> stmt);
+ <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
+ Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt);
}
-
-
}
}
@SuppressWarnings("unchecked")
-
public static final <E extends EffectiveStatement<?, ?>> Function<StmtContext<?, ?, ? extends E>, E> buildEffective() {
return Function.class.cast(BUILD_EFFECTIVE);
}
*/
return (NamespaceBehaviourWithListeners<K, V, N>) potential;
}
- throw new NamespaceNotAvailableException("Namespace " + type + "is not available in phase " + currentPhase);
+ throw new NamespaceNotAvailableException("Namespace " + type + " is not available in phase " + currentPhase);
}
public StatementDefinitionContext<?, ?, ?> getStatementDefinition(QName name) {
switch (sourceProgress) {
case FINISHED:
currentSource.remove();
+ // Fallback to progress, since we were able to make progress in computation
case PROGRESS:
progressing = true;
+ break;
case NO_PROGRESS:
- // Noop;
+ // Noop
+ break;
+ default:
+ throw new IllegalStateException("Unsupported phase progress " + sourceProgress);
}
}
}
}
private void tryToResolve() throws InferenceException {
- if(action == null) {
+ if(action == null || isApplied()) {
// Action was not yet defined
return;
}
private void applyAction() throws InferenceException {
- action.apply();
- //Â Mark all mutations as performed, so context node could move to next.
+ try {
+ action.apply();
+ } catch (InferenceException e) {
+ actionApplied = false;
+ return;
+ }
+ // Â Mark all mutations as performed, so context node could move to next.
actionApplied = true;
}
return done;
}
- protected void resolvePrereq(T value) throws InferenceException {
- Preconditions.checkState(!isDone());
+ protected boolean resolvePrereq(T value) throws InferenceException {
this.value = value;
this.done = true;
tryToResolve();
+ return isApplied();
}
protected <O> Prerequisite<O> transform(final Function<? super T,O> transformation) {
@SuppressWarnings("unchecked")
@Override
- public void phaseFinished(StatementContextBase<?, ?, ?> context, ModelProcessingPhase phase) throws SourceException {
- resolvePrereq((C) (context));
+ public boolean phaseFinished(StatementContextBase<?, ?, ?> context, ModelProcessingPhase phase) throws SourceException {
+ return resolvePrereq((C) (context));
}
}
@SuppressWarnings("unchecked")
@Override
- public void phaseFinished(StatementContextBase<?, ?, ?> context, ModelProcessingPhase phase) throws SourceException {
- resolvePrereq((C) context);
+ public boolean phaseFinished(StatementContextBase<?, ?, ?> context, ModelProcessingPhase phase) throws SourceException {
+ return resolvePrereq((C) context);
}
}
}
RootStatementContext(RootStatementContext<A, D, E> original,
- QNameModule newQNameModule) throws SourceException {
+ QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+ throws SourceException {
super(original);
sourceContext = original.sourceContext;
this.argument = original.argument;
- copyDeclaredStmts(original, newQNameModule);
+ copyDeclaredStmts(original, newQNameModule, typeOfCopy);
- copyEffectiveStmts(original, newQNameModule);
+ copyEffectiveStmts(original, newQNameModule, typeOfCopy);
}
private void copyDeclaredStmts(RootStatementContext<A, D, E> original,
- QNameModule newQNameModule) throws SourceException {
+ QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+ throws SourceException {
Collection<? extends StmtContext<?, ?, ?>> originalDeclaredSubstatements = original
.declaredSubstatements();
for (StmtContext<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
- this.addEffectiveSubstatement(stmtContext
- .createCopy(newQNameModule,this));
+ this.addEffectiveSubstatement(stmtContext.createCopy(
+ newQNameModule, this, typeOfCopy));
}
}
private void copyEffectiveStmts(RootStatementContext<A, D, E> original,
- QNameModule newQNameModule) throws SourceException {
+ QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+ throws SourceException {
Collection<? extends StmtContext<?, ?, ?>> originalEffectiveSubstatements = original
.effectiveSubstatements();
for (StmtContext<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
- this.addEffectiveSubstatement(stmtContext
- .createCopy(newQNameModule,this));
+ this.addEffectiveSubstatement(stmtContext.createCopy(
+ newQNameModule, this, typeOfCopy));
}
}
}
@Override
- public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent)
+ public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
+ StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
throws SourceException {
-
- return new RootStatementContext<>(this, newQNameModule);
+ RootStatementContext<A, D, E> copy = new RootStatementContext<>(this,
+ newQNameModule, typeOfCopy);
+ copy.setTypeOfCopy(typeOfCopy);
+ copy.setOriginalCtx(this);
+ return copy;
}
@Override
return argumentList;
}
+ @Override
+ public boolean isRootContext() {
+ return true;
+ }
}
boolean phaseCompleted = root.tryToCompletePhase(phase);
- hasProgressed = hasProgress(currentPhaseModifiers);
+ hasProgressed = (hasProgress(currentPhaseModifiers) | hasProgressed);
if(phaseCompleted && (currentPhaseModifiers.isEmpty())) {
finishedPhase = phase;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.NamespaceBehaviourWithListeners.ValueAddedListener;
-public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> extends
- NamespaceStorageSupport implements StmtContext.Mutable<A, D, E>, Identifiable<StatementIdentifier> {
+public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+ extends NamespaceStorageSupport implements
+ StmtContext.Mutable<A, D, E>, Identifiable<StatementIdentifier> {
- interface OnNamespaceItemAdded extends EventListener{
+ interface OnNamespaceItemAdded extends EventListener {
- void namespaceItemAdded(StatementContextBase<?,?,?> context, Class<?> namespace, Object key, Object value) throws SourceException;
+ void namespaceItemAdded(StatementContextBase<?, ?, ?> context,
+ Class<?> namespace, Object key, Object value)
+ throws SourceException;
}
- interface OnPhaseFinished extends EventListener{
+ interface OnPhaseFinished extends EventListener {
- void phaseFinished(StatementContextBase<?,?,?> context, ModelProcessingPhase phase) throws SourceException;
+ boolean phaseFinished(StatementContextBase<?, ?, ?> context,
+ ModelProcessingPhase phase) throws SourceException;
}
private String rawArg;
private StatementSourceReference argRef;
- public ContextBuilder(StatementDefinitionContext<A, D, E> def, StatementSourceReference sourceRef) {
+ public ContextBuilder(StatementDefinitionContext<A, D, E> def,
+ StatementSourceReference sourceRef) {
this.definition = def;
this.stmtRef = sourceRef;
}
- public void setArgument(@Nonnull String argument, @Nonnull StatementSourceReference argumentSource) {
- Preconditions.checkArgument(definition.hasArgument(), "Statement does not take argument.");
+ public void setArgument(@Nonnull String argument,
+ @Nonnull StatementSourceReference argumentSource) {
+ Preconditions.checkArgument(definition.hasArgument(),
+ "Statement does not take argument.");
this.rawArg = Preconditions.checkNotNull(argument);
this.argRef = Preconditions.checkNotNull(argumentSource);
}
}
public StatementIdentifier getIdentifier() {
- return new StatementIdentifier(definition.getStatementName(), rawArg);
+ return new StatementIdentifier(definition.getStatementName(),
+ rawArg);
}
- public abstract StatementContextBase<A, D, E> build() throws SourceException;
+ public abstract StatementContextBase<A, D, E> build()
+ throws SourceException;
}
private final StatementIdentifier identifier;
private final StatementSourceReference statementDeclSource;
- private Map<StatementIdentifier, StatementContextBase<?, ?, ?> > substatements = new LinkedHashMap<>();
+ private Map<StatementIdentifier, StatementContextBase<?, ?, ?>> substatements = new LinkedHashMap<>();
private Collection<StatementContextBase<?, ?, ?>> declared = new ArrayList<>();
private Collection<StatementContextBase<?, ?, ?>> effective = new ArrayList<>();
private ModelProcessingPhase completedPhase;
- private Multimap<ModelProcessingPhase,OnPhaseFinished> phaseListeners = HashMultimap.create();
- private Multimap<ModelProcessingPhase, ContextMutation> phaseMutation = HashMultimap.create();
+ private Multimap<ModelProcessingPhase, OnPhaseFinished> phaseListeners = HashMultimap
+ .create();
+ private Multimap<ModelProcessingPhase, ContextMutation> phaseMutation = HashMultimap
+ .create();
private D declaredInstance;
private E effectiveInstance;
+ private StatementContextBase<?, ?, ?> originalCtx;
+ private TypeOfCopy typeOfCopy = TypeOfCopy.ORIGINAL;
- StatementContextBase(@Nonnull ContextBuilder<A, D, E> builder) throws SourceException {
+ @Override
+ public TypeOfCopy getTypeOfCopy() {
+ return typeOfCopy;
+ }
+
+ @Override
+ public void setTypeOfCopy(TypeOfCopy typeOfCopy) {
+ this.typeOfCopy = typeOfCopy;
+ }
+
+ @Override
+ public StatementContextBase<?, ?, ?> getOriginalCtx() {
+ return originalCtx;
+ }
+
+ @Override
+ public void setOriginalCtx(StatementContextBase<?, ?, ?> originalCtx) {
+ this.originalCtx = originalCtx;
+ }
+
+ @Override
+ public ModelProcessingPhase getCompletedPhase() {
+ return completedPhase;
+ }
+
+ @Override
+ public void setCompletedPhase(ModelProcessingPhase completedPhase) {
+ this.completedPhase = completedPhase;
+ }
+
+ StatementContextBase(@Nonnull ContextBuilder<A, D, E> builder)
+ throws SourceException {
this.definition = builder.getDefinition();
this.identifier = builder.getIdentifier();
this.statementDeclSource = builder.getStamementSource();
this.completedPhase = null;
}
- StatementContextBase(StatementContextBase<A,D,E> original) {
+ StatementContextBase(StatementContextBase<A, D, E> original) {
this.definition = original.definition;
this.identifier = original.identifier;
this.statementDeclSource = original.statementDeclSource;
@Override
public abstract RootStatementContext<?, ?, ?> getRoot();
-
@Override
public StatementIdentifier getIdentifier() {
return identifier;
return Collections.unmodifiableCollection(effective);
}
- public void addEffectiveSubstatement(StatementContextBase<?, ?, ?> substatement){
+ public void addEffectiveSubstatement(
+ StatementContextBase<?, ?, ?> substatement) {
effective.add(substatement);
}
- public void addDeclaredSubstatement(StatementContextBase<?, ?, ?> substatement){
+ public void addDeclaredSubstatement(
+ StatementContextBase<?, ?, ?> substatement) {
declared.add(substatement);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- public ContextBuilder<?, ?, ?> substatementBuilder(StatementDefinitionContext<?, ?, ?> def,
+ public ContextBuilder<?, ?, ?> substatementBuilder(
+ StatementDefinitionContext<?, ?, ?> def,
StatementSourceReference ref) {
return new ContextBuilder(def, ref) {
@Override
public StatementContextBase build() throws SourceException {
- StatementContextBase<?, ?, ?> potential = substatements.get(getIdentifier());
- if(potential == null) {
- potential = new SubstatementContext(StatementContextBase.this, this);
+ StatementContextBase<?, ?, ?> potential = substatements
+ .get(getIdentifier());
+ if (potential == null) {
+ potential = new SubstatementContext(
+ StatementContextBase.this, this);
substatements.put(getIdentifier(), potential);
}
potential.resetLists();
switch (this.getStamementSource().getStatementSource()) {
- case DECLARATION:
- declared.add(potential);
- break;
- case CONTEXT:
- effective.add(potential);
- break;
+ case DECLARATION:
+ declared.add(potential);
+ break;
+ case CONTEXT:
+ effective.add(potential);
+ break;
}
return potential;
}
};
}
-
-
@Override
public StorageNodeType getStorageNodeType() {
return StorageNodeType.STATEMENT_LOCAL;
@Override
public D buildDeclared() {
- Preconditions.checkArgument(completedPhase == ModelProcessingPhase.FULL_DECLARATION || completedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
+ Preconditions
+ .checkArgument(completedPhase == ModelProcessingPhase.FULL_DECLARATION
+ || completedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
if (declaredInstance == null) {
declaredInstance = definition().getFactory().createDeclared(this);
}
@Override
public E buildEffective() {
- Preconditions.checkArgument(completedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
if (effectiveInstance == null) {
effectiveInstance = definition().getFactory().createEffective(this);
}
return effectiveInstance;
}
-
void resetLists() {
declared.clear();
}
- boolean tryToCompletePhase(ModelProcessingPhase phase) throws SourceException {
- if(phase.equals(completedPhase)) {
- return true;
- }
- Iterator<ContextMutation> openMutations = phaseMutation.get(phase).iterator();
+ boolean tryToCompletePhase(ModelProcessingPhase phase)
+ throws SourceException {
+ Iterator<ContextMutation> openMutations = phaseMutation.get(phase)
+ .iterator();
boolean finished = true;
- while(openMutations.hasNext()) {
+ while (openMutations.hasNext()) {
ContextMutation current = openMutations.next();
- if(current.isFinished()) {
+ if (current.isFinished()) {
openMutations.remove();
} else {
finished = false;
}
}
- for(StatementContextBase<?, ?, ?> child: declared) {
+ for (StatementContextBase<?, ?, ?> child : declared) {
finished &= child.tryToCompletePhase(phase);
}
- for(StatementContextBase<?, ?, ?> child: effective) {
+ for (StatementContextBase<?, ?, ?> child : effective) {
finished &= child.tryToCompletePhase(phase);
}
- if(finished) {
+
+ if (finished) {
onPhaseCompleted(phase);
return true;
}
return false;
}
-
- private void onPhaseCompleted(ModelProcessingPhase phase) throws SourceException {
+ private void onPhaseCompleted(ModelProcessingPhase phase)
+ throws SourceException {
completedPhase = phase;
- Iterator<OnPhaseFinished> listener = phaseListeners.get(completedPhase).iterator();
- while(listener.hasNext()) {
- listener.next().phaseFinished(this, phase);
- listener.remove();
+ Iterator<OnPhaseFinished> listener = phaseListeners.get(completedPhase)
+ .iterator();
+ while (listener.hasNext()) {
+ OnPhaseFinished next = listener.next();
+ if(next.phaseFinished(this, phase)) {
+ listener.remove();
+ }
}
}
* @throws SourceException
*
*/
- void endDeclared(StatementSourceReference ref,ModelProcessingPhase phase) throws SourceException {
- definition().onDeclarationFinished(this,phase);
+ void endDeclared(StatementSourceReference ref, ModelProcessingPhase phase)
+ throws SourceException {
+ definition().onDeclarationFinished(this, phase);
}
protected final StatementDefinitionContext<A, D, E> definition() {
}
@Override
- protected void checkLocalNamespaceAllowed(Class<? extends IdentifierNamespace<?, ?>> type) {
+ protected void checkLocalNamespaceAllowed(
+ Class<? extends IdentifierNamespace<?, ?>> type) {
definition().checkNamespaceAllowed(type);
}
@Override
- protected <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceElementAdded(Class<N> type, K key, V value) {
- //definition().onNamespaceElementAdded(this, type, key, value);
+ protected <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceElementAdded(
+ Class<N> type, K key, V value) {
+ // definition().onNamespaceElementAdded(this, type, key, value);
}
- <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceItemAddedAction(final Class<N> type, K key, final OnNamespaceItemAdded listener) throws SourceException {
+ <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceItemAddedAction(
+ final Class<N> type, K key, final OnNamespaceItemAdded listener)
+ throws SourceException {
Object potential = getFromNamespace(type, key);
- if(potential != null) {
+ if (potential != null) {
listener.namespaceItemAdded(this, type, key, potential);
return;
}
- NamespaceBehaviour<K,V,N> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
- if(behaviour instanceof NamespaceBehaviourWithListeners) {
- NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K,V,N>) behaviour;
+ NamespaceBehaviour<K, V, N> behaviour = getBehaviourRegistry()
+ .getNamespaceBehaviour(type);
+ if (behaviour instanceof NamespaceBehaviourWithListeners) {
+ NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K, V, N>) behaviour;
casted.addValueListener(key, new ValueAddedListener(this) {
@Override
void onValueAdded(Object key, Object value) {
try {
- listener.namespaceItemAdded(StatementContextBase.this, type, key, value);
+ listener.namespaceItemAdded(StatementContextBase.this,
+ type, key, value);
} catch (SourceException e) {
throw Throwables.propagate(e);
}
return getRoot().getSourceContext().newInferenceAction(phase);
}
- void addPhaseCompletedListener(ModelProcessingPhase phase, OnPhaseFinished listener) throws SourceException {
+ void addPhaseCompletedListener(ModelProcessingPhase phase,
+ OnPhaseFinished listener) throws SourceException {
ModelProcessingPhase finishedPhase = completedPhase;
while (finishedPhase != null) {
- if(phase.equals(finishedPhase)) {
+ if (phase.equals(finishedPhase)) {
listener.phaseFinished(this, finishedPhase);
return;
}
void addMutation(ModelProcessingPhase phase, ContextMutation mutation) {
ModelProcessingPhase finishedPhase = completedPhase;
while (finishedPhase != null) {
- if(phase.equals(finishedPhase)) {
- throw new IllegalStateException("Mutation registered after phase was completed.");
+ if (phase.equals(finishedPhase)) {
+ throw new IllegalStateException(
+ "Mutation registered after phase was completed.");
}
finishedPhase = finishedPhase.getPreviousPhase();
}
}
@Override
- public <K,KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
+ public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(
Class<N> namespace, KT key, StmtContext<?, ?, ?> stmt) {
- addContextToNamespace(namespace,(K) key, stmt);
+ addContextToNamespace(namespace, (K) key, stmt);
}
}
package org.opendaylight.yangtools.yang.parser.stmt.reactor;
import java.util.List;
-
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.GroupingUtils;
import org.opendaylight.yangtools.yang.common.QNameModule;
import java.util.Collection;
import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-class SubstatementContext<A,D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
- extends StatementContextBase<A,D,E> {
+class SubstatementContext<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
+ extends StatementContextBase<A, D, E> {
- private final StatementContextBase<?,?,?> parent;
+ private final StatementContextBase<?, ?, ?> parent;
private final A argument;
- SubstatementContext(StatementContextBase<?,?,?> parent,ContextBuilder<A,D,E> builder) throws SourceException {
- //super(builder, builder.getDefinition().parseArgumentValue(parent, builder.getRawArgument()));
+ SubstatementContext(StatementContextBase<?, ?, ?> parent,
+ ContextBuilder<A, D, E> builder) throws SourceException {
super(builder);
- this.parent = Preconditions.checkNotNull(parent, "Parent must not be null");
- this.argument = builder.getDefinition().parseArgumentValue(this, builder.getRawArgument());
+ this.parent = Preconditions.checkNotNull(parent,
+ "Parent must not be null");
+ this.argument = builder.getDefinition().parseArgumentValue(this,
+ builder.getRawArgument());
}
- SubstatementContext(SubstatementContext<A,D,E> original, QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
+ SubstatementContext(SubstatementContext<A, D, E> original,
+ QNameModule newQNameModule,
+ StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
+ throws SourceException {
super(original);
this.parent = newParent;
- if(newQNameModule != null && original.argument instanceof QName) {
+ if (newQNameModule != null && original.argument instanceof QName) {
QName originalQName = (QName) original.argument;
- this.argument = (A) QName.create(newQNameModule,originalQName.getLocalName());
+ this.argument = (A) QName.create(newQNameModule,
+ originalQName.getLocalName());
} else {
this.argument = original.argument;
}
- copyDeclaredStmts(original, newQNameModule);
+ copyDeclaredStmts(original, newQNameModule, typeOfCopy);
- copyEffectiveStmts(original, newQNameModule);
+ copyEffectiveStmts(original, newQNameModule, typeOfCopy);
}
private void copyDeclaredStmts(SubstatementContext<A, D, E> original,
- QNameModule newQNameModule) throws SourceException {
+ QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+ throws SourceException {
Collection<? extends StatementContextBase<?, ?, ?>> originalDeclaredSubstatements = original
.declaredSubstatements();
for (StatementContextBase<?, ?, ?> stmtContext : originalDeclaredSubstatements) {
if (GroupingUtils.needToCopyByUses(stmtContext)) {
- StatementContextBase<?, ?, ?> copy = stmtContext
- .createCopy(newQNameModule,this);
+ StatementContextBase<?, ?, ?> copy = stmtContext.createCopy(
+ newQNameModule, this, typeOfCopy);
this.addEffectiveSubstatement(copy);
} else if (GroupingUtils.isReusedByUses(stmtContext)) {
this.addEffectiveSubstatement(stmtContext);
}
private void copyEffectiveStmts(SubstatementContext<A, D, E> original,
- QNameModule newQNameModule) throws SourceException {
+ QNameModule newQNameModule, TypeOfCopy typeOfCopy)
+ throws SourceException {
Collection<? extends StatementContextBase<?, ?, ?>> originalEffectiveSubstatements = original
.effectiveSubstatements();
for (StatementContextBase<?, ?, ?> stmtContext : originalEffectiveSubstatements) {
if (GroupingUtils.needToCopyByUses(stmtContext)) {
- StatementContextBase<?, ?, ?> copy = stmtContext
- .createCopy(newQNameModule,this);
+ StatementContextBase<?, ?, ?> copy = stmtContext.createCopy(
+ newQNameModule, this, typeOfCopy);
this.addEffectiveSubstatement(copy);
} else if (GroupingUtils.isReusedByUses(stmtContext)) {
this.addEffectiveSubstatement(stmtContext);
}
@Override
- public StatementContextBase<?,?,?> getParentContext() {
+ public StatementContextBase<?, ?, ?> getParentContext() {
return parent;
}
return parent.getRoot();
}
-
@Override
public A getStatementArgument() {
return argument;
}
@Override
- public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule, StatementContextBase<?, ?, ?> newParent) throws SourceException {
- return new SubstatementContext<>(this,newQNameModule, newParent);
+ public StatementContextBase<A, D, E> createCopy(QNameModule newQNameModule,
+ StatementContextBase<?, ?, ?> newParent, TypeOfCopy typeOfCopy)
+ throws SourceException {
+ SubstatementContext<A, D, E> copy = new SubstatementContext<>(this,
+ newQNameModule, newParent, typeOfCopy);
+ copy.setTypeOfCopy(typeOfCopy);
+ copy.setOriginalCtx(this);
+ return copy;
}
@Override
return argumentsFromRoot;
}
-
+ @Override
+ public boolean isRootContext() {
+ return false;
+ }
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.EFFECTIVE_MODEL;
-
import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
-
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AugmentEffectiveStatementImpl;
-public class AugmentStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements AugmentStatement {
+public class AugmentStatementImpl extends
+ AbstractDeclaredStatement<SchemaNodeIdentifier> implements
+ AugmentStatement {
- private static final Logger LOG = LoggerFactory.getLogger(AugmentStatementImpl.class);
+ private static final Logger LOG = LoggerFactory
+ .getLogger(AugmentStatementImpl.class);
- protected AugmentStatementImpl(StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
+ protected AugmentStatementImpl(
+ StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> context) {
super(context);
}
- public static class Definition extends AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
+ public static class Definition
+ extends
+ AbstractStatementSupport<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> {
public Definition() {
super(Rfc6020Mapping.AUGMENT);
}
@Override
- public SchemaNodeIdentifier parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return SchemaNodeIdentifier.create(AugmentUtils.parseAugmentPath(ctx, value), Utils.isXPathAbsolute(value));
+ public SchemaNodeIdentifier parseArgumentValue(
+ StmtContext<?, ?, ?> ctx, String value) throws SourceException {
+ return SchemaNodeIdentifier.create(
+ AugmentUtils.parseAugmentPath(ctx, value),
+ Utils.isXPathAbsolute(value));
}
@Override
- public AugmentStatement createDeclared(StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
+ public AugmentStatement createDeclared(
+ StmtContext<SchemaNodeIdentifier, AugmentStatement, ?> ctx) {
return new AugmentStatementImpl(ctx);
}
final StmtContext.Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode)
throws SourceException {
- final ModelActionBuilder augmentAction = augmentNode.newInferenceAction(EFFECTIVE_MODEL);
+ final ModelActionBuilder augmentAction = augmentNode
+ .newInferenceAction(ModelProcessingPhase.FULL_DECLARATION);
final ModelActionBuilder.Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>>> sourceCtxPrereq = augmentAction
- .requiresCtx(augmentNode, ModelProcessingPhase.FULL_DECLARATION);
+ .requiresCtx(augmentNode,
+ ModelProcessingPhase.FULL_DECLARATION);
augmentAction.apply(new ModelActionBuilder.InferenceAction() {
@Override
public void apply() throws InferenceException {
- final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils.getAugmentTargetCtx(augmentNode);
- final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) sourceCtxPrereq.get();
+ final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils
+ .getAugmentTargetCtx(augmentNode);
+
+ if (augmentTargetCtx == null) {
+ throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(), augmentNode.getStatementSourceReference());
+ }
+
+ final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) sourceCtxPrereq
+ .get();
try {
- AugmentUtils.copyFromSourceToTarget(augmentSourceCtx, augmentTargetCtx);
+ AugmentUtils.copyFromSourceToTarget(augmentSourceCtx,
+ augmentTargetCtx);
} catch (SourceException e) {
LOG.warn(e.getMessage(), e);
}
+
}
@Override
- public void prerequisiteFailed(final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
+ public void prerequisiteFailed(
+ final Collection<? extends ModelActionBuilder.Prerequisite<?>> failed)
throws InferenceException {
- if (failed.contains(augmentAction)) {
- throw new InferenceException("Augment action failed", augmentNode.getStatementSourceReference());
- }
+ throw new InferenceException("Augment target not found: "+augmentNode.getStatementArgument(),
+ augmentNode.getStatementSourceReference());
}
});
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import java.util.Iterator;
+import javax.annotation.Nullable;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
private AugmentUtils() {
}
- public static Iterable<QName> parseAugmentPath(StmtContext<?, ?, ?> ctx, String path) {
+ public static Iterable<QName> parseAugmentPath(StmtContext<?, ?, ?> ctx,
+ String path) {
if (path.matches(REGEX_PATH_REL1) || path.matches(REGEX_PATH_REL2)) {
throw new IllegalArgumentException(
return Utils.parseXPath(ctx, path);
}
- public static void copyFromSourceToTarget(StatementContextBase<?, ?, ?> sourceCtx,
- StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
+ public static void copyFromSourceToTarget(
+ StatementContextBase<?, ?, ?> sourceCtx,
+ StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
QNameModule newQNameModule = getNewQNameModule(targetCtx, sourceCtx);
copyDeclaredStmts(sourceCtx, targetCtx, newQNameModule);
}
- public static void copyDeclaredStmts(StatementContextBase<?, ?, ?> sourceCtx,
- StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
- Collection<? extends StatementContextBase<?, ?, ?>> declaredSubstatements = sourceCtx.declaredSubstatements();
+ public static void copyDeclaredStmts(
+ StatementContextBase<?, ?, ?> sourceCtx,
+ StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule)
+ throws SourceException {
+ Collection<? extends StatementContextBase<?, ?, ?>> declaredSubstatements = sourceCtx
+ .declaredSubstatements();
for (StatementContextBase<?, ?, ?> originalStmtCtx : declaredSubstatements) {
if (needToCopyByAugment(originalStmtCtx)) {
- StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
+ StatementContextBase<?, ?, ?> copy = originalStmtCtx
+ .createCopy(newQNameModule, targetCtx,
+ TypeOfCopy.ADDED_BY_AUGMENTATION);
targetCtx.addEffectiveSubstatement(copy);
} else if (isReusedByAugment(originalStmtCtx)) {
targetCtx.addEffectiveSubstatement(originalStmtCtx);
}
}
- public static void copyEffectiveStmts(StatementContextBase<?, ?, ?> sourceCtx,
- StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule) throws SourceException {
- Collection<? extends StatementContextBase<?, ?, ?>> effectiveSubstatements = sourceCtx.effectiveSubstatements();
+ public static void copyEffectiveStmts(
+ StatementContextBase<?, ?, ?> sourceCtx,
+ StatementContextBase<?, ?, ?> targetCtx, QNameModule newQNameModule)
+ throws SourceException {
+ Collection<? extends StatementContextBase<?, ?, ?>> effectiveSubstatements = sourceCtx
+ .effectiveSubstatements();
for (StatementContextBase<?, ?, ?> originalStmtCtx : effectiveSubstatements) {
if (needToCopyByAugment(originalStmtCtx)) {
- StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
+ StatementContextBase<?, ?, ?> copy = originalStmtCtx
+ .createCopy(newQNameModule, targetCtx,
+ TypeOfCopy.ADDED_BY_AUGMENTATION);
targetCtx.addEffectiveSubstatement(copy);
} else if (isReusedByAugment(originalStmtCtx)) {
targetCtx.addEffectiveSubstatement(originalStmtCtx);
}
}
- public static QNameModule getNewQNameModule(StatementContextBase<?, ?, ?> targetCtx,
- StatementContextBase<?, ?, ?> sourceCtx) {
+ public static QNameModule getNewQNameModule(
+ StatementContextBase<?, ?, ?> targetCtx,
+ StatementContextBase<?, ?, ?> sourceCtx) {
Object targetStmtArgument = targetCtx.getStatementArgument();
final StatementContextBase<?, ?, ?> root = sourceCtx.getRoot();
final String moduleName = (String) root.getStatementArgument();
- final QNameModule sourceQNameModule = root.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
+ final QNameModule sourceQNameModule = root.getFromNamespace(
+ ModuleNameToModuleQName.class, moduleName);
if (targetStmtArgument instanceof QName) {
QName targetQName = (QName) targetStmtArgument;
public static StatementContextBase<?, ?, ?> getAugmentTargetCtx(
final Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode) {
- final SchemaNodeIdentifier augmentTargetNode = augmentNode.getStatementArgument();
+ final SchemaNodeIdentifier augmentTargetNode = augmentNode
+ .getStatementArgument();
+ if (augmentTargetNode == null) {
+ throw new IllegalArgumentException(
+ "Augment argument null, something bad happened in some of previous parsing phases");
+ }
List<StatementContextBase<?, ?, ?>> rootStatementCtxList = new LinkedList<>();
if (augmentTargetNode.isAbsolute()) {
- QNameModule module;
- if (augmentTargetNode != null) {
- module = augmentTargetNode.getPathFromRoot().iterator().next().getModule();
- } else {
- throw new IllegalArgumentException(
- "Augment argument null, something bad happened in some of previous parsing phases");
- }
+ QNameModule module = augmentTargetNode.getPathFromRoot().iterator()
+ .next().getModule();
- StatementContextBase<?, ?, ?> rootStatementCtx = (StatementContextBase<?, ?, ?>) augmentNode.getFromNamespace(
- NamespaceToModule.class, module);
+ StatementContextBase<?, ?, ?> rootStatementCtx = (StatementContextBase<?, ?, ?>) augmentNode
+ .getFromNamespace(NamespaceToModule.class, module);
rootStatementCtxList.add(rootStatementCtx);
- final Map<?, ?> subModules = rootStatementCtx.getAllFromNamespace(IncludedModuleContext.class);
+ final Map<?, ?> subModules = rootStatementCtx
+ .getAllFromNamespace(IncludedModuleContext.class);
if (subModules != null) {
- rootStatementCtxList.addAll((Collection<? extends StatementContextBase<?, ?, ?>>) subModules.values());
+ rootStatementCtxList
+ .addAll((Collection<? extends StatementContextBase<?, ?, ?>>) subModules
+ .values());
}
} else {
- StatementContextBase<?, ?, ?> parent = (StatementContextBase<?, ?, ?>) augmentNode.getParentContext();
+ StatementContextBase<?, ?, ?> parent = (StatementContextBase<?, ?, ?>) augmentNode
+ .getParentContext();
if (StmtContextUtils.producesDeclared(parent, UsesStatement.class)) {
rootStatementCtxList.add(parent.getParentContext());
} else {
- //error
+ // error
}
}
- List<QName> augmentTargetPath = new LinkedList<>();
-
- augmentTargetPath.addAll((Collection<? extends QName>) augmentTargetNode.getPathFromRoot());
-
StatementContextBase<?, ?, ?> augmentTargetCtx = null;
for (final StatementContextBase<?, ?, ?> rootStatementCtx : rootStatementCtxList) {
- augmentTargetCtx = Utils.findCtxOfNodeInRoot(rootStatementCtx,
- augmentTargetPath);
- if (augmentTargetCtx != null) break;
+ augmentTargetCtx = findCtxOfNodeInRoot(rootStatementCtx,
+ augmentTargetNode);
+ if (augmentTargetCtx != null)
+ break;
+ }
+
+ return augmentTargetCtx;
+ }
+
+ @Nullable
+ public static StatementContextBase<?, ?, ?> findCtxOfNodeInSubstatements(
+ StatementContextBase<?, ?, ?> rootStmtCtx,
+ final Iterable<QName> path) {
+
+ StatementContextBase<?, ?, ?> parent = rootStmtCtx;
+
+ Iterator<QName> pathIter = path.iterator();
+ while (pathIter.hasNext()) {
+ QName nextPathQName = pathIter.next();
+ StatementContextBase<?, ?, ?> foundSubstatement = getSubstatementByQName(
+ parent, nextPathQName);
+
+ if (foundSubstatement == null) {
+ return null;
+ }
+ if (!pathIter.hasNext()) {
+ return foundSubstatement;
+ }
+
+ parent = foundSubstatement;
}
+ return null;
+ }
+
+ public static StatementContextBase<?, ?, ?> getSubstatementByQName(
+ StatementContextBase<?, ?, ?> parent, QName nextPathQName) {
- if (augmentTargetCtx == null) {
+ Collection<StatementContextBase<?, ?, ?>> declaredSubstatement = parent
+ .declaredSubstatements();
+ Collection<StatementContextBase<?, ?, ?>> effectiveSubstatement = parent
+ .effectiveSubstatements();
- throw new NullPointerException(String.format(
- "Augment path %s not found in target model so its resulting context is null",
- augmentNode.rawStatementArgument()));
+ Collection<StatementContextBase<?, ?, ?>> allSubstatements = new LinkedList<>();
+ allSubstatements.addAll(declaredSubstatement);
+ allSubstatements.addAll(effectiveSubstatement);
+ for (StatementContextBase<?, ?, ?> substatement : allSubstatements) {
+ if (isAllowedAugmentTarget(substatement)
+ && nextPathQName
+ .equals(substatement.getStatementArgument())) {
+ return substatement;
+ }
}
- return augmentTargetCtx;
+ return null;
+ }
+
+ public static boolean isAllowedAugmentTarget(
+ StatementContextBase<?, ?, ?> substatement) {
+
+ /*
+ * :TODO Substatement must be allowed augment target type e.g.
+ * Container, etc... and must be not for example grouping, identity etc.
+ * It is problem in case when more than one substatements have the same
+ * QName, for example Grouping and Container are siblings and they have the
+ * same QName. We must find the Container and the Grouping must be ignored
+ * as disallowed augment target.
+ */
+
+ return true;
+ }
+
+ @Nullable
+ public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(
+ StatementContextBase<?, ?, ?> rootStmtCtx,
+ final SchemaNodeIdentifier node) {
+ return findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot());
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeviateEffectiveStatementImpl;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
import javax.annotation.Nonnull;
-public class DeviateStatementImpl extends AbstractDeclaredStatement<String> implements DeviateStatement {
+public class DeviateStatementImpl extends AbstractDeclaredStatement<Deviation.Deviate> implements DeviateStatement {
protected DeviateStatementImpl(
- StmtContext<String, DeviateStatement, ?> context) {
+ StmtContext<Deviation.Deviate, DeviateStatement, ?> context) {
super(context);
}
- public static class Definition extends AbstractStatementSupport<String,DeviateStatement,EffectiveStatement<String,DeviateStatement>> {
+ public static class Definition extends AbstractStatementSupport<Deviation.Deviate,DeviateStatement,EffectiveStatement<Deviation.Deviate,DeviateStatement>> {
public Definition() {
super(Rfc6020Mapping.DEVIATE);
}
- @Override public String parseArgumentValue(
+ @Override public Deviation.Deviate parseArgumentValue(
StmtContext<?, ?, ?> ctx, String value) throws SourceException {
- return value;
+ return Utils.parseDeviateFromString(value);
}
@Override public DeviateStatement createDeclared(
- StmtContext<String, DeviateStatement, ?> ctx) {
+ StmtContext<Deviation.Deviate, DeviateStatement, ?> ctx) {
return new DeviateStatementImpl(ctx);
}
- @Override public EffectiveStatement<String, DeviateStatement> createEffective(
- StmtContext<String, DeviateStatement, EffectiveStatement<String, DeviateStatement>> ctx) {
+ @Override public EffectiveStatement<Deviation.Deviate, DeviateStatement> createEffective(
+ StmtContext<Deviation.Deviate, DeviateStatement, EffectiveStatement<Deviation.Deviate, DeviateStatement>> ctx) {
return new DeviateEffectiveStatementImpl(ctx);
}
+
}
@Nonnull @Override
- public String getValue() {
- return rawArgument();
+ public Deviation.Deviate getValue() {
+ return argument();
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
.declaredSubstatements();
for (StatementContextBase<?, ?, ?> originalStmtCtx : declaredSubstatements) {
if (needToCopyByUses(originalStmtCtx)) {
- StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
+ StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx, TypeOfCopy.ADDED_BY_USES);
targetCtx.addEffectiveSubstatement(copy);
} else if (isReusedByUses(originalStmtCtx)) {
targetCtx.addEffectiveSubstatement(originalStmtCtx);
.effectiveSubstatements();
for (StatementContextBase<?, ?, ?> originalStmtCtx : effectiveSubstatements) {
if (needToCopyByUses(originalStmtCtx)) {
- StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx);
+ StatementContextBase<?, ?, ?> copy = originalStmtCtx.createCopy(newQNameModule, targetCtx, TypeOfCopy.ADDED_BY_USES);
targetCtx.addEffectiveSubstatement(copy);
} else if (isReusedByUses(originalStmtCtx)) {
targetCtx.addEffectiveSubstatement(originalStmtCtx);
public static QNameModule getNewQNameModule(StatementContextBase<?, ?, ?> targetCtx,
StmtContext<?, ?, ?> stmtContext) {
if (needToCreateNewQName(stmtContext.getPublicDefinition())) {
+ if(targetCtx.isRootContext()) {
+ return targetCtx.getFromNamespace(ModuleNameToModuleQName.class, targetCtx.rawStatementArgument());
+ }
Object targetStmtArgument = targetCtx.getStatementArgument();
Object sourceStmtArgument = stmtContext.getStatementArgument();
if (targetStmtArgument instanceof QName && sourceStmtArgument instanceof QName) {
Collection<StatementContextBase<?, ?, ?>> declaredSubstatements = usesNode.declaredSubstatements();
for (StatementContextBase<?, ?, ?> subStmtCtx : declaredSubstatements) {
if (StmtContextUtils.producesDeclared(subStmtCtx, WhenStatement.class)) {
- StatementContextBase<?, ?, ?> copy = subStmtCtx.createCopy(null, targetNodeStmtCtx);
+ StatementContextBase<?, ?, ?> copy = subStmtCtx.createCopy(null, targetNodeStmtCtx, TypeOfCopy.ADDED_BY_USES);
targetNodeStmtCtx.addEffectiveSubstatement(copy);
}
if (StmtContextUtils.producesDeclared(subStmtCtx, RefineStatement.class)) {
@Override
public void prerequisiteFailed(Collection<? extends Prerequisite<?>> failed) throws InferenceException {
if (failed.contains(requiresCtxPrerequisite)) {
- throw new InferenceException("Included submodule was not found.", stmt
+ throw new InferenceException("Included submodule was not found: "+stmt.getStatementArgument(), stmt
.getStatementSourceReference());
}
}
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.SubmoduleEffectiveStatementImpl;
import com.google.common.base.Optional;
-public class SubmoduleStatementImpl extends
- AbstractRootStatement<SubmoduleStatement> implements SubmoduleStatement {
+public class SubmoduleStatementImpl extends AbstractRootStatement<SubmoduleStatement> implements SubmoduleStatement {
- protected SubmoduleStatementImpl(
- StmtContext<String, SubmoduleStatement, ?> context) {
+ protected SubmoduleStatementImpl(StmtContext<String, SubmoduleStatement, ?> context) {
super(context);
}
- public static class Definition
- extends
+ public static class Definition extends
AbstractStatementSupport<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> {
public Definition() {
}
@Override
- public SubmoduleStatement createDeclared(
- StmtContext<String, SubmoduleStatement, ?> ctx) {
+ public SubmoduleStatement createDeclared(StmtContext<String, SubmoduleStatement, ?> ctx) {
return new SubmoduleStatementImpl(ctx);
}
@Override
public EffectiveStatement<String, SubmoduleStatement> createEffective(
StmtContext<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> ctx) {
- throw new UnsupportedOperationException();
+ return new SubmoduleEffectiveStatementImpl(ctx);
}
@Override
Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> stmt)
throws SourceException {
- Optional<Date> revisionDate = Optional
- .fromNullable(firstAttributeOf(
- stmt.declaredSubstatements(),
- RevisionStatement.class));
+ Optional<Date> revisionDate = Optional.fromNullable(firstAttributeOf(stmt.declaredSubstatements(),
+ RevisionStatement.class));
- ModuleIdentifier submoduleIdentifier = new ModuleIdentifierImpl(
- stmt.getStatementArgument(), Optional.<URI> absent(),
- revisionDate);
+ ModuleIdentifier submoduleIdentifier = new ModuleIdentifierImpl(stmt.getStatementArgument(),
+ Optional.<URI> absent(), revisionDate);
stmt.addContext(SubmoduleNamespace.class, submoduleIdentifier, stmt);
- String belongsToModuleName = firstAttributeOf(
- stmt.declaredSubstatements(), BelongsToStatement.class);
- StmtContext<?, ?, ?> prefixSubStmtCtx = findFirstDeclaredSubstatement(
- stmt, 0, BelongsToStatement.class, PrefixStatement.class);
+ String belongsToModuleName = firstAttributeOf(stmt.declaredSubstatements(), BelongsToStatement.class);
+ StmtContext<?, ?, ?> prefixSubStmtCtx = findFirstDeclaredSubstatement(stmt, 0, BelongsToStatement.class,
+ PrefixStatement.class);
- if(prefixSubStmtCtx == null) {
+ if (prefixSubStmtCtx == null) {
throw new IllegalArgumentException("Prefix of belongsTo statement is missing in submodule ["
+ stmt.getStatementArgument() + "].");
}
String prefix = (String) prefixSubStmtCtx.getStatementArgument();
- stmt.addToNs(BelongsToPrefixToModuleName.class, prefix,
- belongsToModuleName);
+ stmt.addToNs(BelongsToPrefixToModuleName.class, prefix, belongsToModuleName);
}
-
}
@Override
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+import java.util.Collection;
+
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import javax.xml.xpath.XPathFactory;
import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.antlr.v4.runtime.tree.TerminalNode;
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
private static final CharMatcher DOUBLE_QUOTE_MATCHER = CharMatcher.is('"');
- private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher.is('\'');
+ private static final CharMatcher SINGLE_QUOTE_MATCHER = CharMatcher
+ .is('\'');
private static final char SEPARATOR_NODENAME = '/';
public static List<String> splitPathToNodeNames(String path) {
- Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME).omitEmptyStrings().trimResults();
+ Splitter keySplitter = Splitter.on(SEPARATOR_NODENAME)
+ .omitEmptyStrings().trimResults();
return keySplitter.splitToList(path);
}
try {
xPath.compile(path);
} catch (XPathExpressionException e) {
- throw new IllegalArgumentException("Argument is not valid XPath string", e);
+ throw new IllegalArgumentException(
+ "Argument is not valid XPath string", e);
}
}
return identifier;
}
- public static boolean isValidStatementDefinition(PrefixToModule prefixes, QNameToStatementDefinition stmtDef,
- QName identifier) {
+ public static boolean isValidStatementDefinition(PrefixToModule prefixes,
+ QNameToStatementDefinition stmtDef, QName identifier) {
if (stmtDef.get(identifier) != null) {
return true;
} else {
if (namesParts.length == 2) {
String prefix = namesParts[0];
String localName = namesParts[1];
- if (prefixes != null && prefixes.get(prefix) != null
- && stmtDef.get(new QName(YangConstants.RFC6020_YIN_NAMESPACE, localName)) != null) {
+ if (prefixes != null
+ && prefixes.get(prefix) != null
+ && stmtDef
+ .get(new QName(
+ YangConstants.RFC6020_YIN_NAMESPACE,
+ localName)) != null) {
return true;
}
}
return false;
}
- public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx, String path) {
+ public static Iterable<QName> parseXPath(StmtContext<?, ?, ?> ctx,
+ String path) {
validateXPath(path);
return qNames;
}
- public static String stringFromStringContext(final YangStatementParser.ArgumentContext context) {
+ public static String stringFromStringContext(
+ final YangStatementParser.ArgumentContext context) {
StringBuilder sb = new StringBuilder();
List<TerminalNode> strings = context.STRING();
if (strings.isEmpty()) {
case 1:
localName = namesParts[0];
- if (StmtContextUtils.producesDeclared(ctx.getRoot(), ModuleStatement.class)) {
- prefix = firstAttributeOf(ctx.getRoot().declaredSubstatements(), PrefixStatement.class);
- qNameModule = ctx.getFromNamespace(PrefixToModule.class, prefix);
-
- } else if (StmtContextUtils.producesDeclared(ctx.getRoot(), SubmoduleStatement.class)) {
- String belongsToModuleName = firstAttributeOf(ctx.getRoot().declaredSubstatements(),
- BelongsToStatement.class);
- qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName);
+ if (StmtContextUtils.producesDeclared(ctx.getRoot(),
+ ModuleStatement.class)) {
+ prefix = firstAttributeOf(
+ ctx.getRoot().declaredSubstatements(),
+ PrefixStatement.class);
+ qNameModule = ctx
+ .getFromNamespace(PrefixToModule.class, prefix);
+
+ } else if (StmtContextUtils.producesDeclared(ctx.getRoot(),
+ SubmoduleStatement.class)) {
+ String belongsToModuleName = firstAttributeOf(ctx.getRoot()
+ .declaredSubstatements(), BelongsToStatement.class);
+ qNameModule = ctx.getFromNamespace(
+ ModuleNameToModuleQName.class, belongsToModuleName);
}
break;
case 2:
prefix = namesParts[0];
localName = namesParts[1];
- ModuleIdentifier impModIdentifier = ctx.getRoot().getFromNamespace(ImpPrefixToModuleIdentifier.class,
- prefix);
- qNameModule = ctx.getFromNamespace(ModuleIdentifierToModuleQName.class, impModIdentifier);
-
- if (qNameModule == null && StmtContextUtils.producesDeclared(ctx.getRoot(), SubmoduleStatement.class)) {
- String moduleName = ctx.getRoot().getFromNamespace(BelongsToPrefixToModuleName.class, prefix);
- qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);
+ ModuleIdentifier impModIdentifier = ctx.getRoot().getFromNamespace(
+ ImpPrefixToModuleIdentifier.class, prefix);
+ qNameModule = ctx.getFromNamespace(
+ ModuleIdentifierToModuleQName.class, impModIdentifier);
+
+ if (qNameModule == null
+ && StmtContextUtils.producesDeclared(ctx.getRoot(),
+ SubmoduleStatement.class)) {
+ String moduleName = ctx.getRoot().getFromNamespace(
+ BelongsToPrefixToModuleName.class, prefix);
+ qNameModule = ctx.getFromNamespace(
+ ModuleNameToModuleQName.class, moduleName);
}
break;
}
@Nullable
- private static StatementContextBase<?, ?, ?> findCtxOfNodeInSubstatements(
- StatementContextBase<?, ?, ?> rootStmtCtx, final Iterable<QName> path, boolean searchInEffective) {
+ public static StatementContextBase<?, ?, ?> findCtxOfNodeInSubstatements(
+ StatementContextBase<?, ?, ?> rootStmtCtx,
+ final Iterable<QName> path) {
StatementContextBase<?, ?, ?> parent = rootStmtCtx;
Iterator<QName> pathIter = path.iterator();
- QName targetNode = pathIter.next();
-
while (pathIter.hasNext()) {
+ QName nextPathQName = pathIter.next();
+ StatementContextBase<?, ?, ?> foundSubstatement = getSubstatementByQName(
+ parent, nextPathQName);
- for (StatementContextBase<?, ?, ?> child : searchInEffective ? parent.effectiveSubstatements() : parent
- .declaredSubstatements()) {
-
- if (targetNode.equals(child.getStatementArgument())) {
- parent = child;
- targetNode = pathIter.next();
- }
- }
-
- if (parent.equals(rootStmtCtx)) {
-
+ if (foundSubstatement == null) {
return null;
}
- }
-
- StatementContextBase<?, ?, ?> targetCtx = null;
-
- for (StatementContextBase<?, ?, ?> child : searchInEffective ? parent.effectiveSubstatements() : parent
- .declaredSubstatements()) {
-
- if (targetNode.equals(child.getStatementArgument())) {
- targetCtx = child;
+ if (!pathIter.hasNext()) {
+ return foundSubstatement;
}
+
+ parent = foundSubstatement;
}
- return targetCtx;
+ return null;
}
- @Nullable
- public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(StatementContextBase<?, ?, ?> rootStmtCtx,
- final SchemaNodeIdentifier node) {
+ public static StatementContextBase<?, ?, ?> getSubstatementByQName(
+ StatementContextBase<?, ?, ?> parent, QName nextPathQName) {
- System.out.println(node.getPathFromRoot());
+ Collection<StatementContextBase<?, ?, ?>> declaredSubstatement = parent
+ .declaredSubstatements();
+ Collection<StatementContextBase<?, ?, ?>> effectiveSubstatement = parent
+ .effectiveSubstatements();
- StatementContextBase<?, ?, ?> targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot(),
- false);
+ Collection<StatementContextBase<?, ?, ?>> allSubstatements = new LinkedList<>();
+ allSubstatements.addAll(declaredSubstatement);
+ allSubstatements.addAll(effectiveSubstatement);
- if (targetCtx == null) {
-
- targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot(), true);
+ for (StatementContextBase<?, ?, ?> substatement : allSubstatements) {
+ if (nextPathQName.equals(substatement.getStatementArgument())) {
+ return substatement;
+ }
}
- return targetCtx;
+ return null;
}
@Nullable
- public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(StatementContextBase<?, ?, ?> rootStmtCtx,
- final Iterable<QName> path) {
-
- StatementContextBase<?, ?, ?> targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, path, false);
-
- if (targetCtx == null) {
-
- targetCtx = findCtxOfNodeInSubstatements(rootStmtCtx, path, true);
- }
-
- return targetCtx;
+ public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(
+ StatementContextBase<?, ?, ?> rootStmtCtx,
+ final SchemaNodeIdentifier node) {
+ return findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot());
}
public static SchemaPath getSchemaPath(StmtContext<?, ?, ?> ctx) {
- Iterator<Object> argumentsIterator = ctx.getArgumentsFromRoot().iterator();
+ Iterator<Object> argumentsIterator = ctx.getArgumentsFromRoot()
+ .iterator();
argumentsIterator.next(); // skip root argument
List<QName> qNamesFromRoot = new LinkedList<>();
return SchemaPath.create(qNamesFromRoot, true);
}
+
+ public static Deviation.Deviate parseDeviateFromString(final String deviate) {
+ if ("not-supported".equals(deviate)) {
+ return Deviation.Deviate.NOT_SUPPORTED;
+ } else if ("add".equals(deviate)) {
+ return Deviation.Deviate.ADD;
+ } else if ("replace".equals(deviate)) {
+ return Deviation.Deviate.REPLACE;
+ } else if ("delete".equals(deviate)) {
+ return Deviation.Deviate.DELETE;
+ } else {
+ throw new IllegalArgumentException(
+ "String %s is not valid deviate argument");
+ }
+ }
}
import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.sourceLocal;
import static org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.treeScoped;
-import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
+import java.util.Map;
-import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
+import org.opendaylight.yangtools.yang.parser.spi.ExtensionNamespace;
import org.opendaylight.yangtools.yang.parser.spi.GroupingNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
-import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
-import com.google.common.collect.ImmutableMap;
-import java.util.Map;
import org.opendaylight.yangtools.yang.parser.spi.ModuleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
+import org.opendaylight.yangtools.yang.parser.spi.SubmoduleNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
+import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleQNameToModuleName;
+import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule;
import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import com.google.common.collect.ImmutableMap;
+
public final class YangInferencePipeline {
public static final StatementSupportBundle LINKAGE_BUNDLE = StatementSupportBundle.builder()
- .addSupport(new ModuleStatementSupport())
- .addSupport(new SubmoduleStatementImpl.Definition())
- .addSupport(new NamespaceStatementImpl.Definition())
- .addSupport(new ImportStatementDefinition())
- .addSupport(new IncludeStatementImpl.Definition())
- .addSupport(new PrefixStatementImpl.Definition())
+ .addSupport(new ModuleStatementSupport()).addSupport(new SubmoduleStatementImpl.Definition())
+ .addSupport(new NamespaceStatementImpl.Definition()).addSupport(new ImportStatementDefinition())
+ .addSupport(new IncludeStatementImpl.Definition()).addSupport(new PrefixStatementImpl.Definition())
.addSupport(new YangVersionStatementImpl.Definition())
- .addSupport(new DescriptionStatementImpl.Definition())
- .addSupport(new RevisionStatementImpl.Definition())
- .addSupport(new RevisionDateStatementImpl.Definition())
- .addSupport(new ReferenceStatementImpl.Definition())
- .addSupport(new ContactStatementImpl.Definition())
- .addSupport(new OrganizationStatementImpl.Definition())
+ .addSupport(new DescriptionStatementImpl.Definition()).addSupport(new RevisionStatementImpl.Definition())
+ .addSupport(new RevisionDateStatementImpl.Definition()).addSupport(new ReferenceStatementImpl.Definition())
+ .addSupport(new ContactStatementImpl.Definition()).addSupport(new OrganizationStatementImpl.Definition())
.addSupport(new BelongsToStatementImpl.Definition())
.addSupport(global(ModuleNamespace.class))
.addSupport(global(SubmoduleNamespace.class))
.addSupport(sourceLocal(IncludedModuleContext.class))
.addSupport(sourceLocal(ImpPrefixToModuleIdentifier.class))
.addSupport(sourceLocal(BelongsToPrefixToModuleName.class))
- .addSupport(sourceLocal(QNameToStatementDefinition.class))
- .build();
+ .addSupport(sourceLocal(QNameToStatementDefinition.class)).build();
- private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle.
- derivedFrom(LINKAGE_BUNDLE)
- .addSupport(new YinElementStatementImpl.Definition())
- .addSupport(new ArgumentStatementImpl.Definition())
- .addSupport(new ExtensionStatementImpl.Definition())
- .addSupport(global(ExtensionNamespace.class))
- .build();
+ private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle.derivedFrom(LINKAGE_BUNDLE)
+ .addSupport(new YinElementStatementImpl.Definition()).addSupport(new ArgumentStatementImpl.Definition())
+ .addSupport(new ExtensionStatementImpl.Definition()).addSupport(global(ExtensionNamespace.class)).build();
- private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle.
- derivedFrom(STMT_DEF_BUNDLE)
+ private static final StatementSupportBundle FULL_DECL_BUNDLE = StatementSupportBundle
+ .derivedFrom(STMT_DEF_BUNDLE)
.addSupport(new ContainerStatementImpl.Definition())
.addSupport(new LeafStatementImpl.Definition())
.addSupport(new TypeStatementImpl.Definition())
.addSupport(new IfFeatureStatementImpl.Definition())
.addSupport(new UsesStatementImpl.Definition())
.addSupport(new GroupingStatementImpl.Definition())
- .addSupport(treeScoped(GroupingNamespace.class)) //treeScoped
- .addSupport(new StatusStatementImpl.Definition())
- .addSupport(new ErrorMessageStatementImpl.Definition())
- .addSupport(new ErrorAppTagStatementImpl.Definition())
- .addSupport(new LeafListStatementImpl.Definition())
- .addSupport(new ListStatementImpl.Definition())
- .addSupport(new PresenceStatementImpl.Definition())
- .addSupport(new KeyStatementImpl.Definition())
- .addSupport(new MaxElementsStatementImpl.Definition())
- .addSupport(new MinElementsStatementImpl.Definition())
- .addSupport(new OrderedByStatementImpl.Definition())
- .addSupport(new WhenStatementImpl.Definition())
- .addSupport(new AugmentStatementImpl.Definition())
- .addSupport(new RefineStatementImpl.Definition())
- .addSupport(new IdentityStatementImpl.Definition())
- .addSupport(new BaseStatementImpl.Definition())
- .addSupport(new FractionDigitsStatementImpl.Definition())
- .addSupport(new EnumStatementImpl.Definition())
- .addSupport(new FeatureStatementImpl.Definition())
- .addSupport(new RpcStatementImpl.Definition())
- .addSupport(new InputStatementImpl.Definition())
- .addSupport(new OutputStatementImpl.Definition())
- .addSupport(new LengthStatementImpl.Definition())
- .addSupport(new NotificationStatementImpl.Definition())
- .addSupport(new PatternStatementImpl.Definition())
- .addSupport(new PositionStatementImpl.Definition())
- .addSupport(new RangeStatementImpl.Definition())
- .addSupport(new ValueStatementImpl.Definition())
- .addSupport(new UnitsStatementImpl.Definition())
+ .addSupport(treeScoped(GroupingNamespace.class))
+ // treeScoped
+ .addSupport(new StatusStatementImpl.Definition()).addSupport(new ErrorMessageStatementImpl.Definition())
+ .addSupport(new ErrorAppTagStatementImpl.Definition()).addSupport(new LeafListStatementImpl.Definition())
+ .addSupport(new ListStatementImpl.Definition()).addSupport(new PresenceStatementImpl.Definition())
+ .addSupport(new KeyStatementImpl.Definition()).addSupport(new MaxElementsStatementImpl.Definition())
+ .addSupport(new MinElementsStatementImpl.Definition()).addSupport(new OrderedByStatementImpl.Definition())
+ .addSupport(new WhenStatementImpl.Definition()).addSupport(new AugmentStatementImpl.Definition())
+ .addSupport(new RefineStatementImpl.Definition()).addSupport(new IdentityStatementImpl.Definition())
+ .addSupport(new BaseStatementImpl.Definition()).addSupport(new FractionDigitsStatementImpl.Definition())
+ .addSupport(new EnumStatementImpl.Definition()).addSupport(new FeatureStatementImpl.Definition())
+ .addSupport(new RpcStatementImpl.Definition()).addSupport(new InputStatementImpl.Definition())
+ .addSupport(new OutputStatementImpl.Definition()).addSupport(new LengthStatementImpl.Definition())
+ .addSupport(new NotificationStatementImpl.Definition()).addSupport(new PatternStatementImpl.Definition())
+ .addSupport(new PositionStatementImpl.Definition()).addSupport(new RangeStatementImpl.Definition())
+ .addSupport(new ValueStatementImpl.Definition()).addSupport(new UnitsStatementImpl.Definition())
.addSupport(new RequireInstanceStatementImpl.Definition())
- //TODO: add mapping to Rfc6020Mapping class and uncomment following. Please test it.
-// .addSupport(new EnumSpecificationImpl.Definition())
-// .addSupport(new Decimal64SpecificationImpl.Definition())
-// .addSupport(new IdentityRefSpecificationImpl.Definition())
-// .addSupport(new InstanceIdentifierSpecificationImpl.Definition())
-// .addSupport(new LeafrefSpecificationImpl.Definition())
-// .addSupport(new NumericalRestrictionsImpl.Definition())
-// .addSupport(new StringRestrictionsImpl.Definition())
-// .addSupport(new UnionSpecificationImpl.Definition())
-// .addSupport(new BitStatementImpl.Definition())
+ // TODO: add mapping to Rfc6020Mapping class and uncomment
+ // following. Please test it.
+ // .addSupport(new EnumSpecificationImpl.Definition())
+ // .addSupport(new Decimal64SpecificationImpl.Definition())
+ // .addSupport(new IdentityRefSpecificationImpl.Definition())
+ // .addSupport(new InstanceIdentifierSpecificationImpl.Definition())
+ // .addSupport(new LeafrefSpecificationImpl.Definition())
+ // .addSupport(new NumericalRestrictionsImpl.Definition())
+ // .addSupport(new StringRestrictionsImpl.Definition())
+ // .addSupport(new UnionSpecificationImpl.Definition())
+ // .addSupport(new BitStatementImpl.Definition())
.build();
public static final Map<ModelProcessingPhase, StatementSupportBundle> RFC6020_BUNDLES = ImmutableMap
.<ModelProcessingPhase, StatementSupportBundle> builder()
.put(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
- .put(ModelProcessingPhase.STATEMENT_DEFINITION,STMT_DEF_BUNDLE)
- .put(ModelProcessingPhase.FULL_DECLARATION,FULL_DECL_BUNDLE)
- .put(ModelProcessingPhase.EFFECTIVE_MODEL,FULL_DECL_BUNDLE)
- .build();
+ .put(ModelProcessingPhase.STATEMENT_DEFINITION, STMT_DEF_BUNDLE)
+ .put(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
+ .put(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE).build();
public static final CrossSourceStatementReactor RFC6020_REACTOR = CrossSourceStatementReactor.builder()
.setBundle(ModelProcessingPhase.SOURCE_LINKAGE, LINKAGE_BUNDLE)
- .setBundle(ModelProcessingPhase.STATEMENT_DEFINITION,STMT_DEF_BUNDLE)
- .setBundle(ModelProcessingPhase.FULL_DECLARATION,FULL_DECL_BUNDLE)
- .setBundle(ModelProcessingPhase.EFFECTIVE_MODEL,FULL_DECL_BUNDLE)
- .build();
+ .setBundle(ModelProcessingPhase.STATEMENT_DEFINITION, STMT_DEF_BUNDLE)
+ .setBundle(ModelProcessingPhase.FULL_DECLARATION, FULL_DECL_BUNDLE)
+ .setBundle(ModelProcessingPhase.EFFECTIVE_MODEL, FULL_DECL_BUNDLE).build();
private YangInferencePipeline() {
throw new UnsupportedOperationException("Utility class");
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
import java.util.Collection;
import java.util.LinkedList;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
this.path = Utils.getSchemaPath(ctx);
initSubstatementCollections();
+ initCopyType(ctx);
+ }
+
+ private void initCopyType(
+ StmtContext<QName, AnyxmlStatement, EffectiveStatement<QName, AnyxmlStatement>> ctx) {
+
+ TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+ switch (typeOfCopy) {
+ case ADDED_BY_AUGMENTATION:
+ augmenting = true;
+ original = (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ case ADDED_BY_USES:
+ addedByUses = true;
+ original = (AnyXmlSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ default:
+ break;
+ }
}
private void initSubstatementCollections() {
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
-
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
// :TODO init other fields
initSubstatementCollections();
+ initCopyType(ctx);
+ }
+
+ private void initCopyType(
+ StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
+
+ TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+ switch (typeOfCopy) {
+ case ADDED_BY_AUGMENTATION:
+ augmenting = true;
+ original = (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ case ADDED_BY_USES:
+ addedByUses = true;
+ original = (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ default:
+ break;
+ }
}
private void initSubstatementCollections() {
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
-
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceStatement;
//:TODO init other fields
initSubstatementCollections();
-
+ initCopyType(ctx);
+ }
+
+ private void initCopyType(
+ StmtContext<QName, ChoiceStatement, EffectiveStatement<QName, ChoiceStatement>> ctx) {
+
+ TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+ switch (typeOfCopy) {
+ case ADDED_BY_AUGMENTATION:
+ augmenting = true;
+ original = (ChoiceSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ case ADDED_BY_USES:
+ addedByUses = true;
+ original = (ChoiceSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ default:
+ break;
+ }
}
private void initSubstatementCollections() {
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import com.google.common.collect.ImmutableSet;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
import java.util.HashSet;
public class ContainerEffectiveStatementImpl extends
AbstractEffectiveDocumentedDataNodeContainer<QName, ContainerStatement>
implements ContainerSchemaNode, DerivableSchemaNode {
+
private final QName qname;
private final SchemaPath path;
- private final boolean presence;
- boolean augmenting;
- boolean addedByUses;
- boolean configuration;
- ContainerSchemaNode original;
- ConstraintDefinition constraints;
+ private boolean presence;
+ private boolean augmenting;
+ private boolean addedByUses;
+ private boolean configuration;
+ private ContainerSchemaNode original;
+ private ConstraintDefinition constraints;
private ImmutableSet<AugmentationSchema> augmentations;
private ImmutableList<UnknownSchemaNode> unknownNodes;
qname = ctx.getStatementArgument();
path = Utils.getSchemaPath(ctx);
- presence = (firstEffective(PresenceEffectiveStatementImpl.class) == null) ? false
- : true;
+
+ initCopyType(ctx);
+ initFields();
// :TODO init other fields
+ }
- initSubstatementCollections();
+ private void initCopyType(
+ StmtContext<QName, ContainerStatement, EffectiveStatement<QName, ContainerStatement>> ctx) {
+
+ TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+ switch (typeOfCopy) {
+ case ADDED_BY_AUGMENTATION:
+ augmenting = true;
+ original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ case ADDED_BY_USES:
+ addedByUses = true;
+ original = (ContainerSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ default:
+ break;
+ }
}
- private void initSubstatementCollections() {
+ private void initFields() {
Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
Set<AugmentationSchema> augmentationsInit = new HashSet<>();
- for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
- if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
+ for (EffectiveStatement<?, ?> effectiveSubstatement : effectiveSubstatements) {
+ if (effectiveSubstatement instanceof UnknownSchemaNode) {
+ UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveSubstatement;
unknownNodesInit.add(unknownNode);
}
- if (effectiveStatement instanceof AugmentationSchema) {
- AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
+ if (effectiveSubstatement instanceof AugmentationSchema) {
+ AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveSubstatement;
augmentationsInit.add(augmentationSchema);
}
+ if (effectiveSubstatement instanceof PresenceEffectiveStatementImpl) {
+ presence = true;
+ }
+ if (effectiveSubstatement instanceof ConfigEffectiveStatementImpl) {
+ ConfigEffectiveStatementImpl config = (ConfigEffectiveStatementImpl) effectiveSubstatement;
+ this.configuration = config.argument();
+ }
}
this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviateStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
public class DeviateEffectiveStatementImpl extends
- EffectiveStatementBase<String, DeviateStatement> {
+ EffectiveStatementBase<Deviation.Deviate, DeviateStatement> {
public DeviateEffectiveStatementImpl(
- StmtContext<String, DeviateStatement, ?> ctx) {
+ StmtContext<Deviation.Deviate, DeviateStatement, ?> ctx) {
super(ctx);
}
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class DeviationEffectiveStatementImpl extends
- EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement> {
+import com.google.common.collect.ImmutableList;
+
+public class DeviationEffectiveStatementImpl extends EffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
+ implements Deviation, Immutable {
+
+ private SchemaPath targetPath;
+ private Deviate deviate;
+ private String reference;
+ private ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
- public DeviationEffectiveStatementImpl(
- StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
+ public DeviationEffectiveStatementImpl(StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
super(ctx);
+ List<UnknownSchemaNode> unknownSchemaNodesInit = new LinkedList<>();
+
+ targetPath = SchemaPath.create(ctx.getStatementArgument().getPathFromRoot(), ctx.getStatementArgument()
+ .isAbsolute());
+
+ for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
+ if (effectiveStatement instanceof DeviateEffectiveStatementImpl) {
+ deviate = ((DeviateEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
+ reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ if (effectiveStatement instanceof UnknownSchemaNode) {
+ unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
+ }
+ }
+
+ unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
+ }
+
+ @Override
+ public SchemaPath getTargetPath() {
+ return targetPath;
+ }
+
+ @Override
+ public Deviate getDeviate() {
+ return deviate;
}
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownSchemaNodes;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((targetPath == null) ? 0 : targetPath.hashCode());
+ result = prime * result + ((deviate == null) ? 0 : deviate.hashCode());
+ result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
+ if (targetPath == null) {
+ if (other.targetPath != null) {
+ return false;
+ }
+ } else if (!targetPath.equals(other.targetPath)) {
+ return false;
+ }
+ if (deviate == null) {
+ if (other.deviate != null) {
+ return false;
+ }
+ } else if (!deviate.equals(other.deviate)) {
+ return false;
+ }
+ if (reference == null) {
+ if (other.reference != null) {
+ return false;
+ }
+ } else if (!reference.equals(other.reference)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(DeviationEffectiveStatementImpl.class.getSimpleName());
+ sb.append("[");
+ sb.append("targetPath=").append(targetPath);
+ sb.append(", deviate=").append(deviate);
+ sb.append(", reference=").append(reference);
+ sb.append("]");
+ return sb.toString();
+ }
}
\ No newline at end of file
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import java.util.Date;
+
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-public class ImportEffectiveStatementImpl extends
- EffectiveStatementBase<String, ImportStatement> {
+public class ImportEffectiveStatementImpl extends EffectiveStatementBase<String, ImportStatement> implements
+ ModuleImport {
+
+ private String moduleName;
+ private Date revision;
+ private String prefix;
- public ImportEffectiveStatementImpl(
- StmtContext<String, ImportStatement, ?> ctx) {
+ public ImportEffectiveStatementImpl(StmtContext<String, ImportStatement, ?> ctx) {
super(ctx);
+
+ moduleName = ctx.getStatementArgument();
+
+ for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
+ if (effectiveStatement instanceof RevisionEffectiveStatementImpl) {
+ revision = ((RevisionEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
+ prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ }
+ }
+
+ @Override
+ public String getModuleName() {
+ return moduleName;
+ }
+
+ @Override
+ public Date getRevision() {
+ return revision;
+ }
+
+ @Override
+ public String getPrefix() {
+ return prefix;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((moduleName == null) ? 0 : moduleName.hashCode());
+ result = prime * result + ((revision == null) ? 0 : revision.hashCode());
+ result = prime * result + ((prefix == null) ? 0 : prefix.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ImportEffectiveStatementImpl other = (ImportEffectiveStatementImpl) obj;
+ if (getModuleName() == null) {
+ if (other.getModuleName() != null) {
+ return false;
+ }
+ } else if (!getModuleName().equals(other.getModuleName())) {
+ return false;
+ }
+ if (getRevision() == null) {
+ if (other.getRevision() != null) {
+ return false;
+ }
+ } else if (!getRevision().equals(other.getRevision())) {
+ return false;
+ }
+ if (getPrefix() == null) {
+ if (other.getPrefix() != null) {
+ return false;
+ }
+ } else if (!getPrefix().equals(other.getPrefix())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return ImportEffectiveStatementImpl.class.getSimpleName() + "[moduleName=" + moduleName + ", revision="
+ + revision + ", prefix=" + prefix + "]";
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
import java.util.HashSet;
import java.util.LinkedList;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.List;
// :TODO init other fields
initSubstatementCollections();
+ initCopyType(ctx);
+ }
+
+ private void initCopyType(
+ StmtContext<QName, InputStatement, EffectiveStatement<QName, InputStatement>> ctx) {
+
+ TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+ switch (typeOfCopy) {
+ case ADDED_BY_AUGMENTATION:
+ augmenting = true;
+ original = (ContainerSchemaNode) ctx.getOriginalCtx()
+ .buildEffective();
+ break;
+ case ADDED_BY_USES:
+ addedByUses = true;
+ original = (ContainerSchemaNode) ctx.getOriginalCtx()
+ .buildEffective();
+ break;
+ default:
+ break;
+ }
}
private void initSubstatementCollections() {
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
import java.util.Collection;
import java.util.LinkedList;
-
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
// :TODO init other fields
initSubstatementCollections();
+ initCopyType(ctx);
+ }
+
+ private void initCopyType(
+ StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
+
+ TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+ switch (typeOfCopy) {
+ case ADDED_BY_AUGMENTATION:
+ augmenting = true;
+ original = (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ case ADDED_BY_USES:
+ addedByUses = true;
+ original = (LeafSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ default:
+ break;
+ }
}
private void initSubstatementCollections() {
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
import java.util.Collection;
import java.util.LinkedList;
-
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-public class LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, LeafListStatement> implements LeafListSchemaNode, DerivableSchemaNode {
+public class LeafListEffectiveStatementImpl extends
+ AbstractEffectiveDocumentedNode<QName, LeafListStatement> implements
+ LeafListSchemaNode, DerivableSchemaNode {
private final QName qname;
private final SchemaPath path;
private ImmutableList<UnknownSchemaNode> unknownNodes;
- public LeafListEffectiveStatementImpl(StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
+ public LeafListEffectiveStatementImpl(
+ StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
super(ctx);
this.qname = ctx.getStatementArgument();
this.path = Utils.getSchemaPath(ctx);
- //:TODO init other fields
+ // :TODO init other fields
initSubstatementCollections();
+ initCopyType(ctx);
+ }
+
+ private void initCopyType(
+ StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
+
+ TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+ switch (typeOfCopy) {
+ case ADDED_BY_AUGMENTATION:
+ augmenting = true;
+ original = (LeafListSchemaNode) ctx.getOriginalCtx()
+ .buildEffective();
+ break;
+ case ADDED_BY_USES:
+ addedByUses = true;
+ original = (LeafListSchemaNode) ctx.getOriginalCtx()
+ .buildEffective();
+ break;
+ default:
+ break;
+ }
}
private void initSubstatementCollections() {
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(LeafListEffectiveStatementImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(
+ LeafListEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
sb.append(qname);
sb.append("]");
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
initKeyDefinition();
initSubstatementCollections();
+ initCopyType(ctx);
+ }
+
+ private void initCopyType(
+ StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
+
+ TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+ switch (typeOfCopy) {
+ case ADDED_BY_AUGMENTATION:
+ augmenting = true;
+ original = (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ case ADDED_BY_USES:
+ addedByUses = true;
+ original = (ListSchemaNode) ctx.getOriginalCtx().buildEffective();
+ break;
+ default:
+ break;
+ }
}
/**
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+import java.net.URI;
import java.util.Collection;
+import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import java.net.URI;
-import java.util.Date;
-import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
import java.util.List;
import java.util.Set;
+
+import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.Deviation;
import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.IncludedModuleContext;
-public class ModuleEffectiveStatementImpl extends
- AbstractEffectiveDocumentedDataNodeContainer<String, ModuleStatement>
+public class ModuleEffectiveStatementImpl extends AbstractEffectiveDocumentedDataNodeContainer<String, ModuleStatement>
implements Module, Immutable {
- private final QNameModule qnameModule;
+ private final QNameModule qNameModule;
private final String name;
private String sourcePath;
private String prefix;
private ImmutableList<UnknownSchemaNode> unknownNodes;
private String source;
- public ModuleEffectiveStatementImpl(
- StmtContext<String, ModuleStatement, ?> ctx) {
+ public ModuleEffectiveStatementImpl(StmtContext<String, ModuleStatement, ?> ctx) {
super(ctx);
name = argument();
- qnameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, name);
- // :TODO init other fields
+ qNameModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, name);
- initSubstatementCollections();
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
+ if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
+ prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ if (effectiveStatement instanceof YangVersionEffectiveStatementImpl) {
+ yangVersion = ((YangVersionEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ if (effectiveStatement instanceof OrganizationEffectiveStatementImpl) {
+ organization = ((OrganizationEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ if (effectiveStatement instanceof ContactEffectiveStatementImpl) {
+ contact = ((ContactEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ }
+
+ source = ctx.getStatementSource().name();
+
+ //ctx.getFromNamespace(IncludedModuleContext.class, ) //ModuleIdentifier
+ initSubstatementCollections();
}
private void initSubstatementCollections() {
List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
Set<AugmentationSchema> augmentationsInit = new HashSet<>();
+ Set<ModuleImport> importsInit = new HashSet<>();
+ Set<Module> submodulesInit = new HashSet<>();
+ Set<NotificationDefinition> notificationsInit = new HashSet<>();
+ Set<RpcDefinition> rpcsInit = new HashSet<>();
+ Set<Deviation> deviationsInit = new HashSet<>();
+ Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
+ Set<FeatureDefinition> featuresInit = new HashSet<>();
+ List<ExtensionDefinition> extensionNodesInit = new LinkedList<>();
+
+
for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
if (effectiveStatement instanceof UnknownSchemaNode) {
- UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
- unknownNodesInit.add(unknownNode);
+ unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
}
if (effectiveStatement instanceof AugmentationSchema) {
- AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
- augmentationsInit.add(augmentationSchema);
+ augmentationsInit.add((AugmentationSchema) effectiveStatement);
+ }
+ if (effectiveStatement instanceof ModuleImport) {
+ importsInit.add((ModuleImport) effectiveStatement);
+ }
+ if (effectiveStatement instanceof IncludeEffectiveStatementImpl) {
+// ((IncludeEffectiveStatementImpl) effectiveStatement).
+ }
+ if (effectiveStatement instanceof NotificationDefinition) {
+ notificationsInit.add((NotificationDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof RpcDefinition) {
+ rpcsInit.add((RpcDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof Deviation) {
+ deviationsInit.add((Deviation) effectiveStatement);
+ }
+ if (effectiveStatement instanceof IdentitySchemaNode) {
+ identitiesInit.add((IdentitySchemaNode) effectiveStatement);
+ }
+ if (effectiveStatement instanceof FeatureDefinition) {
+ featuresInit.add((FeatureDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof ExtensionDefinition) {
+ extensionNodesInit.add((ExtensionDefinition) effectiveStatement);
}
}
this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
this.augmentations = ImmutableSet.copyOf(augmentationsInit);
-
- // :TODO other substatement collections ...
+ this.imports = ImmutableSet.copyOf(importsInit);
+ this.submodules = ImmutableSet.copyOf(submodulesInit);
+ this.notifications = ImmutableSet.copyOf(notificationsInit);
+ this.rpcs = ImmutableSet.copyOf(rpcsInit);
+ this.deviations = ImmutableSet.copyOf(deviationsInit);
+ this.identities = ImmutableSet.copyOf(identitiesInit);
+ this.features = ImmutableSet.copyOf(featuresInit);
+ this.extensionNodes = ImmutableList.copyOf(extensionNodesInit);
}
@Override
@Override
public URI getNamespace() {
- return qnameModule.getNamespace();
+ return qNameModule.getNamespace();
}
@Override
@Override
public Date getRevision() {
- return qnameModule.getRevision();
+ return qNameModule.getRevision();
}
@Override
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result
- + ((yangVersion == null) ? 0 : yangVersion.hashCode());
- result = prime * result + qnameModule.hashCode();
+ result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+ result = prime * result + qNameModule.hashCode();
return result;
}
} else if (!name.equals(other.name)) {
return false;
}
- if (!qnameModule.equals(other.qnameModule)) {
+ if (!qNameModule.equals(other.qNameModule)) {
return false;
}
if (yangVersion == null) {
return true;
}
- // private static <T extends SchemaNode> Set<T> toImmutableSortedSet(final
- // Set<T> original) {
- // TreeSet<T> sorted = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
- // sorted.addAll(original);
- // return Collections.unmodifiableSet(sorted);
- // }
-
@Override
public String toString() {
StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
@Override
public QNameModule getQNameModule() {
- return qnameModule;
+ return qNameModule;
}
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+
import java.util.HashSet;
import java.util.LinkedList;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
-
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.util.List;
// :TODO init other fields
initSubstatementCollections();
+ initCopyType(ctx);
+ }
+
+ private void initCopyType(
+ StmtContext<QName, OutputStatement, EffectiveStatement<QName, OutputStatement>> ctx) {
+
+ TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
+ switch (typeOfCopy) {
+ case ADDED_BY_AUGMENTATION:
+ augmenting = true;
+ original = (ContainerSchemaNode) ctx.getOriginalCtx()
+ .buildEffective();
+ break;
+ case ADDED_BY_USES:
+ addedByUses = true;
+ original = (ContainerSchemaNode) ctx.getOriginalCtx()
+ .buildEffective();
+ break;
+ default:
+ break;
+ }
}
private void initSubstatementCollections() {
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
+import java.net.URI;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleImpl;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName;
+
+import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
+
public class SubmoduleEffectiveStatementImpl extends
- ModuleEffectiveStatementImpl {
+ AbstractEffectiveDocumentedDataNodeContainer<String, SubmoduleStatement> implements Module, Immutable {
- public SubmoduleEffectiveStatementImpl(
- StmtContext<String, ModuleStatement, ?> ctx) {
+ private final QNameModule qNameModule;
+ private final String name;
+ private String sourcePath;
+ private String prefix;
+ private String yangVersion;
+ private String organization;
+ private String contact;
+ private ImmutableSet<ModuleImport> imports;
+ private ImmutableSet<Module> submodules;
+ private ImmutableSet<FeatureDefinition> features;
+ private ImmutableSet<NotificationDefinition> notifications;
+ private ImmutableSet<AugmentationSchema> augmentations;
+ private ImmutableSet<RpcDefinition> rpcs;
+ private ImmutableSet<Deviation> deviations;
+ private ImmutableList<ExtensionDefinition> extensionNodes;
+ private ImmutableSet<IdentitySchemaNode> identities;
+ private ImmutableList<UnknownSchemaNode> unknownNodes;
+ private String source;
+
+ public SubmoduleEffectiveStatementImpl(StmtContext<String, SubmoduleStatement, ?> ctx) {
super(ctx);
+ name = argument();
+
+ String belongsToModuleName = firstAttributeOf(ctx.declaredSubstatements(), BelongsToStatement.class);
+ final QNameModule belongsToModule = ctx.getFromNamespace(ModuleNameToModuleQName.class, belongsToModuleName);
+ qNameModule = QNameModule.create(belongsToModule.getNamespace(), belongsToModule.getRevision());
+
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
+ if (effectiveStatement instanceof PrefixEffectiveStatementImpl) {
+ prefix = ((PrefixEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ if (effectiveStatement instanceof YangVersionEffectiveStatementImpl) {
+ yangVersion = ((YangVersionEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ if (effectiveStatement instanceof OrganizationEffectiveStatementImpl) {
+ organization = ((OrganizationEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ if (effectiveStatement instanceof ContactEffectiveStatementImpl) {
+ contact = ((ContactEffectiveStatementImpl) effectiveStatement).argument();
+ }
+ }
+
+ source = ctx.getStatementSource().name();
+
+ initSubstatementCollections();
}
+ private void initSubstatementCollections() {
+ Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
+
+ List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
+ Set<AugmentationSchema> augmentationsInit = new HashSet<>();
+ Set<ModuleImport> importsInit = new HashSet<>();
+ Set<Module> submodulesInit = new HashSet<>();
+ Set<NotificationDefinition> notificationsInit = new HashSet<>();
+ Set<RpcDefinition> rpcsInit = new HashSet<>();
+ Set<Deviation> deviationsInit = new HashSet<>();
+ Set<IdentitySchemaNode> identitiesInit = new HashSet<>();
+ Set<FeatureDefinition> featuresInit = new HashSet<>();
+ List<ExtensionDefinition> extensionNodesInit = new LinkedList<>();
+
+ for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
+ if (effectiveStatement instanceof UnknownSchemaNode) {
+ unknownNodesInit.add((UnknownSchemaNode) effectiveStatement);
+ }
+ if (effectiveStatement instanceof AugmentationSchema) {
+ augmentationsInit.add((AugmentationSchema) effectiveStatement);
+ }
+ if (effectiveStatement instanceof ModuleImport) {
+ importsInit.add((ModuleImport) effectiveStatement);
+ }
+ if (effectiveStatement instanceof Module) {
+ submodulesInit.add((Module) effectiveStatement);
+ }
+ if (effectiveStatement instanceof NotificationDefinition) {
+ notificationsInit.add((NotificationDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof RpcDefinition) {
+ rpcsInit.add((RpcDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof Deviation) {
+ deviationsInit.add((Deviation) effectiveStatement);
+ }
+ if (effectiveStatement instanceof IdentitySchemaNode) {
+ identitiesInit.add((IdentitySchemaNode) effectiveStatement);
+ }
+ if (effectiveStatement instanceof FeatureDefinition) {
+ featuresInit.add((FeatureDefinition) effectiveStatement);
+ }
+ if (effectiveStatement instanceof ExtensionDefinition) {
+ extensionNodesInit.add((ExtensionDefinition) effectiveStatement);
+ }
+ }
+
+ this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
+ this.augmentations = ImmutableSet.copyOf(augmentationsInit);
+ this.imports = ImmutableSet.copyOf(importsInit);
+ this.submodules = ImmutableSet.copyOf(submodulesInit);
+ this.notifications = ImmutableSet.copyOf(notificationsInit);
+ this.rpcs = ImmutableSet.copyOf(rpcsInit);
+ this.deviations = ImmutableSet.copyOf(deviationsInit);
+ this.identities = ImmutableSet.copyOf(identitiesInit);
+ this.features = ImmutableSet.copyOf(featuresInit);
+ this.extensionNodes = ImmutableList.copyOf(extensionNodesInit);
+ }
+
+ @Override
+ public String getModuleSourcePath() {
+ return sourcePath;
+ }
+
+ @Override
+ public URI getNamespace() {
+ return qNameModule.getNamespace();
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Date getRevision() {
+ return qNameModule.getRevision();
+ }
+
+ @Override
+ public String getPrefix() {
+ return prefix;
+ }
+
+ @Override
+ public String getYangVersion() {
+ return yangVersion;
+ }
+
+ @Override
+ public String getOrganization() {
+ return organization;
+ }
+
+ @Override
+ public String getContact() {
+ return contact;
+ }
+
+ @Override
+ public Set<ModuleImport> getImports() {
+ return imports;
+ }
+
+ @Override
+ public Set<Module> getSubmodules() {
+ return submodules;
+ }
+
+ @Override
+ public Set<FeatureDefinition> getFeatures() {
+ return features;
+ }
+
+ @Override
+ public Set<NotificationDefinition> getNotifications() {
+ return notifications;
+ }
+
+ @Override
+ public Set<AugmentationSchema> getAugmentations() {
+ return augmentations;
+ }
+
+ @Override
+ public Set<RpcDefinition> getRpcs() {
+ return rpcs;
+ }
+
+ @Override
+ public Set<Deviation> getDeviations() {
+ return deviations;
+ }
+
+ @Override
+ public List<ExtensionDefinition> getExtensionSchemaNodes() {
+ return extensionNodes;
+ }
+
+ @Override
+ public Set<IdentitySchemaNode> getIdentities() {
+ return identities;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ @Override
+ public String getSource() {
+ return source;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((yangVersion == null) ? 0 : yangVersion.hashCode());
+ result = prime * result + qNameModule.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ SubmoduleEffectiveStatementImpl other = (SubmoduleEffectiveStatementImpl) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (!qNameModule.equals(other.qNameModule)) {
+ return false;
+ }
+ if (yangVersion == null) {
+ if (other.yangVersion != null) {
+ return false;
+ }
+ } else if (!yangVersion.equals(other.yangVersion)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(ModuleImpl.class.getSimpleName());
+ sb.append("[");
+ sb.append("name=").append(name);
+ sb.append(", namespace=").append(getNamespace());
+ sb.append(", revision=").append(getRevision());
+ sb.append(", prefix=").append(prefix);
+ sb.append(", yangVersion=").append(yangVersion);
+ sb.append("]");
+ return sb.toString();
+ }
+
+ @Override
+ public QNameModule getQNameModule() {
+ return qNameModule;
+ }
}
reactor.addSource(source);
}
}
-
}
--- /dev/null
+package org.opendaylight.yangtools.yang.stmt.effective.build.test;
+
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.Deviation;
+import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+import java.net.URI;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class EffectiveModuleTest {
+
+ private static final YangStatementSourceImpl ROOT_MODULE = new YangStatementSourceImpl(
+ "/semantic-statement-parser/effective-module/root.yang");
+ private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl(
+ "/semantic-statement-parser/effective-module/imported.yang");
+ private static final YangStatementSourceImpl SUBMODULE = new YangStatementSourceImpl(
+ "/semantic-statement-parser/effective-module/submod.yang");
+
+ private static final QNameModule ROOT_MODULE_QNAME = QNameModule.create(URI.create("root-ns"), null);
+
+ private static final QName cont = QName.create(ROOT_MODULE_QNAME, "cont");
+
+ private static final SchemaPath contSchemaPath = SchemaPath.create(true, cont);
+
+ private static Date revision;
+
+ @BeforeClass
+ public static void init() {
+ try {
+ revision = SimpleDateFormatUtil.getRevisionFormat()
+ .parse("2000-01-01");
+ } catch (ParseException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ @Test
+ public void effectiveBuildTest() throws SourceException, ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ addSources(reactor, ROOT_MODULE, IMPORTED_MODULE, SUBMODULE);
+ EffectiveSchemaContext result = reactor.buildEffective();
+
+ assertNotNull(result);
+
+ Module rootModule = result.findModuleByName("root", null);
+ assertNotNull(rootModule);
+
+ assertEquals("root-pref", rootModule.getPrefix());
+ assertEquals("1", rootModule.getYangVersion());
+ assertEquals("kisko", rootModule.getOrganization());
+ assertEquals("kisko email", rootModule.getContact());
+
+ final Set<AugmentationSchema> augmentations = rootModule.getAugmentations();
+ assertEquals(1, augmentations.size());
+ assertEquals(contSchemaPath, augmentations.iterator().next().getTargetPath());
+
+ final Set<ModuleImport> imports = rootModule.getImports();
+ assertEquals(1, imports.size());
+ final ModuleImport importStmt = imports.iterator().next();
+ assertNotNull(importStmt);
+ assertEquals("imported", importStmt.getModuleName());
+ assertEquals(revision, importStmt.getRevision());
+ assertEquals("imp-pref", importStmt.getPrefix());
+
+ final Set<Module> submodules = rootModule.getSubmodules();
+ //assertEquals(1, submodules.size());
+ //assertEquals("submod", submodules.iterator().next().getName());
+
+ final Set<NotificationDefinition> notifications = rootModule.getNotifications();
+ assertEquals(1, notifications.size());
+ assertEquals("notif1", notifications.iterator().next().getQName().getLocalName());
+
+ final Set<RpcDefinition> rpcs = rootModule.getRpcs();
+ assertEquals(1, rpcs.size());
+ assertEquals("rpc1", rpcs.iterator().next().getQName().getLocalName());
+
+ final Set<Deviation> deviations = rootModule.getDeviations();
+ assertEquals(1, deviations.size());
+ final Deviation deviationStmt = deviations.iterator().next();
+ assertNotNull(deviationStmt);
+ assertEquals(contSchemaPath, deviationStmt.getTargetPath());
+ assertEquals(Deviation.Deviate.ADD, deviationStmt.getDeviate());
+ assertEquals("deviate reference", deviationStmt.getReference());
+
+ final Set<IdentitySchemaNode> identities = rootModule.getIdentities();
+ assertEquals(1, identities.size());
+ assertEquals("identity1", identities.iterator().next().getQName().getLocalName());
+
+// final Set<FeatureDefinition> features = rootModule.getFeatures();
+// assertEquals(1, features.size());
+// assertEquals("feature1", features.iterator().next().getQName().getLocalName());
+
+ final List<ExtensionDefinition> extensionSchemaNodes = rootModule.getExtensionSchemaNodes();
+ assertEquals(1, extensionSchemaNodes.size());
+ assertEquals("ext1", extensionSchemaNodes.iterator().next().getQName().getLocalName());
+ }
+
+ private void addSources(CrossSourceStatementReactor.BuildAction reactor, YangStatementSourceImpl... sources) {
+ for (YangStatementSourceImpl source : sources) {
+ reactor.addSource(source);
+ }
+ }
+}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-
+import static org.junit.Assert.assertNull;
import java.net.URI;
-
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
-
import com.google.common.collect.ImmutableList;
public class AugmentProcessTest {
private static final YangStatementSourceImpl AUGMENTED = new YangStatementSourceImpl(
- "/stmt-test/effective-build/augmented.yang");
+ "/stmt-test/augments/augmented.yang");
private static final YangStatementSourceImpl ROOT = new YangStatementSourceImpl(
- "/stmt-test/effective-build/aug-root.yang");
+ "/stmt-test/augments/aug-root.yang");
- private static final QNameModule ROOT_QNAME_MODULE = QNameModule.create(URI.create("root"), null);
- private static final QNameModule AUGMENTED_QNAME_MODULE = QNameModule.create(URI.create("aug"), null);
+ private static final QNameModule ROOT_QNAME_MODULE = QNameModule.create(
+ URI.create("root"), null);
+ private static final QNameModule AUGMENTED_QNAME_MODULE = QNameModule
+ .create(URI.create("aug"), null);
private static GroupingDefinition grp2Def;
- private final QName augParent1 = QName.create(AUGMENTED_QNAME_MODULE, "aug-parent1");
- private final QName augParent2 = QName.create(AUGMENTED_QNAME_MODULE, "aug-parent2");
- private final QName contTarget = QName.create(AUGMENTED_QNAME_MODULE, "cont-target");
+ private final QName augParent1 = QName.create(AUGMENTED_QNAME_MODULE,
+ "aug-parent1");
+ private final QName augParent2 = QName.create(AUGMENTED_QNAME_MODULE,
+ "aug-parent2");
+ private final QName contTarget = QName.create(AUGMENTED_QNAME_MODULE,
+ "cont-target");
- private final QName contAdded1 = QName.create(AUGMENTED_QNAME_MODULE, "cont-added1");
- private final QName contAdded2 = QName.create(AUGMENTED_QNAME_MODULE, "cont-added2");
+ private final QName contAdded1 = QName.create(AUGMENTED_QNAME_MODULE,
+ "cont-added1");
+ private final QName contAdded2 = QName.create(AUGMENTED_QNAME_MODULE,
+ "cont-added2");
private final QName list1 = QName.create(AUGMENTED_QNAME_MODULE, "list1");
private final QName axml = QName.create(AUGMENTED_QNAME_MODULE, "axml");
- private final QName contGrp = QName.create(AUGMENTED_QNAME_MODULE, "cont-grp");
- private final QName axmlGrp = QName.create(AUGMENTED_QNAME_MODULE, "axml-grp");
+ private final QName contGrp = QName.create(AUGMENTED_QNAME_MODULE,
+ "cont-grp");
+ private final QName axmlGrp = QName.create(AUGMENTED_QNAME_MODULE,
+ "axml-grp");
private final QName augCont1 = QName.create(ROOT_QNAME_MODULE, "aug-cont1");
private final QName augCont2 = QName.create(ROOT_QNAME_MODULE, "aug-cont2");
private final QName grpCont2 = QName.create(ROOT_QNAME_MODULE, "grp-cont2");
- private final QName grpCont22 = QName.create(ROOT_QNAME_MODULE, "grp-cont22");
+ private final QName grpCont22 = QName.create(ROOT_QNAME_MODULE,
+ "grp-cont22");
private final QName grpAdd = QName.create(ROOT_QNAME_MODULE, "grp-add");
+ private static final YangStatementSourceImpl MULTIPLE_AUGMENT = new YangStatementSourceImpl(
+ "/stmt-test/augments/multiple-augment-test.yang");
+
+ private static final YangStatementSourceImpl MULTIPLE_AUGMENT_ROOT = new YangStatementSourceImpl(
+ "/stmt-test/augments/multiple-augment-root.yang");
+ private static final YangStatementSourceImpl MULTIPLE_AUGMENT_IMPORTED = new YangStatementSourceImpl(
+ "/stmt-test/augments/multiple-augment-imported.yang");
+ private static final YangStatementSourceImpl MULTIPLE_AUGMENT_SUBMODULE = new YangStatementSourceImpl(
+ "/stmt-test/augments/multiple-augment-submodule.yang");
+
+ private static final YangStatementSourceImpl MULTIPLE_AUGMENT_INCORRECT = new YangStatementSourceImpl(
+ "/stmt-test/augments/multiple-augment-incorrect.yang");
+
+ private static final YangStatementSourceImpl MULTIPLE_AUGMENT_INCORRECT2 = new YangStatementSourceImpl(
+ "/stmt-test/augments/multiple-augment-incorrect2.yang");
+
+ @Test
+ public void multipleAugmentsAndMultipleModulesTest() throws SourceException,
+ ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
+ addSources(reactor, MULTIPLE_AUGMENT_ROOT, MULTIPLE_AUGMENT_IMPORTED, MULTIPLE_AUGMENT_SUBMODULE);
+
+ EffectiveSchemaContext result = null;
+ try {
+ result = reactor.buildEffective();
+ } catch (Exception e) {
+ log(e, "");
+ }
+ assertNotNull(result);
+ }
+
+ @Test
+ public void multipleAugmentTest() throws SourceException, ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
+ addSources(reactor, MULTIPLE_AUGMENT);
+
+ EffectiveSchemaContext result = null;
+ try {
+ result = reactor.buildEffective();
+ } catch (Exception e) {
+ log(e, "");
+ }
+ assertNotNull(result);
+ }
+
+ @Test
+ public void multipleAugmentIncorrectPathTest() throws SourceException,
+ ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
+ addSources(reactor, MULTIPLE_AUGMENT_INCORRECT);
+
+ EffectiveSchemaContext result = null;
+ try {
+ result = reactor.buildEffective();
+ } catch (Exception e) {
+ log(e, "");
+ }
+
+ assertNull(result);
+ }
+
+ @Test
+ public void multipleAugmentIncorrectPathAndGrpTest() throws SourceException,
+ ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
+ addSources(reactor, MULTIPLE_AUGMENT_INCORRECT2);
+
+ EffectiveSchemaContext result = null;
+ try {
+ result = reactor.buildEffective();
+ } catch (Exception e) {
+ log(e, "");
+ }
+
+ assertNull(result);
+ }
+
+ private void log(Throwable e, String indent) {
+ System.out.println(indent + e.getMessage());
+
+ Throwable[] suppressed = e.getSuppressed();
+ for (Throwable throwable : suppressed) {
+ log(throwable, indent + " ");
+ }
+ }
+
@Test
- public void readAndParseYangFileTest() throws SourceException, ReactorException {
+ public void readAndParseYangFileTest() throws SourceException,
+ ReactorException {
- CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
+ .newBuild();
addSources(reactor, AUGMENTED, ROOT);
final EffectiveSchemaContext root = reactor.buildEffective();
Module augmentedModule = root.findModuleByName("augmented", null);
assertNotNull(augmentedModule);
- ContainerSchemaNode augParent1Node = (ContainerSchemaNode) root.getDataChildByName(augParent1);
- ContainerSchemaNode augParent2Node = (ContainerSchemaNode) augParent1Node.getDataChildByName(augParent2);
- ContainerSchemaNode targetContNode = (ContainerSchemaNode) augParent2Node.getDataChildByName(contTarget);
+ ContainerSchemaNode augParent1Node = (ContainerSchemaNode) root
+ .getDataChildByName(augParent1);
+ ContainerSchemaNode augParent2Node = (ContainerSchemaNode) augParent1Node
+ .getDataChildByName(augParent2);
+ ContainerSchemaNode targetContNode = (ContainerSchemaNode) augParent2Node
+ .getDataChildByName(contTarget);
assertNotNull(targetContNode);
assertNotNull(targetContNode.getChildNodes());
assertEquals(3, targetContNode.getChildNodes().size());
- ContainerSchemaNode contAdded1Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded1);
+ ContainerSchemaNode contAdded1Node = (ContainerSchemaNode) targetContNode
+ .getDataChildByName(contAdded1);
assertNotNull(contAdded1Node);
- ListSchemaNode list1Node = (ListSchemaNode) contAdded1Node.getDataChildByName(list1);
+ ListSchemaNode list1Node = (ListSchemaNode) contAdded1Node
+ .getDataChildByName(list1);
assertNotNull(list1Node);
- ContainerSchemaNode contAdded2Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded2);
+ ContainerSchemaNode contAdded2Node = (ContainerSchemaNode) targetContNode
+ .getDataChildByName(contAdded2);
assertNotNull(contAdded2Node);
- AnyXmlSchemaNode axmlNode = (AnyXmlSchemaNode) contAdded2Node.getDataChildByName(axml);
+ AnyXmlSchemaNode axmlNode = (AnyXmlSchemaNode) contAdded2Node
+ .getDataChildByName(axml);
assertNotNull(axmlNode);
- ContainerSchemaNode contGrpNode = (ContainerSchemaNode) targetContNode.getDataChildByName(contGrp);
+ ContainerSchemaNode contGrpNode = (ContainerSchemaNode) targetContNode
+ .getDataChildByName(contGrp);
assertNotNull(contGrpNode);
- AnyXmlSchemaNode axmlGrpNode = (AnyXmlSchemaNode) contGrpNode.getDataChildByName(axmlGrp);
+ AnyXmlSchemaNode axmlGrpNode = (AnyXmlSchemaNode) contGrpNode
+ .getDataChildByName(axmlGrp);
assertNotNull(axmlGrpNode);
- ContainerSchemaNode augCont1Node = (ContainerSchemaNode) root.getDataChildByName(augCont1);
- ContainerSchemaNode augCont2Node = (ContainerSchemaNode) augCont1Node.getDataChildByName(augCont2);
+ ContainerSchemaNode augCont1Node = (ContainerSchemaNode) root
+ .getDataChildByName(augCont1);
+ ContainerSchemaNode augCont2Node = (ContainerSchemaNode) augCont1Node
+ .getDataChildByName(augCont2);
assertNotNull(augCont2Node);
- ContainerSchemaNode grpCont2Node = (ContainerSchemaNode) augCont2Node.getDataChildByName(grpCont2);
- ContainerSchemaNode grpCont22Node = (ContainerSchemaNode) grpCont2Node.getDataChildByName(grpCont22);
+ ContainerSchemaNode grpCont2Node = (ContainerSchemaNode) augCont2Node
+ .getDataChildByName(grpCont2);
+ ContainerSchemaNode grpCont22Node = (ContainerSchemaNode) grpCont2Node
+ .getDataChildByName(grpCont22);
assertNotNull(grpCont22Node);
- ContainerSchemaNode grpAddNode = (ContainerSchemaNode) grpCont22Node.getDataChildByName(grpAdd);
+ ContainerSchemaNode grpAddNode = (ContainerSchemaNode) grpCont22Node
+ .getDataChildByName(grpAdd);
assertNotNull(grpAddNode);
}
- private <T extends ModelStatement> T findInStatements(QName target, ImmutableList<T> statements) {
+ private <T extends ModelStatement> T findInStatements(QName target,
+ ImmutableList<T> statements) {
for (final T statement : statements) {
- if (target.equals(statement.statementDefinition().getArgumentName())) {
+ if (target
+ .equals(statement.statementDefinition().getArgumentName())) {
return statement;
}
}
return null;
}
- private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
+ private void addSources(CrossSourceStatementReactor.BuildAction reactor,
+ StatementStreamSource... sources) {
for (StatementStreamSource source : sources) {
reactor.addSource(source);
}
import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
-
import static org.junit.Assert.assertNotNull;
public class YangFileStmtTest {
private static final YangStatementSourceImpl EXTFILE = new YangStatementSourceImpl("/semantic-statement-parser/ext-typedef.yang");
private static final YangStatementSourceImpl EXTUSE = new YangStatementSourceImpl("/semantic-statement-parser/ext-use.yang");
+
+ private static final YangStatementSourceImpl BAR = new YangStatementSourceImpl("/model-new/bar.yang");
+ private static final YangStatementSourceImpl BAZ = new YangStatementSourceImpl("/model-new/baz.yang");
+ private static final YangStatementSourceImpl FOO = new YangStatementSourceImpl("/model-new/foo.yang");
+ private static final YangStatementSourceImpl SUBFOO = new YangStatementSourceImpl("/model-new/subfoo.yang");
+
+ @Test
+ public void readAndParseYangFileTestModel() throws SourceException, ReactorException {
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+
+ addSources(reactor, BAZ,FOO,BAR,SUBFOO);
+ EffectiveModelContext result = reactor.build();
+ assertNotNull(result);
+ }
+
@Test
public void readAndParseYangFileTest() throws SourceException, ReactorException {
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
--- /dev/null
+module bar {
+ yang-version 1;
+ namespace "urn:opendaylight.bar";
+ prefix "bar";
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org/";
+ description "This model define custom type definitions";
+
+ revision "2013-07-03" {
+ reference " WILL BE DEFINED LATER";
+ }
+
+ typedef int32-ext1 {
+ type int32 {
+ range "2..20";
+ }
+ }
+
+ typedef int32-ext2 {
+ type int32-ext1 {
+ range "3..9|11..max";
+ }
+ units "mile";
+ default "11";
+ }
+
+ typedef string-ext1 {
+ type string {
+ pattern "[a-k]*";
+ length "5..11";
+ }
+ }
+
+ typedef string-ext2 {
+ type string-ext1 {
+ length "6..10";
+ }
+ }
+
+ typedef string-ext3 {
+ type string-ext2 {
+ pattern "[b-u]*";
+ }
+ }
+
+ typedef string-ext4 {
+ type string-ext3 {
+ pattern "[e-z]*";
+ }
+ }
+
+ typedef invalid-string-pattern {
+ type string {
+ pattern "[[A-1*-%22!^^}";
+ }
+ }
+
+ typedef multiple-pattern-string {
+ type string {
+ pattern "[[A-1*-%22!^^}";
+ pattern "[e-z]*";
+ }
+ }
+
+ typedef my-decimal-type {
+ type decimal64 {
+ fraction-digits 6;
+ }
+ }
+
+ typedef my-union {
+ type union {
+ type int16 {
+ range "1..100";
+ }
+ type int32;
+ }
+ }
+
+ typedef my-union-ext {
+ type my-union;
+ }
+
+ typedef nested-union2 {
+ type union {
+ type my-union-ext;
+ type string;
+ }
+ }
+
+ container interfaces {
+ grouping ifEntry {
+ container augment-holder;
+ }
+ list ifEntry {
+ key "ifIndex";
+
+ leaf ifIndex {
+ type uint32;
+ units minutes;
+ }
+
+ leaf ifMtu {
+ type int32;
+ }
+
+ min-elements 1;
+ max-elements 11;
+ }
+ }
+
+ extension opendaylight {
+ argument "name" {
+ yin-element "true";
+ }
+ }
+}
--- /dev/null
+module baz {
+ yang-version 1;
+ namespace "urn:opendaylight.baz";
+ prefix "baz";
+
+ import bar { prefix "br"; revision-date 2013-07-03; }
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org/";
+
+ revision "2013-02-27" {
+ reference " WILL BE DEFINED LATER";
+ }
+
+ typedef union1 {
+ type union2;
+ }
+
+ typedef union2 {
+ type union {
+ type int32;
+ type br:nested-union2;
+ }
+ }
+
+ augment "/br:interfaces/br:ifEntry" {
+ when "if:ifType='ds0'";
+ container augment-holder {
+ description "Description for augment holder";
+ }
+ }
+
+ augment "/br:interfaces/br:ifEntry" {
+ when "if:ifType='ds2'";
+ container augment-holder2 {
+ description "Description for augment holder";
+ }
+ }
+
+ container network {
+ c-define point {
+ }
+
+ description "network-description";
+ reference "network-reference";
+ status obsolete;
+ config true;
+ presence "some presence text";
+ }
+
+ feature local-storage {
+ description
+ "This feature means the device supports local storage (memory,
+ flash or disk) that can be used to store syslog messages.";
+ }
+
+ extension c-define {
+ description "Takes as argument a name string. Makes the code generator use
+ the given name in the #define.";
+ argument "name" {
+ yin-element "true";
+ }
+ }
+
+ notification event {
+ leaf event-class {
+ type string;
+ }
+ anyxml reporting-entity;
+ leaf severity {
+ type string;
+ }
+ }
+
+ rpc get-config {
+ description "Retrieve all or part of a specified configuration.";
+ reference "RFC 6241, Section 7.1";
+
+ input {
+ container source {
+ description
+ "Particular configuration to retrieve.";
+
+ choice config-source {
+ mandatory true;
+ description
+ "The configuration to retrieve.";
+ case a {
+ leaf candidate {
+ if-feature candidate;
+ type empty;
+ description
+ "The candidate configuration is the config source.";
+ }
+ }
+ case b {
+ leaf running {
+ type empty;
+ description
+ "The running configuration is the config source.";
+ }
+ }
+ case c {
+ leaf startup {
+ if-feature startup;
+ type empty;
+ description
+ "The startup configuration is the config source. This is optional-to-implement
+ on the server because not all servers will support filtering for
+ this datastore.";
+ }
+ }
+ }
+ }
+
+ anyxml filter {
+ description "Subtree or XPath filter to use.";
+ baz:c-define element-attributes;
+ }
+ }
+
+ output {
+ anyxml data {
+ description
+ "Copy of the source datastore subset that matched the filter criteria
+ (if any). An empty data container indicates that the request did
+ not produce any results.";
+ }
+ }
+ }
+
+ grouping target {
+ anyxml data {
+ config true;
+ description "Copy of the source datastore subset.";
+ mandatory false;
+ must "test-condition-text";
+ reference "test-no-reference";
+ status "obsolete";
+ when "test-when-text";
+ }
+ choice how {
+ description "test choice description";
+ default interval;
+ case interval {
+ leaf interval {
+ type uint16;
+ default 30;
+ units minutes;
+ }
+ }
+ case daily {
+ leaf daily {
+ type empty;
+ }
+ leaf time-of-day {
+ type string;
+ units 24-hour-clock;
+ default 1am;
+ }
+ }
+ }
+ leaf address {
+ type string;
+ description "Target IP address";
+ mandatory true;
+ }
+ container port {
+ description "Target port container";
+ }
+ list addresses {
+ key "id";
+ leaf id {
+ type int8;
+ }
+ }
+ grouping target-inner {
+ description "target-inner default description";
+ leaf inner-grouping-id {
+ type int8;
+ }
+ }
+ typedef group-type {
+ type br:my-decimal-type;
+ }
+
+ br:opendaylight;
+ }
+}
--- /dev/null
+module foo {
+ yang-version 1;
+ namespace "urn:opendaylight.foo";
+ prefix "foo";
+
+ import bar { prefix "br"; revision-date 2013-07-03; }
+
+ import baz { prefix "bz"; revision-date 2013-02-27; }
+
+ include subfoo {
+ revision-date "2013-02-27";
+ }
+
+ organization "opendaylight";
+ contact "http://www.opendaylight.org/";
+
+ revision "2013-02-27" {
+ reference " WILL BE DEFINED LATER";
+ }
+
+ typedef identifier {
+ type int32;
+ }
+
+ leaf int32-leaf {
+ type br:int32-ext2 {
+ range "12..max";
+ }
+ }
+
+ leaf string-leaf {
+ type br:string-ext4;
+ }
+
+ leaf invalid-pattern-string-leaf {
+ type br:invalid-string-pattern;
+ }
+
+ leaf invalid-direct-string-pattern-def-leaf {
+ type string {
+ pattern "[[A-1*-%22!^^}";
+ }
+ }
+
+ leaf multiple-pattern-string-leaf {
+ type br:multiple-pattern-string;
+ }
+
+ leaf multiple-pattern-direct-string-def-leaf {
+ type string {
+ pattern "[e-z]*";
+ pattern "[[A-1*-%22!^^}";
+ pattern "[a-d]*";
+ }
+ }
+
+ leaf length-leaf {
+ type br:string-ext2 {
+ length "7..max";
+ }
+ }
+
+ leaf decimal-leaf {
+ type br:my-decimal-type {
+ fraction-digits 4;
+ }
+ }
+
+ leaf decimal-leaf2 {
+ type br:my-decimal-type;
+ }
+
+ container ext {
+ bz:c-define "MY_INTERFACES";
+ }
+
+ leaf union-leaf {
+ type br:my-union-ext;
+ }
+
+ deviation /br:interfaces/br:ifEntry {
+ deviate add {
+ default "admin";
+ config "true";
+ }
+ reference "system/user ref";
+ }
+
+ leaf custom-union-leaf {
+ type bz:union1;
+ }
+
+ container transfer {
+ choice how {
+ default interval;
+ container input {
+ }
+ list output {
+ leaf id {
+ type string;
+ }
+ }
+ case interval {
+ leaf interval {
+ type uint16;
+ default 30;
+ units minutes;
+ }
+ }
+ case daily {
+ leaf daily {
+ type empty;
+ }
+ leaf time-of-day {
+ type string;
+ units 24-hour-clock;
+ default 1am;
+ }
+ }
+ case manual {
+ leaf manual {
+ type empty;
+ }
+ }
+ }
+ }
+
+ anyxml datas {
+ description
+ "Copy of the source typesstore subset that matched the filter
+ criteria (if any). An empty types container indicates that the
+ request did not produce any results.";
+ status obsolete;
+ }
+
+ augment "/br:interfaces/br:ifEntry/br:augment-holder" {
+ when "if:ifType='ds0'";
+ leaf ds0ChannelNumber {
+ type string;
+ }
+ leaf interface-id {
+ type leafref {
+ path "/if:interfaces/if:interface/if:name";
+ }
+ }
+ leaf my-type {
+ type br:int32-ext2;
+ }
+ container schemas {
+ }
+ choice odl {
+ leaf id {
+ type int8;
+ }
+ case node1 {
+ description "node1";
+ }
+ case node2 {
+ description "node2";
+ }
+ container node3 {
+ description "node3";
+ }
+ }
+ }
+
+ container mycont {
+ container innercont {
+ typedef mytype {
+ type string;
+ }
+ leaf myleaf {
+ type mytype;
+ }
+ }
+ }
+
+ uses bz:target {
+ augment "how/interval" {
+ description "inner augment";
+ leaf name {
+ type string;
+ }
+ }
+ }
+
+ container peer {
+ container destination {
+ uses bz:target {
+ refine address {
+ default "1.2.3.4";
+ description "IP address of target node";
+ reference "address reference added by refine";
+ config false;
+ mandatory false;
+ must "ifType != 'ethernet' or " +
+ "(ifType = 'ethernet' and ifMTU = 1500)" {
+ error-message "An ethernet MTU must be 1500";
+ }
+ mountpoint "mnt-extension";
+ }
+ refine port {
+ description "description of port defined by refine";
+ reference "port reference added by refine";
+ config false;
+ presence "presence is required";
+ }
+ refine "addresses" {
+ description "description of addresses defined by refine";
+ reference "addresses reference added by refine";
+ config false;
+ min-elements 2;
+ max-elements unbounded;
+ }
+ refine addresses/id {
+ description "id of address";
+ }
+ }
+ }
+ }
+
+ extension mountpoint {
+ description "enter point";
+ argument "name" {
+ yin-element "true";
+ }
+ }
+}
--- /dev/null
+submodule subfoo {
+ yang-version 1;
+
+ belongs-to foo {
+ prefix f;
+ }
+
+ import bar {
+ prefix "br";
+ revision-date 2013-07-03;
+ }
+
+ import baz {
+ prefix "bz";
+ revision-date 2013-02-27;
+ }
+
+ revision "2013-02-27" {
+ }
+
+ leaf id {
+ type br:int32-ext2 {
+ range "12..max";
+ }
+ }
+
+ leaf foo-id {
+ type f:identifier;
+ }
+
+ container sub-ext {
+ bz:c-define "MY_INTERFACES";
+ }
+
+ container sub-transfer {
+ choice how {
+ default interval;
+ container input {
+ }
+ list output {
+ leaf id {
+ type string;
+ }
+ }
+ case manual {
+ leaf manual {
+ type empty;
+ }
+ }
+ }
+ }
+
+ anyxml sub-datas {
+ status obsolete;
+ }
+
+ augment "/br:interfaces/br:ifEntry/br:augment-holder" {
+ when "if:ifType='ds0'";
+ leaf subleaf {
+ type string;
+ }
+ }
+
+ extension sub-mountpoint {
+ argument "name" {
+ yin-element "true";
+ }
+ }
+
+}
--- /dev/null
+module imported {
+ namespace imported;
+ prefix imported;
+
+ revision "2000-01-01";
+}
\ No newline at end of file
--- /dev/null
+module root {
+ namespace root-ns;
+ prefix root-pref;
+
+ yang-version 1;
+ organization "kisko";
+ contact "kisko email";
+
+ import imported {
+ prefix imp-pref;
+ revision "2000-01-01";
+ }
+ include submod;
+
+ container cont {
+ }
+
+ augment "/cont" {
+ container cont-aug {
+ }
+ }
+
+ notification notif1 {
+ }
+
+ rpc rpc1 {
+ }
+
+ deviation /cont {
+ deviate add {
+ container subcont{
+ }
+ }
+ reference "deviate reference";
+ }
+
+ identity identity1 {
+ }
+
+ feature feature1 {
+ }
+
+ extension ext1 {
+ }
+}
\ No newline at end of file
--- /dev/null
+submodule submod {
+ belongs-to "root" {
+ prefix root;
+ }
+ revision "2000-01-01";
+}
\ No newline at end of file
--- /dev/null
+module aug-root {
+ namespace root;
+ prefix root;
+
+ import augmented { prefix aug; }
+
+ augment "/aug:aug-parent1/aug:aug-parent2/aug:cont-target" {
+ container cont-added1 {
+ list list1 {
+ }
+ }
+
+ container cont-added2 {
+ anyxml axml;
+ }
+
+ uses aug:grp;
+ }
+
+ grouping grp2 {
+ container grp-cont2 {
+ container grp-cont22 {
+ }
+ }
+ }
+
+ container aug-cont1 {
+ container aug-cont2 {
+ uses grp2 {
+ augment "grp-cont2/grp-cont22" {
+ container grp-add {
+ }
+ }
+ }
+ }
+ }
+}
--- /dev/null
+module augmented {
+ namespace aug;
+ prefix aug;
+
+ container aug-parent1 {
+ container aug-parent2 {
+ container cont-target {
+ }
+ }
+ }
+
+ grouping grp {
+ container cont-grp {
+ anyxml axml-grp;
+ }
+ }
+}
--- /dev/null
+module multiple-augment-imported {
+
+ namespace "multiple-augment-imported";
+ prefix imp;
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2/sub-container-from-augment3 {
+ container sub-container-from-augment4 {
+ }
+ }
+
+ container root-container {
+ uses grp1 {
+ augment container-from-grp1/sub-container-from-grp1 {
+ container container-in-uses-augment {
+ }
+ }
+ }
+ }
+
+ grouping grp1 {
+ container container-from-grp1 {
+ container sub-container-from-grp1 {
+ uses grp2 {
+ augment container-from-grp2/sub-container-from-grp2 {
+ container augmented-container-in-uses-grp2;
+ }
+ }
+ }
+ }
+ }
+
+ augment /root-container/added-container-1 {
+ container added-container-2 {
+ }
+ }
+
+ grouping grp2 {
+ container container-from-grp2 {
+ container sub-container-from-grp2 {
+ }
+ }
+ uses grp3;
+ }
+
+ grouping grp3 {
+ container container-from-grp3 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment {
+ container sub-container-from-augment2 {
+ }
+ }
+
+ grouping grp-from-import {
+ container container-from-grp-from-import {
+
+ }
+ }
+}
--- /dev/null
+module multiple-augment-incorrect {
+
+ namespace "multiple-augment-test";
+ prefix mpa;
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2/sub-container-from-augment3 {
+ container sub-container-from-augment4 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2 {
+ container sub-container-from-augment3 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1 {
+ container sub-container-from-augment {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/augmented-container-in-uses-grp2 {
+ container sub-container-from-augment6 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/sub-container-from-augment5 {
+ container sub-container-from-augment7 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2 {
+ container sub-container-from-augment5 {
+ }
+ }
+
+ augment /root-container/added-container-1 {
+ container added-container-2 {
+ }
+ }
+
+ augment /root-container {
+ container added-container-1 {
+ }
+ }
+
+ grouping grp1 {
+ container container-from-grp1 {
+ container sub-container-from-grp1 {
+ uses grp2 {
+ augment container-from-grp2/sub-container-from-grp2 {
+ container augmented-container-in-uses-grp2;
+ }
+ }
+ }
+ }
+ }
+
+ grouping grp2 {
+ container container-from-grp2 {
+ container sub-container-from-grp2 {
+ }
+ }
+ uses grp3;
+ }
+
+ grouping grp3 {
+ container container-from-grp3 {
+
+ }
+ }
+
+ container root-container {
+ uses grp1 {
+ augment container-from-grp1/sub-container-from-grp1 {
+ container container-in-uses-augment {
+ }
+ }
+ }
+ }
+}
--- /dev/null
+module multiple-augment-incorrect2 {
+
+ namespace "multiple-augment-test";
+ prefix mpa;
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2/sub-container-from-augment3 {
+ container sub-container-from-augment4 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2 {
+ container sub-container-from-augment3 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1 {
+ container sub-container-from-augment {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/augmented-container-in-uses-grp2 {
+ container sub-container-from-augment6 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/sub-container-from-augment5 {
+ container sub-container-from-augment7 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2 {
+ container sub-container-from-augment5 {
+ }
+ }
+
+ augment /root-container/added-container-1 {
+ container added-container-2 {
+ }
+ }
+
+ augment /root-container {
+ container added-container-1 {
+ }
+ }
+
+ grouping grp1 {
+ container container-from-grp1 {
+ container sub-container-from-grp1 {
+ uses grp2 {
+ augment container-from-grp2/sub-container-from-grp2 {
+ container augmented-container-in-uses-grp2;
+ }
+ }
+ }
+ }
+ }
+
+ grouping grp2 {
+ container container-from-grp2 {
+ container sub-container-from-grp2 {
+ }
+ }
+ uses grp3;
+ }
+
+ grouping grp3 {
+ container container-from-grp3 {
+ }
+ }
+
+ container root-container {
+ uses grp1 {
+ augment container-from-grp1/sub-container-from-grp1 {
+ container container-in-uses-augment {
+ }
+ }
+ }
+ }
+
+ container container-with-incorrect-uses {
+ uses grp4 {
+ augment unknown {
+ container new {
+
+ }
+ }
+ }
+ }
+}
--- /dev/null
+module multiple-augment-root {
+
+ namespace "multiple-augment-root";
+ prefix root;
+
+ import multiple-augment-imported { prefix imp; revision-date 1970-01-01; }
+
+ include multiple-augment-submodule { revision-date 1970-01-01; }
+
+ augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-in-uses-augment/imp:sub-container-from-augment2 {
+ container sub-container-from-augment3 {
+ }
+ }
+
+ augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1 {
+ container sub-container-from-augment {
+ }
+ }
+
+ augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-from-grp2/imp:sub-container-from-grp2/imp:augmented-container-in-uses-grp2 {
+ container sub-container-from-augment6 {
+ }
+ }
+
+ augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-from-grp2/imp:sub-container-from-grp2/imp:sub-container-from-augment5 {
+ container sub-container-from-augment7 {
+ }
+ }
+
+ augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-from-grp2/imp:sub-container-from-grp2 {
+ container sub-container-from-augment5 {
+ }
+ }
+
+ augment /imp:root-container {
+ container added-container-1 {
+ }
+ }
+
+ container container-with-multiple-uses {
+ uses imp:grp-from-import{
+ augment container-from-grp-from-import {
+ container new {
+ }
+ }
+ }
+ uses grp-from-include{
+ augment container-from-grp-from-include {
+ container new {
+ }
+ }
+ }
+ }
+}
--- /dev/null
+submodule multiple-augment-submodule {
+
+ belongs-to multiple-augment-root {
+ prefix rt;
+ }
+
+ grouping grp-from-include{
+ container container-from-grp-from-include {
+ }
+ }
+}
--- /dev/null
+module multiple-augment-test {
+
+ namespace "multiple-augment-test";
+ prefix mpa;
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2/sub-container-from-augment3 {
+ container sub-container-from-augment4 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2 {
+ container sub-container-from-augment3 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment {
+ container sub-container-from-augment2 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1 {
+ container sub-container-from-augment {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/augmented-container-in-uses-grp2 {
+ container sub-container-from-augment6 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2/sub-container-from-augment5 {
+ container sub-container-from-augment7 {
+ }
+ }
+
+ augment /root-container/container-from-grp1/sub-container-from-grp1/container-from-grp2/sub-container-from-grp2 {
+ container sub-container-from-augment5 {
+ }
+ }
+
+ augment /root-container/added-container-1 {
+ container added-container-2 {
+ }
+ }
+
+ augment /root-container {
+ container added-container-1 {
+ }
+ }
+
+ grouping grp1 {
+ container container-from-grp1 {
+ container sub-container-from-grp1 {
+ uses grp2 {
+ augment container-from-grp2/sub-container-from-grp2 {
+ container augmented-container-in-uses-grp2;
+ }
+ }
+ }
+ }
+ }
+
+ grouping grp2 {
+ container container-from-grp2 {
+ container sub-container-from-grp2 {
+ }
+ }
+ uses grp3;
+ }
+
+ grouping grp3 {
+ container container-from-grp3 {
+
+ }
+ }
+
+ container root-container {
+ uses grp1 {
+ augment container-from-grp1/sub-container-from-grp1 {
+ container container-in-uses-augment {
+ }
+ }
+ }
+ }
+}
+++ /dev/null
-module aug-root {
- namespace root;
- prefix root;
-
- import augmented {
- prefix aug;
- }
-
- augment "/aug:aug-parent1/aug:aug-parent2/aug:cont-target" {
- container cont-added1 {
- list list1 {
- }
- }
-
- container cont-added2 {
- anyxml axml;
- }
-
- uses aug:grp;
- }
-
- grouping grp2 {
- container grp-cont2 {
- container grp-cont22 {
- }
- }
- }
-
- container aug-cont1 {
- container aug-cont2 {
- uses grp2 {
- augment "grp-cont2/grp-cont22" {
- container grp-add {
- }
- }
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-module augmented {
- namespace aug;
- prefix aug;
-
- container aug-parent1 {
- container aug-parent2 {
- container cont-target {
-
- }
- }
- }
-
- grouping grp {
- container cont-grp {
- anyxml axml-grp;
- }
- }
-}
\ No newline at end of file