<artifactId>ietf-topology-l3-unicast</artifactId>
<version>${ietf.topology.version}</version>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-composite-node</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>restconf-client-api</artifactId>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-data-api</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-composite-node</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-data-impl</artifactId>
<bundle>mvn:org.opendaylight.yangtools.thirdparty/antlr4-runtime-osgi-nohead/{{VERSION}}</bundle>
<bundle>mvn:commons-io/commons-io/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.yangtools/yang-data-api/{{VERSION}}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-data-composite-node/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.yangtools/yang-data-impl/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.yangtools/yang-data-operations/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.yangtools/yang-data-util/{{VERSION}}</bundle>
<module>yang-parser-api</module>
<module>yang-parser-impl</module>
<module>yang-model-export</module>
- <module>yang-data-composite-node</module>
</modules>
<build>
<plugins>
package org.opendaylight.yangtools.yang.data.api;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.common.QName;
/**
- *
- * Container of attributes, which may be attached to {@link Node}
- *
+ *
+ * Container of attributes, which may be attached to nodes.
+ *
*/
public interface AttributesContainer {
/**
* Returns immutable map of QName and value of the attribute.
- *
+ *
* @return immutable map of attribute names and values.
*/
Map<QName, String> getAttributes();
/**
* Returns attribute value by supplied QName
- *
- *
+ *
+ *
* @param name Attribute name
* @return Value of attribute if present, null otherwise.
*/
+++ /dev/null
-/*
- * Copyright (c) 2013 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.api;
-
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
-
-/**
- * Composite node represents a branch in the data tree, which could contain
- * nested composite nodes or leaf nodes. In the terms of the XML the simple node
- * is element which does not text data directly (CDATA or PCDATA), only other
- * nodes. The composite node is the manifestation of the following data schema
- * constructs in the YANG:
- *
- * <ul>
- * <li><b>container</b> - the composite node represents the YANG container and
- * could contain all children schema nodes of that container</li>
- * <li><b>item</b> in the <b>list</b> - the composite node represents one item
- * in the YANG list and could contain all children schema nodes of that list
- * item.</li>
- * <li><b>anyxml</b></li>
- * </ul>
- *
- * @deprecated Use {@link NormalizedNodeContainer} instead.
- */
-@Deprecated
-public interface CompositeNode extends Node<List<Node<?>>>, NodeModification, Map<QName,List<Node<?>>> {
-
- /**
- * Returns a list of children as seens in resulting XML serialization
- * defined by YANG specification.
- *
- * @return
- *
- * @deprecated Use {@link #getValue()} instead.
- */
- @Deprecated
- List<Node<?>> getChildren();
-
- List<CompositeNode> getCompositesByName(QName children);
-
- List<CompositeNode> getCompositesByName(String children);
-
- List<SimpleNode<?>> getSimpleNodesByName(QName children);
-
- List<SimpleNode<?>> getSimpleNodesByName(String children);
-
- CompositeNode getFirstCompositeByName(QName container);
-
- SimpleNode<?> getFirstSimpleByName(QName leaf);
-
- /**
- * @return cast self to mutable, if possible
- */
- @Deprecated
- MutableCompositeNode asMutable();
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.api;
-
-import java.util.List;
-
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
-
-
-/**
- * @author michal.rehak
- *
- * @deprecated Deprecated in favor of {@link NormalizedNodeContainer} classes.
- */
-@Deprecated
-public interface MutableCompositeNode extends MutableNode<List<Node<?>>>, CompositeNode {
-
- /**
- * update internal map
- */
- @Deprecated
- void init();
-
- /**
- * @return original node, if available
- */
- CompositeNode getOriginal();
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.api;
-
-import org.opendaylight.yangtools.concepts.Mutable;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-
-/**
- * Base representation of node in the data tree, defines basic parameters of
- * node such as a QName.
- *
- *
- * @param <T>
- *
- * @deprecated Use {@link NormalizedNode} instead.
- */
-@Deprecated
-public interface MutableNode<T> extends Node<T>,Mutable {
-
- /**
- * @param parent value to set
- */
- void setParent(CompositeNode parent);
-
- /**
- * @param value value to set (children list or leaf value)
- */
- @Override
- T setValue(T value);
-
- /**
- * @param action value to set
- */
- void setModifyAction(ModifyAction action);
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.api;
-
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-
-/**
- * @author michal.rehak
- * @param <T> node value type
- *
- * @deprecated Use {@link NormalizedNode} instead.
- */
-@Deprecated
-public interface MutableSimpleNode<T> extends MutableNode<T>, SimpleNode<T> {
-
- /**
- * @return original node, if available
- */
- SimpleNode<T> getOriginal();
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.api;
-
-import java.util.Map.Entry;
-
-import org.opendaylight.yangtools.yang.common.QName;
-
-/**
- * Base representation of node in the data tree, defines basic parameters of
- * node such as a QName.
- *
- *
- * @param <T>
- */
-public interface Node<T> extends Entry<QName, T> {
-
- /**
- * Returns the name of the Node
- *
- * @return qName of node
- */
- QName getNodeType();
-
- /**
- * Returns parent node
- *
- * @return parent node
- * @deprecated Unused, Deprecated because reference to parent disallows of sharing one instance
- * in multiple trees / subtress.
- */
- @Deprecated
- CompositeNode getParent();
-
- /**
- * Returns the value that holds current node, if no value is defined method
- * can return <code>null</code>
- *
- * @return Returns the value that holds current node.
- */
- @Override
- T getValue();
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.api;
-
-
-/**
- * @author michal.rehak
- *
- * @deprecated Use {@link org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes} instead.
- */
-@Deprecated
-public interface NodeModificationBuilder {
-
- Node<?> getMutableEquivalent(Node<?> originalNode);
-
- CompositeNode buildDiffTree();
-
- void mergeNode(MutableCompositeNode alteredNode);
-
- void removeNode(MutableCompositeNode deadNode);
-
- void removeNode(MutableSimpleNode<?> deadNode);
-
- void deleteNode(MutableSimpleNode<?> deadNode);
-
- void deleteNode(MutableCompositeNode deadNode);
-
- void replaceNode(MutableCompositeNode replacementNode);
-
- void replaceNode(MutableSimpleNode<?> replacementNode);
-
- void addNode(MutableCompositeNode newNode);
-
- void addNode(MutableSimpleNode<?> newNode);
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.api;
-
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * Simple node represents a leaf in the data tree, which does not contain any
- * nested nodes, but the value of node. In the terms of the XML the simple node
- * is element which contains only text data (CDATA or PCDATA). The simple node
- * is the manifestation of the following data schema constructs in YANG:
- * <ul>
- * <li><b>leaf</b> - simple node could represent YANG leafs of all types except
- * the empty type, which in XML form is similar to the empty container.</li>
- * <li><b>item</b> in <b>leaf-list</b></li>
- * </ul>
- *
- *
- * @param <T>
- *
- * @deprecated Use {@link NormalizedNode} instead.
- */
-@Deprecated
-public interface SimpleNode<T> extends Node<T>, NodeModification {
-
- /**
- * @return cast self to mutable, if possible
- */
- MutableSimpleNode<T> asMutable();
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.api.codec;
-
-import org.opendaylight.yangtools.concepts.Codec;
-import org.opendaylight.yangtools.yang.data.api.Node;
-
-public interface DataNodeCodec<I> extends Codec<I, Node<?>> {
- @Override
- Node<?> deserialize(I input);
-
- @Override
- I serialize(Node<?> input);
-}
import java.util.HashMap;
import java.util.Map;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
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.ImmutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
return lflst11.build();
}
- private static CompositeNode prepareLf12Value() {
- SimpleNode<?> anyxmlInData = NodeFactory.createImmutableSimpleNode(
- QName.create("ns:complex:json", "2014-08-11", "anyxml-in-data"), null, "foo");
- return ImmutableCompositeNode.builder().add(anyxmlInData)
- .setQName(QName.create("ns:complex:json", "2014-08-11", "lf12-any")).build();
- }
-
- private static CompositeNode prepareLf13Value() {
- SimpleNode<?> anyxmlInData = NodeFactory.createImmutableSimpleNode(
- QName.create("ns:complex:json", "2014-08-11", "anyxml-in-data"), null, "foo");
- return ImmutableCompositeNode.builder().add(anyxmlInData)
- .setQName(QName.create("ns:complex:json", "2014-08-11", "lf13-any")).build();
- }
-
public static NormalizedNode<?, ?> leafNodeInContainer() {
LeafNode<Object> lf11 = Builders.leafBuilder()
.withNodeIdentifier(new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lf11")))
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!-- Copyright (c) 2013 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 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <parent>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yangtools-parent</artifactId>
- <version>0.7.0-SNAPSHOT</version>
- <relativePath>/../../common/parent/pom.xml</relativePath>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>yang-data-composite-node</artifactId>
- <name>${project.artifactId}</name>
- <description>${project.artifactId}</description>
- <packaging>bundle</packaging>
-
- <dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>yang-data-api</artifactId>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>yang-data-impl</artifactId>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>yang-model-api</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>yang-parser-impl</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-Name>Composite node Normalized node transformator</Bundle-Name>
- <Import-Package>*</Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
-</project>
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import javax.xml.transform.dom.DOMSource;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.AnyXmlNodeBaseParser;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
-
-public class AnyXmlNodeCnSnParser extends AnyXmlNodeBaseParser<Node<?>> {
-
- public AnyXmlNodeCnSnParser() {
- super();
- }
-
- @Override
- protected DOMSource parseAnyXml(Node<?> element, AnyXmlSchemaNode schema) {
- // This will be removed
- return null;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.composite.node.schema.json.CnSnToNormalizedNodesUtils;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
-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 com.google.common.base.Preconditions;
-import com.google.common.collect.LinkedListMultimap;
-
-public final class AugmentationNodeCnSnParser extends AugmentationNodeBaseParser<Node<?>> {
-
- private final NodeParserDispatcher<Node<?>> dispatcher;
-
- public AugmentationNodeCnSnParser(final NodeParserDispatcher<Node<?>> dispatcher) {
- this.dispatcher = Preconditions.checkNotNull(dispatcher);
- }
-
- @Override
- protected LinkedListMultimap<QName, Node<?>> mapChildElements(Iterable<Node<?>> elements) {
- return CnSnToNormalizedNodesUtils.mapChildElements(elements);
- }
-
- @Override
- protected NodeParserDispatcher<Node<?>> getDispatcher() {
- return dispatcher;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.composite.node.schema.json.CnSnToNormalizedNodesUtils;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
-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 com.google.common.base.Preconditions;
-import com.google.common.collect.LinkedListMultimap;
-
-public final class ChoiceNodeCnSnParser extends ChoiceNodeBaseParser<Node<?>> {
-
- private final NodeParserDispatcher<Node<?>> dispatcher;
-
- public ChoiceNodeCnSnParser(final NodeParserDispatcher<Node<?>> dispatcher) {
- this.dispatcher = Preconditions.checkNotNull(dispatcher);
- }
-
- @Override
- protected LinkedListMultimap<QName, Node<?>> mapChildElements(Iterable<Node<?>> elements) {
- return CnSnToNormalizedNodesUtils.mapChildElements(elements);
- }
-
- @Override
- protected NodeParserDispatcher<Node<?>> getDispatcher() {
- return dispatcher;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-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.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
-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.ToNormalizedNodeParserFactory;
-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.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-public class CnSnToNormalizedNodeParserFactory implements ToNormalizedNodeParserFactory<Node<?>> {
-
- private final ContainerNodeCnSnParser containerNodeCnSnParser;
- private final LeafNodeCnSnParser leafNodeCnSnParser;
- private final LeafSetEntryNodeCnSnParser leafSetEntryNodeCnSnParser;
- private final LeafSetNodeCnSnParser leafSetNodeCnSnParser;
- private final MapNodeCnSnParser mapNodeCnSnParser;
- private final MapEntryNodeCnSnParser mapEntryNodeCnSnParser;
- private final UnkeyedListNodeCnSnParser unkeyedListNodeCnSnParser;
- private final UnkeyedListEntryNodeCnSnParser unkeyedListEntryNodeCnSnParser;
- private final ChoiceNodeCnSnParser choiceNodeCnSnParser;
- private final AugmentationNodeCnSnParser augmentationNodeCnSnParser;
- private final AnyXmlNodeCnSnParser anyXmlNodeCnSnParser;
- private final OrderedListNodeCnSnParser orderedListNodeCnSnParser;
-
- private CnSnToNormalizedNodeParserFactory() {
- leafNodeCnSnParser = new LeafNodeCnSnParser();
- leafSetEntryNodeCnSnParser = new LeafSetEntryNodeCnSnParser();
- leafSetNodeCnSnParser = new LeafSetNodeCnSnParser(leafSetEntryNodeCnSnParser);
- anyXmlNodeCnSnParser = new AnyXmlNodeCnSnParser();
-
- final NodeParserDispatcher<Node<?>> dispatcher = new NodeParserDispatcher.BaseNodeParserDispatcher<Node<?>>(
- this) {
-
- };
-
- containerNodeCnSnParser = new ContainerNodeCnSnParser(dispatcher);
- mapEntryNodeCnSnParser = new MapEntryNodeCnSnParser(dispatcher);
- mapNodeCnSnParser = new MapNodeCnSnParser(mapEntryNodeCnSnParser);
- orderedListNodeCnSnParser = new OrderedListNodeCnSnParser(mapEntryNodeCnSnParser);
- unkeyedListEntryNodeCnSnParser = new UnkeyedListEntryNodeCnSnParser(dispatcher);
- unkeyedListNodeCnSnParser = new UnkeyedListNodeCnSnParser(unkeyedListEntryNodeCnSnParser);
- choiceNodeCnSnParser = new ChoiceNodeCnSnParser(dispatcher);
- augmentationNodeCnSnParser = new AugmentationNodeCnSnParser(dispatcher);
-
- }
-
- public static CnSnToNormalizedNodeParserFactory getInstance() {
- return new CnSnToNormalizedNodeParserFactory();
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, ContainerNode, ContainerSchemaNode> getContainerNodeParser() {
- return containerNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, LeafNode<?>, LeafSchemaNode> getLeafNodeParser() {
- return leafNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, LeafSetNode<?>, LeafListSchemaNode> getLeafSetNodeParser() {
- return leafSetNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, MapNode, ListSchemaNode> getMapNodeParser() {
- return mapNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, ChoiceNode, ChoiceSchemaNode> getChoiceNodeParser() {
- return choiceNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, AugmentationNode, AugmentationSchema> getAugmentationNodeParser() {
- return augmentationNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, LeafSetEntryNode<?>, LeafListSchemaNode> getLeafSetEntryNodeParser() {
- return leafSetEntryNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, MapEntryNode, ListSchemaNode> getMapEntryNodeParser() {
- return mapEntryNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, AnyXmlNode, AnyXmlSchemaNode> getAnyXmlNodeParser() {
- return anyXmlNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, UnkeyedListNode, ListSchemaNode> getUnkeyedListNodeParser() {
- return unkeyedListNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, UnkeyedListEntryNode, ListSchemaNode> getUnkeyedListEntryNodeParser() {
- return unkeyedListEntryNodeCnSnParser;
- }
-
- @Override
- public ToNormalizedNodeParser<Node<?>, OrderedMapNode, ListSchemaNode> getOrderedListNodeParser() {
- return orderedListNodeCnSnParser;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.composite.node.schema.json.CnSnToNormalizedNodesUtils;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
-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 com.google.common.base.Preconditions;
-import com.google.common.collect.LinkedListMultimap;
-
-public final class ContainerNodeCnSnParser extends ContainerNodeBaseParser<Node<?>> {
-
- private final NodeParserDispatcher<Node<?>> dispatcher;
-
- public ContainerNodeCnSnParser(final NodeParserDispatcher<Node<?>> dispatcher) {
- this.dispatcher = Preconditions.checkNotNull(dispatcher);
- }
-
- @Override
- protected NodeParserDispatcher<Node<?>> getDispatcher() {
- return dispatcher;
- }
-
- @Override
- protected LinkedListMultimap<QName, Node<?>> mapChildElements(Iterable<Node<?>> elements) {
- return CnSnToNormalizedNodesUtils.mapChildElementsForSingletonNode(elements.iterator().next());
- }
-
- @Override
- protected Map<QName, String> getAttributes(Node<?> e) {
- return Collections.emptyMap();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.LeafNodeBaseParser;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-
-public class LeafNodeCnSnParser extends LeafNodeBaseParser<Node<?>> {
-
- public LeafNodeCnSnParser() {
- super();
- }
-
- @Override
- protected Object parseLeaf(Node<?> elements, LeafSchemaNode schema) {
- return elements.getValue();
- }
-
- @Override
- protected Map<QName, String> getAttributes(Node<?> e) {
- return Collections.emptyMap();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.LeafSetEntryNodeBaseParser;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-
-public class LeafSetEntryNodeCnSnParser extends LeafSetEntryNodeBaseParser<Node<?>> {
-
- public LeafSetEntryNodeCnSnParser() {
- super();
- }
-
- @Override
- protected Object parseLeafListEntry(Node<?> elements, LeafListSchemaNode schema) {
- return elements.getValue();
- }
-
- @Override
- protected Map<QName, String> getAttributes(Node<?> e) {
- return Collections.emptyMap();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.LeafSetNodeBaseParser;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-
-public class LeafSetNodeCnSnParser extends LeafSetNodeBaseParser<Node<?>> {
-
- private final LeafSetEntryNodeCnSnParser leafSetEntryNodeCnSnParser;
-
- public LeafSetNodeCnSnParser(LeafSetEntryNodeCnSnParser leafSetEntryNodeCnSnParser) {
- this.leafSetEntryNodeCnSnParser = leafSetEntryNodeCnSnParser;
- }
-
- @Override
- protected ToNormalizedNodeParser<Node<?>, LeafSetEntryNode<?>, LeafListSchemaNode> getLeafSetEntryNodeParser() {
- return leafSetEntryNodeCnSnParser;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.LinkedListMultimap;
-import java.util.Collections;
-import java.util.Map;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
-import org.opendaylight.yangtools.yang.data.composite.node.schema.json.CnSnToNormalizedNodesUtils;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.ListEntryNodeBaseParser;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.NodeParserDispatcher;
-
-abstract class ListEntryNodeCnSnParser<N extends DataContainerNode<?>> extends ListEntryNodeBaseParser<Node<?>, N> {
-
- private final NodeParserDispatcher<Node<?>> dispatcher;
-
- ListEntryNodeCnSnParser(final NodeParserDispatcher<Node<?>> dispatcher) {
- this.dispatcher = Preconditions.checkNotNull(dispatcher);
- }
-
- @Override
- protected LinkedListMultimap<QName, Node<?>> mapChildElements(Iterable<Node<?>> elements) {
- return CnSnToNormalizedNodesUtils.mapChildElementsForSingletonNode(elements.iterator().next());
- }
-
- @Override
- protected NodeParserDispatcher<Node<?>> getDispatcher() {
- return dispatcher;
- }
-
- @Override
- protected Map<QName, String> getAttributes(Node<?> e) {
- return Collections.emptyMap();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.NodeParserDispatcher;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-public final class MapEntryNodeCnSnParser extends ListEntryNodeCnSnParser<MapEntryNode> {
-
- public MapEntryNodeCnSnParser(final NodeParserDispatcher<Node<?>> dispatcher) {
- super(dispatcher);
- }
-
- @Override
- protected final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> getBuilder(
- ListSchemaNode schema) {
- return Builders.mapEntryBuilder(schema);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-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;
-
-public final class MapNodeCnSnParser extends MapNodeBaseParser<Node<?>> {
-
- private final MapEntryNodeCnSnParser mapEntryNodeCnSnParser;
-
- public MapNodeCnSnParser(MapEntryNodeCnSnParser mapEntryNodeCnSnParser) {
- this.mapEntryNodeCnSnParser = mapEntryNodeCnSnParser;
- }
-
- @Override
- protected ToNormalizedNodeParser<Node<?>, MapEntryNode, ListSchemaNode> getListEntryNodeParser() {
- return mapEntryNodeCnSnParser;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-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;
-
-public final class OrderedListNodeCnSnParser extends OrderedListNodeBaseParser<Node<?>> {
-
- private final MapEntryNodeCnSnParser mapEntryNodeCnSnParser;
-
- public OrderedListNodeCnSnParser(MapEntryNodeCnSnParser mapEntryNodeCnSnParser) {
- this.mapEntryNodeCnSnParser = mapEntryNodeCnSnParser;
- }
-
- @Override
- protected ToNormalizedNodeParser<Node<?>, MapEntryNode, ListSchemaNode> getListEntryNodeParser() {
- return mapEntryNodeCnSnParser;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-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.UnkeyedListEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser.NodeParserDispatcher;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-final class UnkeyedListEntryNodeCnSnParser extends ListEntryNodeCnSnParser<UnkeyedListEntryNode> {
-
- UnkeyedListEntryNodeCnSnParser(final NodeParserDispatcher<Node<?>> dispatcher) {
- super(dispatcher);
- }
-
- @Override
- protected final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> getBuilder(
- ListSchemaNode schema) {
- return Builders.unkeyedListEntryBuilder().withNodeIdentifier(new NodeIdentifier(schema.getQName()));
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.parser;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
-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;
-
-final class UnkeyedListNodeCnSnParser extends UnkeyedListNodeBaseParser<Node<?>> {
-
- private final UnkeyedListEntryNodeCnSnParser unkeyedListEntryNodeParser;
-
- UnkeyedListNodeCnSnParser(UnkeyedListEntryNodeCnSnParser unkeyedListEntryNodeParser) {
- this.unkeyedListEntryNodeParser = unkeyedListEntryNodeParser;
- }
-
- @Override
- protected ToNormalizedNodeParser<Node<?>, UnkeyedListEntryNode, ListSchemaNode> getListEntryNodeParser() {
- return unkeyedListEntryNodeParser;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.AnyXmlNodeBaseSerializer;
-
-public class AnyXmlNodeCnSnSerializer extends AnyXmlNodeBaseSerializer<Node<?>> {
-
- @Override
- protected Node<?> serializeAnyXml(AnyXmlNode node) {
- // This should be removed along with composite nodes
- return null;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.AugmentationNodeBaseSerializer;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.NodeSerializerDispatcher;
-
-import com.google.common.base.Preconditions;
-
-public class AugmentationNodeCnSnSerializer extends AugmentationNodeBaseSerializer<Node<?>> {
-
- private NodeSerializerDispatcher<Node<?>> dispatcher;
-
- AugmentationNodeCnSnSerializer(final NodeSerializerDispatcher<Node<?>> dispatcher) {
- this.dispatcher = Preconditions.checkNotNull(dispatcher);
- }
-
- @Override
- protected NodeSerializerDispatcher<Node<?>> getNodeDispatcher() {
- return dispatcher;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.ChoiceNodeBaseSerializer;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.NodeSerializerDispatcher;
-
-import com.google.common.base.Preconditions;
-
-public class ChoiceNodeCnSnSerializer
- extends
- ChoiceNodeBaseSerializer<Node<?>> {
-
- private final NodeSerializerDispatcher<Node<?>> dispatcher;
-
- ChoiceNodeCnSnSerializer(final NodeSerializerDispatcher<Node<?>> dispatcher) {
- this.dispatcher = Preconditions.checkNotNull(dispatcher);
- }
-
- @Override
- protected NodeSerializerDispatcher<Node<?>> getNodeDispatcher() {
- return dispatcher;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-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.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.FromNormalizedNodeSerializer;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.FromNormalizedNodeSerializerFactory;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.NodeSerializerDispatcher;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-public final class CnSnFromNormalizedNodeSerializerFactory implements FromNormalizedNodeSerializerFactory<Node<?>> {
- private final ContainerNodeCnSnSerializer containerSerializer;
- private final ChoiceNodeCnSnSerializer choiceSerializer;
- private final AugmentationNodeCnSnSerializer augmentSerializer;
- private final LeafNodeCnSnSerializer leafNodeSerializer;
- private final LeafSetNodeCnSnSerializer leafSetSerializer;
- private final MapNodeCnSnSerializer mapNodeSerializer;
- private final LeafSetEntryNodeCnSnSerializer leafSetEntryNodeSerializer;
- private final MapEntryNodeCnSnSerializer mapEntryNodeSerializer;
- private final AnyXmlNodeCnSnSerializer anyXmlNodeSerializer;
- private final UnkeyedListNodeCnSnSerializer unkeyedListNodeSerializer;
- private final UnkeyedListEntryNodeCnSnSerializer unkeyedListEntryNodeSerializer;
-
- private CnSnFromNormalizedNodeSerializerFactory() {
- final NodeSerializerDispatcher.BaseNodeSerializerDispatcher<Node<?>> dispatcher = new NodeSerializerDispatcher.BaseNodeSerializerDispatcher<Node<?>>(
- this) {
-
- };
-
- containerSerializer = new ContainerNodeCnSnSerializer(dispatcher);
- choiceSerializer = new ChoiceNodeCnSnSerializer(dispatcher);
- augmentSerializer = new AugmentationNodeCnSnSerializer(dispatcher);
- leafNodeSerializer = new LeafNodeCnSnSerializer();
- anyXmlNodeSerializer = new AnyXmlNodeCnSnSerializer();
-
- leafSetEntryNodeSerializer = new LeafSetEntryNodeCnSnSerializer();
- leafSetSerializer = new LeafSetNodeCnSnSerializer(leafSetEntryNodeSerializer);
-
- mapEntryNodeSerializer = new MapEntryNodeCnSnSerializer(dispatcher);
- mapNodeSerializer = new MapNodeCnSnSerializer(mapEntryNodeSerializer);
-
- unkeyedListEntryNodeSerializer = new UnkeyedListEntryNodeCnSnSerializer(dispatcher);
- unkeyedListNodeSerializer = new UnkeyedListNodeCnSnSerializer(unkeyedListEntryNodeSerializer);
- }
-
-
- public static CnSnFromNormalizedNodeSerializerFactory getInstance() {
- return new CnSnFromNormalizedNodeSerializerFactory();
-}
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, ContainerNode, ContainerSchemaNode> getContainerNodeSerializer() {
- return containerSerializer;
- }
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, LeafNode<?>, LeafSchemaNode> getLeafNodeSerializer() {
- return leafNodeSerializer;
- }
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, LeafSetNode<?>, LeafListSchemaNode> getLeafSetNodeSerializer() {
- return leafSetSerializer;
- }
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, MapNode, ListSchemaNode> getMapNodeSerializer() {
- return mapNodeSerializer;
- }
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, ChoiceNode, ChoiceSchemaNode> getChoiceNodeSerializer() {
- return choiceSerializer;
- }
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, AugmentationNode, AugmentationSchema> getAugmentationNodeSerializer() {
- return augmentSerializer;
- }
-
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, LeafSetEntryNode<?>, LeafListSchemaNode> getLeafSetEntryNodeSerializer() {
- return leafSetEntryNodeSerializer;
- }
-
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, MapEntryNode, ListSchemaNode> getMapEntryNodeSerializer() {
- return mapEntryNodeSerializer;
- }
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, AnyXmlNode, AnyXmlSchemaNode> getAnyXmlNodeSerializer() {
- return anyXmlNodeSerializer;
- }
-
- @Override
- public FromNormalizedNodeSerializer<Node<?>, UnkeyedListNode, ListSchemaNode> getUnkeyedListNodeSerializer() {
- return unkeyedListNodeSerializer;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import com.google.common.base.Preconditions;
-import java.util.Collections;
-import java.util.List;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.ContainerNodeBaseSerializer;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.NodeSerializerDispatcher;
-import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-
-public class ContainerNodeCnSnSerializer extends ContainerNodeBaseSerializer<Node<?>> {
-
- private final NodeSerializerDispatcher<Node<?>> dispatcher;
-
- ContainerNodeCnSnSerializer(final NodeSerializerDispatcher<Node<?>> dispatcher) {
- this.dispatcher = Preconditions.checkNotNull(dispatcher);
- }
-
- @Override
- public List<Node<?>> serialize(final ContainerSchemaNode schema, final ContainerNode node) {
- CompositeNodeBuilder<ImmutableCompositeNode> compNodeBuilder = ImmutableCompositeNode.builder();
- compNodeBuilder.setQName(node.getNodeType());
- compNodeBuilder.addAll(super.serialize(schema, node));
- return Collections.<Node<?>> singletonList(compNodeBuilder.build());
- }
-
- @Override
- protected NodeSerializerDispatcher<Node<?>> getNodeDispatcher() {
- return dispatcher;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.LeafNodeBaseSerializer;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-
-public class LeafNodeCnSnSerializer extends LeafNodeBaseSerializer<Node<?>> {
-
- @Override
- protected Node<?> serializeLeaf(LeafSchemaNode schema, LeafNode<?> node) {
- return NodeFactory.createMutableSimpleNode(node.getNodeType(), null, node.getValue(), null, null);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.LeafSetEntryNodeBaseSerializer;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-
-public class LeafSetEntryNodeCnSnSerializer extends
- LeafSetEntryNodeBaseSerializer<Node<?>> {
-
- @Override
- protected Node<?> serializeLeaf(LeafListSchemaNode schema, LeafSetEntryNode<?> node) {
- return NodeFactory.createMutableSimpleNode(
- node.getNodeType(), null, node.getValue(), null, null);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.FromNormalizedNodeSerializer;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.LeafSetNodeBaseSerializer;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-
-public class LeafSetNodeCnSnSerializer extends
- LeafSetNodeBaseSerializer<Node<?>> {
-
- private FromNormalizedNodeSerializer<Node<?>, LeafSetEntryNode<?>, LeafListSchemaNode> leafSetEntryNodeSerializer;
-
- public LeafSetNodeCnSnSerializer(final LeafSetEntryNodeCnSnSerializer leafSetEntryNodeSerializer) {
- this.leafSetEntryNodeSerializer = leafSetEntryNodeSerializer;
- }
-
- @Override
- protected FromNormalizedNodeSerializer<Node<?>, LeafSetEntryNode<?>, LeafListSchemaNode> getLeafSetEntryNodeSerializer() {
- return leafSetEntryNodeSerializer;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import com.google.common.base.Preconditions;
-import java.util.Collections;
-import java.util.List;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
-import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.ListEntryNodeBaseSerializer;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.NodeSerializerDispatcher;
-import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-/**
- *
- * Common class for list entry node serialization (MapEntry, UnkeyedListEntry nodes)
- *
- * @param <N>
- * concrete entry node type
- */
-abstract class ListEntryNodeCnSnSerializer<N extends DataContainerNode<?>> extends
- ListEntryNodeBaseSerializer<Node<?>, N> {
- private final NodeSerializerDispatcher<Node<?>> dispatcher;
-
- ListEntryNodeCnSnSerializer(final NodeSerializerDispatcher<Node<?>> dispatcher) {
- this.dispatcher = Preconditions.checkNotNull(dispatcher);
- }
-
- @Override
- public List<Node<?>> serialize(ListSchemaNode schema, N node) {
- CompositeNodeBuilder<ImmutableCompositeNode> compNodeBuilder = ImmutableCompositeNode.builder();
- compNodeBuilder.setQName(node.getNodeType());
- compNodeBuilder.addAll(super.serialize(schema, node));
- return Collections.<Node<?>> singletonList(compNodeBuilder.toInstance());
- }
-
- @Override
- protected NodeSerializerDispatcher<Node<?>> getNodeDispatcher() {
- return dispatcher;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.NodeSerializerDispatcher;
-
-public class MapEntryNodeCnSnSerializer extends ListEntryNodeCnSnSerializer<MapEntryNode> {
-
- MapEntryNodeCnSnSerializer(final NodeSerializerDispatcher<Node<?>> dispatcher) {
- super(dispatcher);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-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.FromNormalizedNodeSerializer;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.ListNodeBaseSerializer;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-public class MapNodeCnSnSerializer extends ListNodeBaseSerializer<Node<?>, MapNode, MapEntryNode> {
-
- private final FromNormalizedNodeSerializer<Node<?>, MapEntryNode, ListSchemaNode> mapEntrySerializer;
-
- public MapNodeCnSnSerializer(final MapEntryNodeCnSnSerializer mapEntrySerializer) {
- this.mapEntrySerializer = mapEntrySerializer;
- }
-
- @Override
- protected FromNormalizedNodeSerializer<Node<?>, MapEntryNode, ListSchemaNode> getListEntryNodeSerializer() {
- return mapEntrySerializer;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.NodeSerializerDispatcher;
-
-final class UnkeyedListEntryNodeCnSnSerializer extends ListEntryNodeCnSnSerializer<UnkeyedListEntryNode> {
-
- UnkeyedListEntryNodeCnSnSerializer(final NodeSerializerDispatcher<Node<?>> dispatcher) {
- super(dispatcher);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.cnsn.serializer;
-
-import org.opendaylight.yangtools.yang.data.api.Node;
-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.FromNormalizedNodeSerializer;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.serializer.ListNodeBaseSerializer;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-final class UnkeyedListNodeCnSnSerializer extends
- ListNodeBaseSerializer<Node<?>, UnkeyedListNode, UnkeyedListEntryNode> {
-
- private final FromNormalizedNodeSerializer<Node<?>, UnkeyedListEntryNode, ListSchemaNode> unkeyedListEntrySerializer;
-
- UnkeyedListNodeCnSnSerializer(UnkeyedListEntryNodeCnSnSerializer unkeyedListEntrySerializer) {
- this.unkeyedListEntrySerializer = unkeyedListEntrySerializer;
- }
-
- @Override
- protected FromNormalizedNodeSerializer<Node<?>, UnkeyedListEntryNode, ListSchemaNode> getListEntryNodeSerializer() {
- return unkeyedListEntrySerializer;
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2013 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.composite.node.schema.json;
-
-import com.google.common.collect.LinkedListMultimap;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-
-public final class CnSnToNormalizedNodesUtils {
-
-
- private CnSnToNormalizedNodesUtils() {
- throw new UnsupportedOperationException("Utility class should not be instantiated");
- }
-
- public static LinkedListMultimap<QName, Node<?>> mapChildElementsForSingletonNode(Node<?> node) {
- return mapChildElements( ((CompositeNode)node).getValue());
- }
-
- public static LinkedListMultimap<QName, Node<?>> mapChildElements(Iterable<Node<?>> childNodesCollection) {
- LinkedListMultimap<QName, Node<?>> mappedChildElements = LinkedListMultimap.create();
-
- for (Node<?> node : childNodesCollection) {
- mappedChildElements.put(node.getNodeType(), node);
- }
-
- return mappedChildElements;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.composite.node.schema;
-
-import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.yangtools.yang.data.impl.NodeFactory.createMutableSimpleNode;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-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.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-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.ImmutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TestUtils {
-
- private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class);
- private static final QNameModule MODULE_AUGMENT;
- private static final QNameModule MODULE_BASE;
-
- static {
- final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
-
- try {
- MODULE_BASE = QNameModule.create(URI.create("simple:container:yang"), df.parse("2013-11-12"));
- MODULE_AUGMENT = QNameModule.create(URI.create("augment:container:yang"), df.parse("2014-03-19"));
- } catch (ParseException e) {
- throw new ExceptionInInitializerError(e);
- }
- }
-
- public static Set<Module> loadModules(final URI resourceURI) throws FileNotFoundException {
- final YangModelParser parser = new YangParserImpl();
- final File testDir = new File(resourceURI);
- final String[] fileList = testDir.list();
- final List<File> testFiles = new ArrayList<>();
- if (fileList == null) {
- throw new FileNotFoundException(resourceURI.toString());
- }
- for (String fileName : fileList) {
- testFiles.add(new File(testDir, fileName));
- }
- return parser.parseYangModels(testFiles);
- }
-
- public static Set<Module> loadModulesFrom(final String yangPath) throws URISyntaxException {
- try {
- return loadModules(TestUtils.class.getResource(yangPath).toURI());
- } catch (FileNotFoundException e) {
- LOG.error("Yang files at path: " + yangPath + " weren't loaded.");
- }
-
- return null;
- }
-
- public static DataSchemaNode resolveDataSchemaNode(final String searchedDataSchemaName, final Module module) {
- assertNotNull("Module can't be null", module);
-
- if (searchedDataSchemaName != null) {
- for (DataSchemaNode dsn : module.getChildNodes()) {
- if (dsn.getQName().getLocalName().equals(searchedDataSchemaName)) {
- return dsn;
- }
- }
- } else if (module.getChildNodes().size() == 1) {
- return module.getChildNodes().iterator().next();
- }
- return null;
- }
-
- public static Module resolveModule(final String searchedModuleName, final Set<Module> modules) {
- assertNotNull("Modules can't be null.", modules);
- if (searchedModuleName != null) {
- for (Module m : modules) {
- if (m.getName().equals(searchedModuleName)) {
- return m;
- }
- }
- } else if (modules.size() == 1) {
- return modules.iterator().next();
- }
- return null;
- }
-
- /**
- * Prepare composite node structure according to
- * /cnsn-to-normalized-node/simple-conainer.json
- */
- public static CompositeNode prepareCompositeNodeStruct() {
- CompositeNodeBuilder<ImmutableCompositeNode> contBuilder = ImmutableCompositeNode.builder();
- contBuilder.setQName(QName.create(MODULE_BASE, "cont"));
-
- // cont1
- contBuilder.add(ImmutableCompositeNode.builder().setQName(QName.create(MODULE_BASE, "cont1")).build());
-
- // cont2
- CompositeNodeBuilder<ImmutableCompositeNode> cont2 = ImmutableCompositeNode.builder().setQName(
- QName.create(MODULE_BASE, "cont2"));
- cont2.add(createMutableSimpleNode(QName.create(MODULE_BASE, "lf21"), null, "value in cont2/lf21", null, null));
- contBuilder.add(cont2.build());
-
- // lst1
- contBuilder.add(ImmutableCompositeNode.builder().setQName(QName.create(MODULE_BASE, "lst1")).build());
-
- // lst2
- CompositeNodeBuilder<ImmutableCompositeNode> lst2_1Builder = ImmutableCompositeNode.builder().setQName(
- QName.create(MODULE_BASE, "lst2"));
- lst2_1Builder.add(createMutableSimpleNode(QName.create(MODULE_BASE, "lf21"), null, "some value21", null, null));
- contBuilder.add(lst2_1Builder.build());
-
- CompositeNodeBuilder<ImmutableCompositeNode> lst2_2Builder = ImmutableCompositeNode.builder().setQName(
- QName.create(MODULE_BASE, "lst2"));
- lst2_2Builder.add(createMutableSimpleNode(QName.create(MODULE_BASE, "lf22"), null, "some value22", null, null));
- contBuilder.add(lst2_2Builder.build());
-
- // lflst1
- contBuilder.add(createMutableSimpleNode(QName.create(MODULE_BASE, "lflst1"), null, "lflst1_1", null, null));
- contBuilder.add(createMutableSimpleNode(QName.create(MODULE_BASE, "lflst1"), null, "lflst1_2", null, null));
-
- // lf1
- contBuilder.add(createMutableSimpleNode(QName.create(MODULE_BASE, "lf1"), null, "lf1", null, null));
-
- // lf11
- contBuilder.add(createMutableSimpleNode(QName.create(MODULE_BASE, "lf11"), null, "value from case (cs1)", null,
- null));
-
- // cont3
- CompositeNodeBuilder<ImmutableCompositeNode> cont3Builder = ImmutableCompositeNode.builder().setQName(
- QName.create(MODULE_AUGMENT, "cont3"));
- cont3Builder.add(createMutableSimpleNode(QName.create(MODULE_AUGMENT, "lf31"), null,
- "value in leaf in augment", null, null));
- contBuilder.add(cont3Builder.build());
-
- // anxml-composite
- CompositeNodeBuilder<ImmutableCompositeNode> anxmlCompositeBuilder = ImmutableCompositeNode.builder().setQName(
- QName.create(MODULE_BASE, "anxml-composite"));
- anxmlCompositeBuilder.add(NodeFactory.createImmutableSimpleNode(QName.create(MODULE_BASE, "anxml-cont"), null,
- null));
- contBuilder.add(anxmlCompositeBuilder.build());
-
- // anxml-simple
- contBuilder.add(NodeFactory.createImmutableSimpleNode(QName.create(MODULE_BASE, "anxml-simple"), null,43));
-
- return contBuilder.build();
- }
-
- /**
- * Prepare composite node structure according to
- * /cnsn-to-normalized-node/simple-conainer.json
- */
- public static ContainerNode prepareNormalizedNodeStruct() throws URISyntaxException {
- DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders.containerBuilder();
- containerBuilder.withNodeIdentifier(getNodeIdentifier("cont"));
- containerBuilder.withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("cont1")).build());
- containerBuilder.withChild(Builders
- .containerBuilder()
- .withNodeIdentifier(getNodeIdentifier("cont2"))
- .withChild(
- Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("lf21"))
- .withValue("value in cont2/lf21").build()).build());
-
- CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> lst1 = Builders.unkeyedListBuilder().withNodeIdentifier(
- getNodeIdentifier("lst1"));
- lst1.withChild(Builders.unkeyedListEntryBuilder()
- .withNodeIdentifier(getNodeIdentifier("lst1"))
- .withValue(Collections.<DataContainerChild<? extends PathArgument, ?>> emptyList()).build());
- containerBuilder.withChild(lst1.build());
-
- CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> lst2 = Builders.unkeyedListBuilder().withNodeIdentifier(
- getNodeIdentifier("lst2"));
-
- Map<String, Object> lst2_1 = new HashMap<>();
- lst2_1.put("lf21", "some value21");
-
- List<DataContainerChild<? extends PathArgument, ?>> lst2_1_values = new ArrayList<>();
- lst2_1_values.add(Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("lf21"))
- .withValue("some value21").build());
- lst2.withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(getNodeIdentifier("lst2"))
- .withValue(lst2_1_values).build());
-
- Map<String, Object> lst2_2 = new HashMap<>();
- lst2_2.put("lf22", "some value22");
- List<DataContainerChild<? extends PathArgument, ?>> lst2_2_values = new ArrayList<>();
- lst2_2_values.add(Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("lf22"))
- .withValue("some value22").build());
- lst2.withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(getNodeIdentifier("lst2"))
- .withValue(lst2_2_values).build());
- containerBuilder.withChild(lst2.build());
-
- ListNodeBuilder<Object, LeafSetEntryNode<Object>> lflst1 = Builders.leafSetBuilder().withNodeIdentifier(
- getNodeIdentifier("lflst1"));
- lflst1.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(getNodeIdentifier("lflst1", "lflst1_1"))
- .withValue("lflst1_1").build());
- lflst1.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(getNodeIdentifier("lflst1", "lflst1_2"))
- .withValue("lflst1_2").build());
- containerBuilder.withChild(lflst1.build());
-
- containerBuilder.withChild(Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("lf1")).withValue("lf1")
- .build());
-
- containerBuilder.withChild(Builders
- .choiceBuilder()
- .withNodeIdentifier(getNodeIdentifier("chc"))
- .withChild(
- Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("lf11"))
- .withValue("value from case (cs1)").build()).build());
-
- Set<QName> children = new HashSet<>();
- children.add(QName.create(MODULE_AUGMENT, "cont3"));
-
- containerBuilder.withChild(Builders
- .augmentationBuilder()
- .withNodeIdentifier(getAugmentationIdentifier(null, null, null, children))
- .withChild(
- Builders.containerBuilder()
- .withNodeIdentifier(getNodeIdentifier(MODULE_AUGMENT, "cont3"))
- .withChild(
- Builders.leafBuilder()
- .withNodeIdentifier(getNodeIdentifier(MODULE_AUGMENT, "lf31"))
- .withValue("value in leaf in augment").build()).build()).build());
-
-// containerBuilder.withChild(Builders
-// .anyXmlBuilder()
-// .withNodeIdentifier(getNodeIdentifier("anxml-composite"))
-// .withValue(
-// ImmutableCompositeNode
-// .builder()
-// .setQName(QName.create("simple:container:yang", "2013-11-12", "anxml-composite"))
-// .add(NodeFactory.createImmutableSimpleNode(
-// QName.create("simple:container:yang", "2013-11-12", "anxml-cont"), null, null))
-// .build()).build());
-//
-// containerBuilder
-// .withChild(Builders
-// .anyXmlBuilder()
-// .withNodeIdentifier(getNodeIdentifier("anxml-simple"))
-// .withValue(
-// NodeFactory.createImmutableSimpleNode(
-// QName.create("simple:container:yang", "2013-11-12", "anxml-simple"), null, 43))
-// .build());
-
- ContainerNode build = containerBuilder.build();
- return build;
- }
-
- private static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final String localName) {
- return getNodeIdentifier(MODULE_BASE, localName);
- }
-
- private static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final QNameModule module, final String localName) {
- return new YangInstanceIdentifier.NodeIdentifier(QName.create(module, localName));
- }
-
- private static YangInstanceIdentifier.NodeWithValue getNodeIdentifier(final String localName, final Object value) {
- return new YangInstanceIdentifier.NodeWithValue(QName.create(MODULE_BASE, localName),
- value);
- }
-
- private static YangInstanceIdentifier.NodeIdentifierWithPredicates getNodeIdentifierPredicate(final String localName,
- final Map<String, Object> keys) {
- Map<QName, Object> predicate = new HashMap<>();
- for (String key : keys.keySet()) {
- predicate.put(QName.create(MODULE_BASE, key), keys.get(key));
- }
-
- return new YangInstanceIdentifier.NodeIdentifierWithPredicates(QName.create(MODULE_BASE, localName), predicate);
- }
-
- private static YangInstanceIdentifier.AugmentationIdentifier getAugmentationIdentifier(final String localName,
- final String namespace, final Date revision, final Set<QName> children) {
- return new YangInstanceIdentifier.AugmentationIdentifier(children);
- }
-
-}
+++ /dev/null
-package org.opendaylight.yangtools.yang.data.composite.node.schema.parser;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Set;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.composite.node.schema.TestUtils;
-import org.opendaylight.yangtools.yang.data.composite.node.schema.cnsn.parser.CnSnToNormalizedNodeParserFactory;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.ToNormalizedNodeParser;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-
-@Ignore
-public class Bug2180Test {
- private Module simpleContainerModule;
- private Module bug2111TestModule;
-
- @Before
- public void init() throws URISyntaxException {
- Set<Module> modules = TestUtils.loadModulesFrom("/cnsn-to-normalized-node/yang");
- simpleContainerModule = TestUtils.resolveModule("simple-container-yang", modules);
- bug2111TestModule = TestUtils.resolveModule("bug2180-test-module", modules);
- }
-
- @Test
- public void orderedListParseTest() throws DataValidationFailedException, URISyntaxException {
- ContainerSchemaNode topContainerSchemaNode = (ContainerSchemaNode) TestUtils.resolveDataSchemaNode("top", bug2111TestModule);
- ListSchemaNode aceListSchemaNode = (ListSchemaNode) topContainerSchemaNode.getDataChildByName("ordered-list");
- ToNormalizedNodeParser<Node<?>, OrderedMapNode, ListSchemaNode> orderedListNodeParser =
- CnSnToNormalizedNodeParserFactory.getInstance().getOrderedListNodeParser();
- MapNode mapNode = orderedListNodeParser.parse(new ArrayList<Node<?>>(), aceListSchemaNode);
- assertTrue(mapNode instanceof OrderedMapNode);
- }
-
- @Test
- public void unorderedListParseTest() throws DataValidationFailedException, URISyntaxException {
- ContainerSchemaNode topContainerSchemaNode = (ContainerSchemaNode) TestUtils.resolveDataSchemaNode("cont", simpleContainerModule);
- ListSchemaNode aceListSchemaNode = (ListSchemaNode) topContainerSchemaNode.getDataChildByName("lst2");
- ToNormalizedNodeParser<Node<?>, MapNode, ListSchemaNode> mapNodeParser =
- CnSnToNormalizedNodeParserFactory.getInstance().getMapNodeParser();
- MapNode mapNode = mapNodeParser.parse(new ArrayList<Node<?>>(), aceListSchemaNode);
- assertFalse(mapNode instanceof OrderedMapNode);
- }
-
- @Test
- public void orderedLeafListParseTest() throws DataValidationFailedException, URISyntaxException {
- ContainerSchemaNode topContainerSchemaNode = (ContainerSchemaNode) TestUtils.resolveDataSchemaNode("top", bug2111TestModule);
- LeafListSchemaNode aceListSchemaNode = (LeafListSchemaNode) topContainerSchemaNode.getDataChildByName("ordered-leaf-list");
- ToNormalizedNodeParser<Node<?>, LeafSetNode<?>, LeafListSchemaNode> leafSetNodeParser =
- CnSnToNormalizedNodeParserFactory.getInstance().getLeafSetNodeParser();
- LeafSetNode<?> leafSetNode = leafSetNodeParser.parse(new ArrayList<Node<?>>(), aceListSchemaNode);
- assertTrue(leafSetNode instanceof OrderedLeafSetNode);
- }
-
- @Test
- public void unorderedLeafListParseTest() throws DataValidationFailedException, URISyntaxException {
- ContainerSchemaNode topContainerSchemaNode = (ContainerSchemaNode) TestUtils.resolveDataSchemaNode("cont", simpleContainerModule);
- LeafListSchemaNode aceListSchemaNode = (LeafListSchemaNode) topContainerSchemaNode.getDataChildByName("lflst1");
- ToNormalizedNodeParser<Node<?>, LeafSetNode<?>, LeafListSchemaNode> leafSetNodeParser =
- CnSnToNormalizedNodeParserFactory.getInstance().getLeafSetNodeParser();
- LeafSetNode<?> leafSetNode = leafSetNodeParser.parse(new ArrayList<Node<?>>(), aceListSchemaNode);
- assertFalse(leafSetNode instanceof OrderedLeafSetNode);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.composite.node.schema.parser;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Ignore;
-import org.opendaylight.yangtools.yang.data.composite.node.schema.cnsn.parser.CnSnToNormalizedNodeParserFactory;
-
-
-import org.opendaylight.yangtools.yang.data.composite.node.schema.TestUtils;
-
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-
-@Ignore
-public class ParseCnSnStructToNormalizedStructTest {
-
- private static DataSchemaNode resolvedDataSchemaNode;
-
- @BeforeClass
- public static void loadData() throws URISyntaxException {
- Set<Module> modules = TestUtils.loadModulesFrom("/cnsn-to-normalized-node/yang");
- Module resolvedModule = TestUtils.resolveModule("simple-container-yang", modules);
- resolvedDataSchemaNode = TestUtils.resolveDataSchemaNode("cont", resolvedModule);
- }
-
- @Test
- public void testCnSnToNormalizedNode() throws URISyntaxException {
-
- CompositeNode compNode = TestUtils.prepareCompositeNodeStruct();
-
- List<Node<?>> lst = new ArrayList<Node<?>>();
- lst.add(compNode);
- ContainerNode parsed = CnSnToNormalizedNodeParserFactory.getInstance().getContainerNodeParser()
- .parse(lst, (ContainerSchemaNode) resolvedDataSchemaNode);
-
- ContainerNode prepareExpectedStruct = TestUtils.prepareNormalizedNodeStruct();
- assertEquals(prepareExpectedStruct, parsed);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.composite.node.schema.serializer;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Ignore;
-import org.opendaylight.yangtools.yang.data.composite.node.schema.cnsn.serializer.CnSnFromNormalizedNodeSerializerFactory;
-
-
-import org.opendaylight.yangtools.yang.data.composite.node.schema.TestUtils;
-
-import java.net.URISyntaxException;
-import java.util.Set;
-
-import com.google.common.collect.Sets;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
-
-@Ignore
-public class SerializeNormalizedStructToCnSnStructTest {
-
- private static DataSchemaNode resolvedDataSchemaNode;
-
- @BeforeClass
- public static void loadData() throws URISyntaxException {
- Set<Module> modules = TestUtils.loadModulesFrom("/cnsn-to-normalized-node/yang");
- Module resolvedModule = TestUtils.resolveModule("simple-container-yang", modules);
- resolvedDataSchemaNode = TestUtils.resolveDataSchemaNode("cont", resolvedModule);
- }
-
- @Test
- public void testCnSnToNormalizedNode() throws URISyntaxException {
- ContainerNode containerNode = TestUtils.prepareNormalizedNodeStruct();
-
- Iterable<Node<?>> serialized = CnSnFromNormalizedNodeSerializerFactory.getInstance()
- .getContainerNodeSerializer().serialize((ContainerSchemaNode) resolvedDataSchemaNode, containerNode);
-
- assertNotNull(serialized);
- assertNotNull(serialized.iterator());
- assertNotNull(serialized.iterator().hasNext());
-
- CompositeNode compNode = TestUtils.prepareCompositeNodeStruct();
-
- assertEquals(serialized.iterator().next().getNodeType(), compNode.getNodeType());
-
- Set<Node<?>> value = Sets.newHashSet(((CompositeNode)serialized.iterator().next()).getValue());
- assertEquals(value, Sets.newHashSet(compNode.getValue()));
- }
-}
+++ /dev/null
-{
- "simple-container-yang:cont":{
- "cont1":{
- },
- "cont2":{
- "lf21":"value in cont2/lf21"
- },
- "augment-container-yang:cont3":{
- "lf31":"value in leaf in augment"
- },
- "lst1": [
- {
- }
- ],
- "lst2": [
- {
- "lf21":"some value21"
- },
- {
- "lf22":"some value22"
- }
- ],
- "lflst1":[
- "lflst1_1",
- "lflst1_2"
- ],
- "lf1":"lf1",
-
- "lf11":"value from case (cs1)"
- "anxml-composite": {
- "anxml-cont" {
- }
- }
-
- "anxml-simple":43;
- }
-}
\ No newline at end of file
+++ /dev/null
-module augment-container-yang {
- namespace "augment:container:yang";
-
- prefix "auconyang";
- import simple-container-yang { prefix "simple"; revision-date 2013-11-12; }
-
- revision 2014-03-19 {
- }
-
- augment "/simple:cont" {
- container cont3 {
- leaf lf31 {
- type string;
- }
- }
- }
-
-}
+++ /dev/null
-module bug2180-test-module {
- yang-version 1;
-
- namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:bug2180:test";
-
- prefix bug2180-test-module;
-
- revision 2014-10-22 {
- description "creating base model for netmod";
- }
-
- container top {
- list ordered-list {
- key id;
- ordered-by user;
- leaf id{
- type string;
- }
- }
-
- leaf-list ordered-leaf-list {
- type string;
- ordered-by user;
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-module simple-container-yang {
- namespace "simple:container:yang";
-
- prefix "smpdtp";
- revision 2013-11-12 {
- }
-
- container cont {
- container cont1 {
- }
- container cont2 {
- leaf lf21 {
- type string;
- }
- }
- list lst1 {
- }
- list lst2 {
- leaf lf21 {
- type string;
- }
- leaf lf22 {
- type string;
- }
- }
- leaf-list lflst1 {
- type string;
- }
- leaf lf1 {
- type string;
- }
-
- choice chc {
- case cs1 {
- leaf lf11 {
- type string;
- }
- }
- case cs2 {
- leaf lf21 {
- type string;
- }
- }
- }
-
- anyxml anxml-composite;
- anyxml anxml-simple;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.NodeModification;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
-
-/**
- * @author michal.rehak
- * @param <T>
- * type of node value
- * @deprecated Use one of the {@link NormalizedNodeBuilder} implementations.
- */
-@Deprecated
-public abstract class AbstractNodeTO<T> implements Node<T>, NodeModification {
-
- private QName qName;
- private CompositeNode parent;
- private T value;
- private ModifyAction modifyAction;
-
- // Only for Serialization use
- public AbstractNodeTO(){
-
- }
-
- /**
- * @param qname
- * @param parent
- * @param value
- */
- public AbstractNodeTO(final QName qname, final CompositeNode parent, final T value) {
- this(qname, parent, value, null);
- }
-
- /**
- * @param qname
- * @param parent
- * @param value
- * @param modifyAction
- */
- public AbstractNodeTO(final QName qname, final CompositeNode parent, final T value, final ModifyAction modifyAction) {
- this.qName = qname;
- this.parent = parent;
- this.value = value;
- this.modifyAction = modifyAction;
- }
-
- @Override
- public QName getNodeType() {
- return qName;
- }
-
- /**
- * @return the qName
- */
- public QName getQName() {
- return qName;
- }
-
- @Override
- public CompositeNode getParent() {
- return parent;
- }
-
- /**
- * @param parent
- * the parent to set
- */
- public void setParent(final CompositeNode parent) {
- this.parent = parent;
- }
-
- /**
- * @param value
- * the value to set
- */
- @Override
- public T setValue(final T value) {
- T oldValue = this.value;
- this.value = value;
- return oldValue;
- }
-
- @Override
- public T getValue() {
- return value;
- }
-
- /**
- * @return modification action
- * @see NodeModification#getModificationAction()
- */
- @Override
- public ModifyAction getModificationAction() {
- return modifyAction;
- }
-
- /**
- * @param modifyAction
- * the modifyAction to set
- */
- protected void setModificationAction(final ModifyAction modifyAction) {
- this.modifyAction = modifyAction;
- }
-
- @Override
- public String toString() {
- StringBuffer out = new StringBuffer();
- out.append(String.format("Node[%s], qName[%s], modify[%s]", getClass().getSimpleName(), getQName()
- .getLocalName(), getModificationAction() == null ? "n/a" : getModificationAction()));
- return out.toString();
- }
-
-
- @Override
- public final QName getKey() {
- return getNodeType();
- }
-
- /* */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((qName == null) ? 0 : qName.hashCode());
- result = prime * result + ((value == null) ? 0 : value.hashCode());
- return result % 2;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- @SuppressWarnings("unchecked")
- AbstractNodeTO<T> other = (AbstractNodeTO<T>) obj;
- if (parent == null) {
- if (other.parent != null) {
- return false;
- }
- } else if (other.parent == null) {
- return false;
- }
- if (qName == null) {
- if (other.qName != null) {
- return false;
- }
- } else if (!qName.equals(other.qName)) {
- return false;
- }
- if (value == null) {
- if (other.value != null) {
- return false;
- }
- } else if (!value.equals(other.value)) {
- return false;
- }
- return true;
- }
- /* */
-
-
- //Serialization related
-
- protected final void init(final QName qName, final CompositeNode parent, final T value, final ModifyAction modifyAction){
- this.qName = qName;
- this.modifyAction = modifyAction;
- this.parent = parent;
- this.value = value;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.util.List;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * @author michal.rehak
- *
- * @deprecated Use one of the {@link NormalizedNode} implementations.
- */
-@Deprecated
-public class CompositeNodeModificationTOImpl extends CompositeNodeTOImpl {
- private static final long serialVersionUID = 1L;
-
- /**
- * @param qname
- * @param parent
- * @param value
- * @param modifyAction
- */
- public CompositeNodeModificationTOImpl(final QName qname, final CompositeNode parent,
- final List<Node<?>> value, final ModifyAction modifyAction) {
- super(qname, parent, value);
- super.setModificationAction(modifyAction);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
-
-/**
- * @author michal.rehak
- *
- * @deprecated Use one of the {@link NormalizedNodeContainer} implementations.
- */
-@Deprecated
-public class CompositeNodeTOImpl extends AbstractNodeTO<List<Node<?>>> implements CompositeNode, Serializable {
-
- private static final long serialVersionUID = 100L;
-
- private Map<QName, List<Node<?>>> nodeMap = new HashMap<>();
-
- /**
- * @param qname
- * @param parent
- * use null to create top composite node (without parent)
- * @param value
- */
- public CompositeNodeTOImpl(final QName qname, final CompositeNode parent, final List<Node<?>> value) {
- super(qname, parent, value);
- init();
- }
-
- /**
- * @param qname
- * @param parent
- * use null to create top composite node (without parent)
- * @param value
- * @param modifyAction
- */
- public CompositeNodeTOImpl(final QName qname, final CompositeNode parent, final List<Node<?>> value, final ModifyAction modifyAction) {
- super(qname, parent, value, modifyAction);
- init();
- }
-
- protected void init() {
- if (getValue() != null) {
- nodeMap = NodeUtils.buildNodeMap(getValue());
- }
- }
-
- protected Map<QName, List<Node<?>>> getNodeMap() {
- return nodeMap;
- }
-
- @Override
- public List<Node<?>> getChildren() {
- return Collections.unmodifiableList(getValue() == null ? new ArrayList<Node<?>>() : getValue());
- }
-
- @Override
- public SimpleNode<?> getFirstSimpleByName(final QName leafQName) {
- List<SimpleNode<?>> list = getSimpleNodesByName(leafQName);
- if (list.isEmpty()) {
- return null;
- }
- return list.get(0);
- }
-
- @Override
- public List<CompositeNode> getCompositesByName(final QName children) {
- List<Node<?>> toFilter = getNodeMap().get(children);
- if(toFilter == null) {
- return Collections.emptyList();
- }
- List<CompositeNode> list = new ArrayList<CompositeNode>();
- for (Node<?> node : toFilter) {
- if (node instanceof CompositeNode) {
- list.add((CompositeNode) node);
- }
- }
- return list;
- }
-
- @Override
- public List<SimpleNode<?>> getSimpleNodesByName(final QName children) {
- List<Node<?>> toFilter = getNodeMap().get(children);
- if(toFilter == null) {
- return Collections.emptyList();
- }
- List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
-
- for (Node<?> node : toFilter) {
- if (node instanceof SimpleNode<?>) {
- list.add((SimpleNode<?>) node);
- }
- }
- return list;
- }
-
- @Override
- public CompositeNode getFirstCompositeByName(final QName container) {
- List<CompositeNode> list = getCompositesByName(container);
- if (list.isEmpty()) {
- return null;
- }
- return list.get(0);
- }
-
- /**
- * @param leaf
- * @return TODO:: do we need this method?
- */
- public SimpleNode<?> getFirstLeafByName(final QName leaf) {
- List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
- if (list.isEmpty()) {
- return null;
- }
- return list.get(0);
- }
-
- @Override
- public List<CompositeNode> getCompositesByName(final String children) {
- return getCompositesByName(QName.create(getNodeType(), children));
- }
-
- @Override
- public List<SimpleNode<?>> getSimpleNodesByName(final String children) {
- return getSimpleNodesByName(QName.create(getNodeType(), children));
- }
-
- @Override
- public MutableCompositeNode asMutable() {
- throw new IllegalAccessError("cast to mutable is not supported - " + getClass().getSimpleName());
- }
-
- @Override
- public String toString() {
- return super.toString() + ", children.size = " + (!getChildren().isEmpty() ? getChildren().size() : "n/a");
- }
-
- @Override
- public void clear() {
- nodeMap.clear();
- }
-
- @Override
- public boolean containsKey(final Object key) {
- return nodeMap.containsKey(key);
- }
-
- @Override
- public boolean containsValue(final Object value) {
- return nodeMap.containsValue(value);
- }
-
- @Override
- public Set<java.util.Map.Entry<QName, List<Node<?>>>> entrySet() {
- return nodeMap.entrySet();
- }
-
- @Override
- public int size() {
- return nodeMap.size();
- }
-
- @Override
- public boolean isEmpty() {
- return nodeMap.isEmpty();
- }
-
- @Override
- public List<Node<?>> get(final Object key) {
- return nodeMap.get(key);
- }
-
- @Override
- public List<Node<?>> put(final QName key, final List<Node<?>> value) {
- return nodeMap.put(key, value);
- }
-
- @Override
- public List<Node<?>> remove(final Object key) {
- return nodeMap.remove(key);
- }
-
- @Override
- public void putAll(final Map<? extends QName, ? extends List<Node<?>>> m) {
- nodeMap.putAll(m);
- }
-
- @Override
- public Set<QName> keySet() {
- return nodeMap.keySet();
- }
-
- @Override
- public Collection<List<Node<?>>> values() {
- return nodeMap.values();
- }
-
- // Serialization related
-
- private void readObject(final ObjectInputStream aStream) throws IOException, ClassNotFoundException {
- aStream.defaultReadObject();
- QName qName = (QName)aStream.readObject();
- CompositeNode parent = (CompositeNode) aStream.readObject();
- @SuppressWarnings("unchecked")
- List<Node<?>> value = (List<Node<?>>) aStream.readObject();
- ModifyAction modifyAction = (ModifyAction) aStream.readObject();
-
- init(qName, parent, value, modifyAction);
- }
-
- private void writeObject(final ObjectOutputStream aStream) throws IOException {
- aStream.defaultWriteObject();
- //manually serialize superclass
- aStream.writeObject(getQName());
- aStream.writeObject(getParent());
- aStream.writeObject(getValue());
- aStream.writeObject(getModificationAction());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
-import org.opendaylight.yangtools.yang.data.impl.util.AbstractCompositeNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
-
-/**
- * @deprecated Use one of the {@link NormalizedNodeContainer} implementations.
- */
-@Deprecated
-public final class ImmutableCompositeNode extends AbstractNodeTO<List<Node<?>>> implements Immutable, CompositeNode, AttributesContainer, Serializable {
-
- private static final long serialVersionUID = 100L;
-
- private Map<QName, List<Node<?>>> nodeMap = new HashMap<>();
-
- private final Map<QName, String> attributes;
-
-
-
- /**
- * @param qname
- * @param parent
- * use null to create top composite node (without parent)
- * @param value
- */
- private ImmutableCompositeNode(final QName qname, final Map<QName,String> attributes,final List<Node<?>> value) {
- super(qname, null, ImmutableList.copyOf(value));
- if(attributes == null) {
- this.attributes = ImmutableMap.<QName, String>of();
- } else {
- this.attributes = ImmutableMap.copyOf(attributes);
- }
- init();
- }
-
- /**
- * @param qname
- * @param value
- * @param modifyAction
- */
- public ImmutableCompositeNode(final QName qname, final List<Node<?>> value, final ModifyAction modifyAction) {
- super(qname, null, value, modifyAction);
- attributes = ImmutableMap.of();
- init();
- }
-
- protected void init() {
- if (getValue() != null) {
- nodeMap = NodeUtils.buildNodeMap(getValue());
- }
- }
-
- protected Map<QName, List<Node<?>>> getNodeMap() {
- return nodeMap;
- }
-
- @Override
- public List<Node<?>> getChildren() {
- return Collections.unmodifiableList(getValue() == null ? new ArrayList<Node<?>>() : getValue());
- }
-
- @Override
- public SimpleNode<?> getFirstSimpleByName(final QName leafQName) {
- List<SimpleNode<?>> list = getSimpleNodesByName(leafQName);
- if (list.isEmpty()) {
- return null;
- }
- return list.get(0);
- }
-
- @Override
- public List<CompositeNode> getCompositesByName(final QName children) {
- List<Node<?>> toFilter = getNodeMap().get(children);
- if (toFilter == null) {
- return Collections.emptyList();
- }
- List<CompositeNode> list = new ArrayList<CompositeNode>();
- for (Node<?> node : toFilter) {
- if (node instanceof CompositeNode) {
- list.add((CompositeNode) node);
- }
- }
- return list;
- }
-
- @Override
- public List<SimpleNode<?>> getSimpleNodesByName(final QName children) {
- List<Node<?>> toFilter = getNodeMap().get(children);
- if (toFilter == null) {
- return Collections.emptyList();
- }
- List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
-
- for (Node<?> node : toFilter) {
- if (node instanceof SimpleNode<?>) {
- list.add((SimpleNode<?>) node);
- }
- }
- return list;
- }
-
- @Override
- public CompositeNode getFirstCompositeByName(final QName container) {
- List<CompositeNode> list = getCompositesByName(container);
- if (list.isEmpty()) {
- return null;
- }
- return list.get(0);
- }
-
- @Override
- public Map<QName, String> getAttributes() {
- return attributes;
- }
-
- @Override
- public String getAttributeValue(final QName key) {
- return attributes.get(key);
- }
-
- /**
- * @param leaf
- * @return TODO:: do we need this method?
- */
- public SimpleNode<?> getFirstLeafByName(final QName leaf) {
- List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
- if (list.isEmpty()) {
- return null;
- }
- return list.get(0);
- }
-
- @Override
- public List<CompositeNode> getCompositesByName(final String children) {
- return getCompositesByName(QName.create(getNodeType(), children));
- }
-
- @Override
- public List<SimpleNode<?>> getSimpleNodesByName(final String children) {
- return getSimpleNodesByName(QName.create(getNodeType(), children));
- }
-
- @Override
- public MutableCompositeNode asMutable() {
- throw new IllegalAccessError("cast to mutable is not supported - " + getClass().getSimpleName());
- }
-
- @Override
- public String toString() {
- return super.toString() + ", children.size = " + (!getChildren().isEmpty() ? getChildren().size() : "n/a");
- }
-
- @Override
- public void clear() {
- nodeMap.clear();
- }
-
- @Override
- public boolean containsKey(final Object key) {
- return nodeMap.containsKey(key);
- }
-
- @Override
- public boolean containsValue(final Object value) {
- return nodeMap.containsValue(value);
- }
-
- @Override
- public Set<java.util.Map.Entry<QName, List<Node<?>>>> entrySet() {
- return nodeMap.entrySet();
- }
-
- @Override
- public int size() {
- return nodeMap.size();
- }
-
- @Override
- public boolean isEmpty() {
- return nodeMap.isEmpty();
- }
-
- @Override
- public List<Node<?>> get(final Object key) {
- return nodeMap.get(key);
- }
-
- @Override
- public List<Node<?>> put(final QName key, final List<Node<?>> value) {
- return nodeMap.put(key, value);
- }
-
- @Override
- public List<Node<?>> remove(final Object key) {
- return nodeMap.remove(key);
- }
-
- @Override
- public void putAll(final Map<? extends QName, ? extends List<Node<?>>> m) {
- nodeMap.putAll(m);
- }
-
- @Override
- public Set<QName> keySet() {
- return nodeMap.keySet();
- }
-
- @Override
- public Collection<List<Node<?>>> values() {
- return nodeMap.values();
- }
-
- // Serialization related
-
- private void readObject(final ObjectInputStream aStream) throws IOException, ClassNotFoundException {
- aStream.defaultReadObject();
- QName qName = (QName) aStream.readObject();
- CompositeNode parent = (CompositeNode) aStream.readObject();
- @SuppressWarnings("unchecked")
- List<Node<?>> value = (List<Node<?>>) aStream.readObject();
- ModifyAction modifyAction = (ModifyAction) aStream.readObject();
-
- init(qName, parent, value, modifyAction);
- }
-
- private void writeObject(final ObjectOutputStream aStream) throws IOException {
- aStream.defaultWriteObject();
- // manually serialize superclass
- aStream.writeObject(getQName());
- aStream.writeObject(getParent());
- aStream.writeObject(getValue());
- aStream.writeObject(getModificationAction());
- }
-
- public static CompositeNodeBuilder<ImmutableCompositeNode> builder() {
- return new ImmutableCompositeNodeBuilder();
- }
-
- private static class ImmutableCompositeNodeBuilder extends AbstractCompositeNodeBuilder<ImmutableCompositeNode> {
-
- @Override
- public AbstractCompositeNodeBuilder<ImmutableCompositeNode> addLeaf(final QName leafName, final Object leafValue) {
- add(new SimpleNodeTOImpl<Object>(leafName, null, leafValue));
- return this;
- }
-
- @Override
- public ImmutableCompositeNode build() {
- return ImmutableCompositeNode.create(this.getQName(), this.getAttributes(), this.getChildNodes());
- }
-
- @Deprecated
- public ImmutableCompositeNode toInstance() {
- return ImmutableCompositeNode.create(this.getQName(), this.getAttributes(), this.getChildNodes());
- }
-
- }
-
- public static ImmutableCompositeNode create(final QName qName, final List<Node<?>> childNodes) {
- return new ImmutableCompositeNode(qName, ImmutableMap.<QName, String>of(),childNodes);
- }
-
- public static ImmutableCompositeNode create(final QName qName, final Map<QName, String> attributes, final List<Node<?>> childNodes) {
- return new ImmutableCompositeNode(qName, attributes,childNodes);
- }
-
- public static ImmutableCompositeNode create(final QName qName, final List<Node<?>> childNodes, final ModifyAction modifyAction) {
- return new ImmutableCompositeNode(qName, childNodes, modifyAction);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.MutableNode;
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.NodeModification;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-
-/**
- * @author michal.rehak
- *
- */
-@Deprecated
-public class LazyNodeToNodeMap {
-
- private final Map<Node<?>, Node<?>> node2node = new HashMap<>();
- private CompositeNode originalRoot;
- private MutableCompositeNode mutableRoot;
-
- /**
- * @param originalNode
- * @return mutable twin
- */
- public Node<?> getMutableEquivalent(final Node<?> originalNode) {
- Node<?> mutableNode = node2node.get(originalNode);
- if (mutableNode == null) {
- addPathMembers(originalNode);
- mutableNode = node2node.get(originalNode);
- }
-
- return mutableNode;
- }
-
- /**
- * @param originalNode
- */
- private void addPathMembers(final Node<?> originalNode) {
- final Deque<Node<?>> jobQueue = new ArrayDeque<>();
- jobQueue.push(originalNode);
- while (!jobQueue.isEmpty()) {
- Node<?> node2add = jobQueue.pop();
- boolean fixChildrenRefOnly = false;
- if (node2node.containsKey(node2add)) {
- if (node2add instanceof SimpleNode<?>) {
- continue;
- }
- fixChildrenRefOnly = true;
- }
-
- CompositeNode nextParent = node2add.getParent();
- MutableNode<?> mutableEquivalent = null;
-
- if (node2add instanceof SimpleNode<?>) {
- SimpleNode<?> node2addSimple = (SimpleNode<?>) node2add;
- MutableSimpleNode<?> nodeMutant = NodeFactory.createMutableSimpleNode(
- node2add.getNodeType(), null, node2addSimple.getValue(),
- node2addSimple.getModificationAction(), node2addSimple);
- mutableEquivalent = nodeMutant;
- } else if (node2add instanceof CompositeNode) {
- MutableCompositeNode nodeMutant = null;
- if (fixChildrenRefOnly) {
- nodeMutant = (MutableCompositeNode) node2node.get(node2add);
- } else {
- CompositeNode node2addComposite = (CompositeNode) node2add;
- nodeMutant = NodeFactory.createMutableCompositeNode(node2add.getNodeType(),
- null, null,
- ((NodeModification) node2add).getModificationAction(), node2addComposite);
- }
-
- mutableEquivalent = nodeMutant;
-
- // tidy up children
- if (nodeMutant.getValue() == null) {
- nodeMutant.setValue(new ArrayList<Node<?>>());
- }
- for (Node<?> originalChildNode : ((CompositeNode) node2add).getValue()) {
- MutableNode<?> mutableChild = (MutableNode<?>) node2node.get(originalChildNode);
- fixChildrenRef(nodeMutant, mutableChild);
- }
-
- if (nodeMutant.getValue() != null && !nodeMutant.getValue().isEmpty()) {
- nodeMutant.init();
- }
-
- // store tree root, if occured
- if (nextParent == null) {
- if (originalRoot == null) {
- originalRoot = (CompositeNode) node2add;
- mutableRoot = nodeMutant;
- } else {
- if (!originalRoot.equals(node2add)) {
- throw new IllegalStateException("Different tree root node obtained - " +
- "perhaps nodes of different trees are getting mixed up.");
- }
- }
- }
- }
-
- // feed jobQueue
- node2node.put(node2add, mutableEquivalent);
- if (nextParent != null) {
- jobQueue.push(nextParent);
- }
- }
- }
-
- /**
- * @param nodeMutant
- * @param mutableChild
- */
- private static void fixChildrenRef(final MutableCompositeNode nodeMutant,
- final MutableNode<?> mutableChild) {
- if (mutableChild != null) {
- if (!nodeMutant.getValue().contains(mutableChild)) {
- nodeMutant.getValue().add(mutableChild);
- }
- CompositeNode parentOfChild = mutableChild.getParent();
- if (parentOfChild == null) {
- mutableChild.setParent(nodeMutant);
- } else {
- if (!parentOfChild.equals(nodeMutant)) {
- throw new IllegalStateException("Different parent node obtained - " +
- "perhaps nodes of different trees are getting mixed up.");
- }
- }
- }
- }
-
- /**
- * @return the mutableRoot
- */
- public MutableCompositeNode getMutableRoot() {
- return mutableRoot;
- }
-
- /**
- * @return set of original nodes, registered in map as keys
- */
- public Set<Node<?>> getKeyNodes() {
- return node2node.keySet();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
-
-/**
- * @author michal.rehak
- *
- * @deprecated Use one of the {@link NormalizedNodeContainer} implementations instead.
- */
-@Deprecated
-public class MutableCompositeNodeTOImpl extends AbstractNodeTO<List<Node<?>>> implements MutableCompositeNode, Serializable {
-
- private static final long serialVersionUID = 100L;
-
- private Map<QName, List<Node<?>>> nodeMap = new HashMap<>();
- private CompositeNode original;
-
- public MutableCompositeNodeTOImpl(final QName qname, final CompositeNode parent, final List<Node<?>> value, final ModifyAction modifyAction) {
- super(qname, parent, value, modifyAction);
- init();
- }
-
- /**
- * update nodeMap - it should be invoked after children was changed
- */
- @Override
- public void init() {
- if (!getChildren().isEmpty()) {
- nodeMap = NodeUtils.buildNodeMap(getChildren());
- }
- }
-
- @Override
- public List<Node<?>> getChildren() {
- return getValue() == null ? new ArrayList<Node<?>>() : getValue();
- }
-
- @Override
- public List<Node<?>> setValue(final List<Node<?>> value) {
- List<Node<?>> oldVal = super.setValue(value);
- init();
- return oldVal;
- }
-
- @Override
- public void setModifyAction(final ModifyAction action) {
- super.setModificationAction(action);
- }
-
- protected Map<QName, List<Node<?>>> getNodeMap() {
- return nodeMap;
- }
-
- @Override
- public MutableCompositeNode asMutable() {
- return this;
- }
-
- @Override
- public CompositeNode getOriginal() {
- return original;
- }
-
- /**
- * @param original
- * the original to set
- */
- public void setOriginal(final CompositeNode original) {
- this.original = original;
- }
-
- @Override
- public SimpleNode<?> getFirstSimpleByName(final QName leafQName) {
- List<SimpleNode<?>> list = getSimpleNodesByName(leafQName);
- if (list.isEmpty()) {
- return null;
- }
- return list.get(0);
- }
-
- @Override
- public List<CompositeNode> getCompositesByName(final QName children) {
- List<Node<?>> toFilter = getNodeMap().get(children);
- if (toFilter == null) {
- return Collections.emptyList();
- }
- List<CompositeNode> list = new ArrayList<CompositeNode>();
- for (Node<?> node : toFilter) {
- if (node instanceof CompositeNode) {
- list.add((CompositeNode) node);
- }
- }
- return list;
- }
-
- @Override
- public List<SimpleNode<?>> getSimpleNodesByName(final QName children) {
- List<Node<?>> toFilter = getNodeMap().get(children);
- if (toFilter == null) {
- return Collections.emptyList();
- }
- List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
-
- for (Node<?> node : toFilter) {
- if (node instanceof SimpleNode<?>) {
- list.add((SimpleNode<?>) node);
- }
- }
- return list;
- }
-
- @Override
- public CompositeNode getFirstCompositeByName(final QName container) {
- List<CompositeNode> list = getCompositesByName(container);
- if (list.isEmpty()) {
- return null;
- }
- return list.get(0);
- }
-
- /**
- * @param leaf
- * @return TODO:: do we need this method?
- */
- public SimpleNode<?> getFirstLeafByName(final QName leaf) {
- List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
- if (list.isEmpty()) {
- return null;
- }
- return list.get(0);
- }
-
- @Override
- public List<CompositeNode> getCompositesByName(final String children) {
- return getCompositesByName(QName.create(getNodeType(), children));
- }
-
- @Override
- public List<SimpleNode<?>> getSimpleNodesByName(final String children) {
- return getSimpleNodesByName(QName.create(getNodeType(), children));
- }
-
- @Override
- public String toString() {
- return super.toString() + ", children.size = " + (getChildren() != null ? getChildren().size() : "n/a");
- }
-
- @Override
- public void clear() {
- nodeMap.clear();
- }
-
- @Override
- public boolean containsKey(final Object key) {
- return nodeMap.containsKey(key);
- }
-
- @Override
- public boolean containsValue(final Object value) {
- return nodeMap.containsValue(value);
- }
-
- @Override
- public Set<java.util.Map.Entry<QName, List<Node<?>>>> entrySet() {
- return nodeMap.entrySet();
- }
-
- @Override
- public int size() {
- return nodeMap.size();
- }
-
- @Override
- public boolean isEmpty() {
- return nodeMap.isEmpty();
- }
-
- @Override
- public List<Node<?>> get(final Object key) {
- return nodeMap.get(key);
- }
-
- @Override
- public List<Node<?>> put(final QName key, final List<Node<?>> value) {
- return nodeMap.put(key, value);
- }
-
- @Override
- public List<Node<?>> remove(final Object key) {
- return nodeMap.remove(key);
- }
-
- @Override
- public void putAll(final Map<? extends QName, ? extends List<Node<?>>> m) {
- nodeMap.putAll(m);
- }
-
- @Override
- public Set<QName> keySet() {
- return nodeMap.keySet();
- }
-
- @Override
- public Collection<List<Node<?>>> values() {
- return nodeMap.values();
- }
-
- // Serialization related
-
- private void readObject(final ObjectInputStream aStream) throws IOException, ClassNotFoundException {
- aStream.defaultReadObject();
- QName qName = (QName)aStream.readObject();
- CompositeNode parent = (CompositeNode) aStream.readObject();
- @SuppressWarnings("unchecked")
- List<Node<?>> value = (List<Node<?>>) aStream.readObject();
- ModifyAction modifyAction = (ModifyAction) aStream.readObject();
-
- init(qName, parent, value, modifyAction);
- }
-
- private void writeObject(final ObjectOutputStream aStream) throws IOException {
- aStream.defaultWriteObject();
- //manually serialize superclass
- aStream.writeObject(getQName());
- aStream.writeObject(getParent());
- aStream.writeObject(getValue());
- aStream.writeObject(getModificationAction());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * @author michal.rehak
- * @param <T>
- * type of simple node value
- *
- * @deprecated Use one of the {@link NormalizedNode} implementation packages.
- */
-@Deprecated
-public class MutableSimpleNodeTOImpl<T> extends SimpleNodeTOImpl<T> implements MutableSimpleNode<T> {
- private static final long serialVersionUID = 1L;
- private SimpleNode<T> original;
-
- /**
- * @param qname
- * @param parent
- * @param value
- * @param modifyAction
- */
- public MutableSimpleNodeTOImpl(final QName qname, final CompositeNode parent, final T value, final ModifyAction modifyAction) {
- super(qname, parent, value, modifyAction);
- }
-
- @Override
- public void setModifyAction(final ModifyAction action) {
- super.setModificationAction(action);
- }
-
- @Override
- public MutableSimpleNode<T> asMutable() {
- return this;
- }
-
- @Override
- public SimpleNode<T> getOriginal() {
- return original;
- }
-
- /**
- * @param original
- * the original to set
- */
- public void setOriginal(final SimpleNode<T> original) {
- this.original = original;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.util.AbstractMap.SimpleEntry;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.NodeModification;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-
-/**
- * @author michal.rehak
- *
- * @deprecated Use {@link Builders} instead.
- */
-@Deprecated
-public abstract class NodeFactory {
-
- /**
- * @param qName
- * @param parent
- * @param value
- * @return simple node modification, based on given qname, value and parent
- */
- public static <T> SimpleNode<T> createImmutableSimpleNode(final QName qName,
- final CompositeNode parent, final T value) {
- return createImmutableSimpleNode(qName, parent, value, null);
- }
-
- /**
- * @param qName
- * @param parent
- * @param value
- * @param modifyAction
- * @param original originating node, if available
- * @return simple node modification, based on given qname, value and parent
- */
- public static <T> MutableSimpleNode<T> createMutableSimpleNode(final QName qName,
- final CompositeNode parent, final Object value, final ModifyAction modifyAction, final SimpleNode<T> original) {
- @SuppressWarnings("unchecked")
- MutableSimpleNodeTOImpl<T> simpleNodeTOImpl = new MutableSimpleNodeTOImpl<>(qName, parent, (T) value, modifyAction);
- simpleNodeTOImpl.setOriginal(original);
- return simpleNodeTOImpl;
- }
-
- /**
- * @param qName
- * @param parent
- * @param value
- * @return composite node modification, based on given qname, value (children), parent and modifyAction
- */
- public static CompositeNode createImmutableCompositeNode(final QName qName,
- final CompositeNode parent, final List<Node<?>> value) {
- return createImmutableCompositeNode(qName, parent, value, null);
- }
-
- /**
- * @param qName
- * @param parent
- * @param valueArg
- * @param modifyAction
- * @param original originating node, if available
- * @return composite node modification, based on given qName, value (children), parent and modifyAction
- */
- public static MutableCompositeNode createMutableCompositeNode(final QName qName,
- final CompositeNode parent, final List<Node<?>> valueArg, final ModifyAction modifyAction, final CompositeNode original) {
- List<Node<?>> value = valueArg;
- if (value == null) {
- value = new ArrayList<>();
- }
- MutableCompositeNodeTOImpl compositeNodeTOImpl =
- new MutableCompositeNodeTOImpl(qName, parent, value, modifyAction);
- compositeNodeTOImpl.setOriginal(original);
- return compositeNodeTOImpl;
- }
-
-
- /**
- * @param qName
- * @param parent
- * @param value
- * @param modifyAction
- * @return simple node modification, based on given qname, value, parent and modifyAction
- */
- public static <T> SimpleNode<T> createImmutableSimpleNode(final QName qName,
- final CompositeNode parent, final T value, final ModifyAction modifyAction) {
- SimpleNodeTOImpl<T> simpleNodeModTOImpl =
- new SimpleNodeTOImpl<T>(qName, parent, value, modifyAction);
- return simpleNodeModTOImpl;
- }
-
- /**
- * @param qName
- * @param parent
- * @param value
- * @param modifyAction
- * @return composite node modification, based on given qname, value (children), parent and modifyAction
- */
- public static CompositeNode createImmutableCompositeNode(final QName qName,
- final CompositeNode parent, final List<Node<?>> value, final ModifyAction modifyAction) {
- return new CompositeNodeTOImpl(qName, parent, value, modifyAction);
- }
-
- /**
- * @param node
- * @return copy of given node, parent and value are the same, but parent
- * has no reference to this copy
- */
- public static <T> SimpleNode<T> copyNode(final SimpleNode<T> node) {
- return createImmutableSimpleNode(node.getNodeType(), node.getParent(), node.getValue());
- }
-
- /**
- * @param node
- * @return copy of given node, parent and value are the same, but parent
- * has no reference to this copy
- */
- public static <T> MutableSimpleNode<T> copyNodeAsMutable(final SimpleNode<T> node) {
- return createMutableSimpleNode(
- node.getNodeType(), node.getParent(), node.getValue(),
- node.getModificationAction(), null);
- }
-
- /**
- * @param node
- * @param children
- * @return copy of given node, parent and children are the same, but parent and children
- * have no reference to this copy
- */
- public static CompositeNode copyNode(final CompositeNode node, final Node<?>... children) {
- CompositeNode twinNode = createImmutableCompositeNode(
- node.getNodeType(), node.getParent(), Arrays.asList(children), node.getModificationAction());
- return twinNode;
- }
-
- /**
- * @param node
- * @return copy of given node, parent and children are the same, but parent and children
- * have no reference to this copy
- */
- public static CompositeNode copyNode(final CompositeNode node) {
- return copyNode(node, node.getValue().toArray(new Node<?>[0]));
- }
-
- /**
- * @param node root of original tree
- * @param originalToCopyArg (optional) empty map, where binding between original and copy
- * will be stored
- * @return copy of given node and all subnodes recursively
- */
- public static MutableCompositeNode copyDeepAsMutable(final CompositeNode node,
- final Map<Node<?>, Node<?>> originalToCopyArg) {
-
- Map<Node<?>, Node<?>> originalToCopy = originalToCopyArg;
- if (originalToCopy == null) {
- originalToCopy = new HashMap<>();
- }
-
- MutableCompositeNode mutableRoot = createMutableCompositeNode(node.getNodeType(), null, null,
- node.getModificationAction(), null);
- final Deque<SimpleEntry<CompositeNode, MutableCompositeNode>> jobQueue = new ArrayDeque<>();
- jobQueue.push(new SimpleEntry<CompositeNode, MutableCompositeNode>(node, mutableRoot));
- originalToCopy.put(node, mutableRoot);
-
- while (!jobQueue.isEmpty()) {
- SimpleEntry<CompositeNode, MutableCompositeNode> job = jobQueue.pop();
- CompositeNode originalNode = job.getKey();
- MutableCompositeNode mutableNode = job.getValue();
- mutableNode.setValue(new ArrayList<Node<?>>());
-
- for (Node<?> child : originalNode.getValue()) {
- Node<?> mutableAscendant = null;
- if (child instanceof CompositeNode) {
- MutableCompositeNode newMutable =
- createMutableCompositeNode(child.getNodeType(), mutableNode, null,
- ((NodeModification) child).getModificationAction(), null);
- jobQueue.push(new SimpleEntry<CompositeNode, MutableCompositeNode>(
- (CompositeNode) child, newMutable));
- mutableAscendant = newMutable;
- } else if (child instanceof SimpleNode<?>) {
- mutableAscendant =
- createMutableSimpleNode(child.getNodeType(), mutableNode,
- child.getValue(),
- ((NodeModification) child).getModificationAction(), null);
- } else {
- throw new IllegalStateException("Node class deep copy not supported: "
- +child.getClass().getName());
- }
-
- mutableNode.getValue().add(mutableAscendant);
- originalToCopy.put(child, mutableAscendant);
- }
- mutableNode.init();
- }
-
- return mutableRoot;
- }
-
- /**
- * @param node root of original tree
- * @param originalToCopyArg (optional) empty map, where binding between original and copy
- * will be stored
- * @return copy of given node and all subnodes recursively
- */
- public static CompositeNode copyDeepAsImmutable(final CompositeNode node,
- final Map<Node<?>, Node<?>> originalToCopyArg) {
- final Deque<CompositeNode> jobQueue = new ArrayDeque<>();
- jobQueue.push(node);
-
- Map<Node<?>, Node<?>> originalToCopy = originalToCopyArg;
- if (originalToCopy == null) {
- originalToCopy = new HashMap<>();
- }
-
- while (!jobQueue.isEmpty()) {
- CompositeNode jobNode = jobQueue.peek();
- if (!originalToCopy.isEmpty()
- && originalToCopy.keySet().containsAll(jobNode.getValue())) {
- jobQueue.pop();
- List<Node<?>> newChildren = NodeUtils.collectMapValues(jobNode.getValue(), originalToCopy);
- CompositeNode nodeCopy = createImmutableCompositeNode(jobNode.getNodeType(), null,
- newChildren, jobNode.getModificationAction());
- NodeUtils.fixChildrenRelation(nodeCopy);
- originalToCopy.put(jobNode, nodeCopy);
- } else {
- for (Node<?> child : jobNode.getValue()) {
- if (child instanceof SimpleNode<?>) {
- originalToCopy.put(child, createImmutableSimpleNode(
- child.getNodeType(), null, child.getValue(),
- ((NodeModification) child).getModificationAction()));
- } else if (child instanceof CompositeNode) {
- jobQueue.push((CompositeNode) child);
- }
- }
- }
- }
-
- return (CompositeNode) originalToCopy.get(node);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.MutableNode;
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.NodeModificationBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-
-/**
- * @author michal.rehak
- *
- * @deprecated Use {@link Builders} instead.
- */
-@Deprecated
-public class NodeModificationBuilderImpl implements NodeModificationBuilder {
-
- private final SchemaContext context;
-
- private final Set<MutableNode<?>> changeLog;
- private final LazyNodeToNodeMap originalToMutable;
-
- /**
- * @param context
- */
- public NodeModificationBuilderImpl(final SchemaContext context) {
- this.context = context;
- originalToMutable = new LazyNodeToNodeMap();
- changeLog = new HashSet<>();
- }
-
- /**
- * @param modNode
- * @param action
- */
- private void addModificationToLog(final MutableNode<?> modNode, final ModifyAction action) {
- modNode.setModifyAction(action);
- changeLog.add(modNode);
- }
-
- @Override
- public void addNode(final MutableSimpleNode<?> newNode) {
- NodeUtils.fixParentRelation(newNode);
- addModificationToLog(newNode, ModifyAction.CREATE);
- }
-
- @Override
- public void addNode(final MutableCompositeNode newNode) {
- NodeUtils.fixParentRelation(newNode);
- addModificationToLog(newNode, ModifyAction.CREATE);
- }
-
- @Override
- public void replaceNode(final MutableSimpleNode<?> replacementNode) {
- addModificationToLog(replacementNode, ModifyAction.REPLACE);
- }
-
- @Override
- public void replaceNode(final MutableCompositeNode replacementNode) {
- addModificationToLog(replacementNode, ModifyAction.REPLACE);
- }
-
- @Override
- public void deleteNode(final MutableCompositeNode deadNode) {
- addModificationToLog(deadNode, ModifyAction.DELETE);
- }
-
- @Override
- public void deleteNode(final MutableSimpleNode<?> deadNode) {
- addModificationToLog(deadNode, ModifyAction.DELETE);
- }
-
- @Override
- public void removeNode(final MutableSimpleNode<?> deadNode) {
- addModificationToLog(deadNode, ModifyAction.REMOVE);
- }
-
- @Override
- public void removeNode(final MutableCompositeNode deadNode) {
- addModificationToLog(deadNode, ModifyAction.REMOVE);
- }
-
- @Override
- public void mergeNode(final MutableCompositeNode alteredNode) {
- addModificationToLog(alteredNode, ModifyAction.MERGE);
- }
-
- /**
- * @return minimalistic tree containing diffs only
- */
- @Override
- public CompositeNode buildDiffTree() {
- Set<Node<?>> wanted = new HashSet<>();
-
- // walk changeLog, collect all required nodes
- for (MutableNode<?> mutant : changeLog) {
- wanted.addAll(collectSelfAndAllParents(mutant));
- }
-
- // walk wanted and add relevant keys
- Map<String, ListSchemaNode> mapOfLists = NodeUtils.buildMapOfListNodes(context);
- for (Node<?> outlaw : wanted) {
- if (outlaw instanceof CompositeNode) {
- String path = NodeUtils.buildPath(outlaw);
- if (mapOfLists.containsKey(path)) {
- ListSchemaNode listSchema = mapOfLists.get(path);
- if (listSchema.getQName().equals(outlaw.getNodeType())) {
- // try to add key subnode to wanted list
- List<QName> supportedKeys = listSchema.getKeyDefinition();
- CompositeNode outlawOriginal = ((MutableCompositeNode) outlaw).getOriginal();
- for (Node<?> outlawOriginalChild : outlawOriginal.getValue()) {
- if (supportedKeys.contains(outlawOriginalChild.getNodeType())) {
- originalToMutable.getMutableEquivalent(outlawOriginalChild);
- }
- }
- }
- }
- }
- }
-
- return originalToMutable.getMutableRoot();
- }
-
- /**
- * @param focusedDescendant
- * @return set of parents and focusedAncestor itself
- */
- private static Set<Node<?>> collectSelfAndAllParents(final Node<?> focusedDescendant) {
- Set<Node<?>> family = new HashSet<>();
- Node<?> tmpNode = focusedDescendant;
- while (tmpNode != null) {
- family.add(tmpNode);
- tmpNode = tmpNode.getParent();
- }
- return family;
- }
-
- /**
- * @param originalNode
- * @return mutable version of given node
- */
- @Override
- public Node<?> getMutableEquivalent(final Node<?> originalNode) {
- return originalToMutable.getMutableEquivalent(originalNode);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import com.google.common.base.Function;
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import java.util.AbstractMap.SimpleEntry;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Nonnull;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.NodeModification;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Element;
-
-/**
- * @author michal.rehak
- *
- * @deprecated Use {@link NormalizedNodes} instead.
- */
-@Deprecated
-public abstract class NodeUtils {
- private static final Joiner DOT_JOINER = Joiner.on(".");
- private static final Logger LOG = LoggerFactory.getLogger(NodeUtils.class);
- private static final Function<QName, String> LOCALNAME_FUNCTION = new Function<QName, String>() {
- @Override
- public String apply(final @Nonnull QName input) {
- Preconditions.checkNotNull(input);
- return input.getLocalName();
- }
- };
-
- /**
- *
- */
- private static final String USER_KEY_NODE = "node";
-
- /**
- * @param node
- * @return node path up till root node
- */
- public static String buildPath(final Node<?> node) {
- List<String> breadCrumbs = new ArrayList<>();
- Node<?> tmpNode = node;
- while (tmpNode != null) {
- breadCrumbs.add(0, tmpNode.getNodeType().getLocalName());
- tmpNode = tmpNode.getParent();
- }
-
- return DOT_JOINER.join(breadCrumbs);
- }
-
- /**
- * @param treeRootNode
- * @return dom tree, containing same node structure, yang nodes are
- * associated to dom nodes as user data
- */
- public static org.w3c.dom.Document buildShadowDomTree(final CompositeNode treeRootNode) {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- org.w3c.dom.Document doc = null;
- try {
- DocumentBuilder bob = dbf.newDocumentBuilder();
- doc = bob.newDocument();
- } catch (ParserConfigurationException e) {
- LOG.error("documentBuilder problem", e);
- return null;
- }
-
- final Deque<SimpleEntry<org.w3c.dom.Node, Node<?>>> jobQueue = new ArrayDeque<>();
- jobQueue.push(new SimpleEntry<org.w3c.dom.Node, Node<?>>(doc, treeRootNode));
-
- while (!jobQueue.isEmpty()) {
- SimpleEntry<org.w3c.dom.Node, Node<?>> job = jobQueue.pop();
- org.w3c.dom.Node jointPlace = job.getKey();
- Node<?> item = job.getValue();
- QName nodeType = item.getNodeType();
- Element itemEl = doc.createElementNS(nodeType.getNamespace().toString(), item.getNodeType().getLocalName());
- itemEl.setUserData(USER_KEY_NODE, item, null);
- if (item instanceof SimpleNode<?>) {
- Object value = ((SimpleNode<?>) item).getValue();
- if(value != null) {
- itemEl.setTextContent(String.valueOf(value));
- }
- }
- if (item instanceof NodeModification) {
- ModifyAction modificationAction = ((NodeModification) item).getModificationAction();
- if (modificationAction != null) {
- itemEl.setAttribute("modifyAction", modificationAction.toString());
- }
- }
-
- jointPlace.appendChild(itemEl);
-
- if (item instanceof CompositeNode) {
- for (Node<?> child : ((CompositeNode) item).getValue()) {
- jobQueue.push(new SimpleEntry<org.w3c.dom.Node, Node<?>>(itemEl, child));
- }
- }
- }
-
- return doc;
- }
-
- /**
- * @param doc
- * @param xpathEx
- * @return user data value on found node
- * @throws XPathExpressionException
- */
- @SuppressWarnings("unchecked")
- public static <T> T findNodeByXpath(final org.w3c.dom.Document doc, final String xpathEx) throws XPathExpressionException {
- T userNode = null;
- XPathFactory xPathfactory = XPathFactory.newInstance();
- XPath xpath = xPathfactory.newXPath();
- XPathExpression expr = xpath.compile(xpathEx);
-
- org.w3c.dom.Node result = (org.w3c.dom.Node) expr.evaluate(doc, XPathConstants.NODE);
- if (result != null) {
- userNode = (T) result.getUserData(USER_KEY_NODE);
- }
-
- return userNode;
- }
-
- /**
- * build NodeMap, where key = qName; value = node
- *
- * @param value
- * @return map of children, where key = qName and value is list of children
- * groupped by qName
- */
- public static Map<QName, List<Node<?>>> buildNodeMap(final List<Node<?>> value) {
- Map<QName, List<Node<?>>> nodeMapTmp = Maps.newLinkedHashMap();
- if (value == null) {
- throw new IllegalStateException("nodeList should not be null or empty");
- }
- for (Node<?> node : value) {
- List<Node<?>> qList = nodeMapTmp.get(node.getNodeType());
- if (qList == null) {
- qList = new ArrayList<>();
- nodeMapTmp.put(node.getNodeType(), qList);
- }
- qList.add(node);
- }
- return nodeMapTmp;
- }
-
- /**
- * @param context
- * @return map of lists, where key = path; value = {@link DataSchemaNode}
- */
- public static Map<String, ListSchemaNode> buildMapOfListNodes(final SchemaContext context) {
- Map<String, ListSchemaNode> mapOfLists = new HashMap<>();
-
- final Deque<DataSchemaNode> jobQueue = new ArrayDeque<>();
- jobQueue.addAll(context.getDataDefinitions());
-
- while (!jobQueue.isEmpty()) {
- DataSchemaNode dataSchema = jobQueue.pop();
- if (dataSchema instanceof ListSchemaNode) {
- mapOfLists.put(schemaPathToPath(dataSchema.getPath().getPathFromRoot()), (ListSchemaNode) dataSchema);
- }
-
- if (dataSchema instanceof DataNodeContainer) {
- jobQueue.addAll(((DataNodeContainer) dataSchema).getChildNodes());
- }
- }
-
- return mapOfLists;
- }
-
- /**
- * @param qNamesPath
- * @return path
- */
- private static String schemaPathToPath(final Iterable<QName> qNamesPath) {
- return DOT_JOINER.join(Iterables.transform(qNamesPath, LOCALNAME_FUNCTION));
- }
-
- /**
- * add given node to it's parent's list of children
- *
- * @param newNode
- */
- public static void fixParentRelation(final Node<?> newNode) {
- if (newNode.getParent() != null) {
- List<Node<?>> siblings = newNode.getParent().getValue();
- if (!siblings.contains(newNode)) {
- siblings.add(newNode);
- }
- }
- }
-
- /**
- * crawl all children of given node and assign it as their parent
- *
- * @param parentNode
- */
- public static void fixChildrenRelation(final CompositeNode parentNode) {
- if (parentNode.getValue() != null) {
- for (Node<?> child : parentNode.getValue()) {
- if (child instanceof AbstractNodeTO<?>) {
- ((AbstractNodeTO<?>) child).setParent(parentNode);
- }
- }
- }
- }
-
- /**
- * @param keys
- * @param dataMap
- * @return list of values of map, found by given keys
- */
- public static <T, K> List<K> collectMapValues(final List<T> keys, final Map<T, K> dataMap) {
- List<K> valueSubList = new ArrayList<>();
- for (T key : keys) {
- valueSubList.add(dataMap.get(key));
- }
-
- return valueSubList;
- }
-
- /**
- * @param nodes
- * @return list of children in list of appropriate type
- */
- public static List<Node<?>> buildChildrenList(final Node<?>... nodes) {
- return Lists.newArrayList(nodes);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * @author michal.rehak
- * @param <T> type of node value
- *
- * @deprecated Use one of the {@link NormalizedNode} implementation packages.
- */
-@Deprecated
-public class SimpleNodeModificationTOImpl<T> extends SimpleNodeTOImpl<T> {
- private static final long serialVersionUID = 1L;
-
- /**
- * @param qname
- * @param parent
- * @param value
- * @param modifyAction
- */
- public SimpleNodeModificationTOImpl(final QName qname, final CompositeNode parent,
- final T value, final ModifyAction modifyAction) {
- super(qname, parent, value);
- setModificationAction(modifyAction);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * @author michal.rehak
- * @param <T> type of simple node value
- *
- * @deprecated Use one of the {@link NormalizedNode} implementation packages.
- */
-@Deprecated
-public class SimpleNodeTOImpl<T> extends AbstractNodeTO<T> implements SimpleNode<T>, Serializable {
-
- private static final long serialVersionUID = 100L;
-
- /**
- * @param qname
- * @param parent
- * @param value
- */
- public SimpleNodeTOImpl(final QName qname, final CompositeNode parent, final T value) {
- super(qname, parent, value);
- }
-
- /**
- * @param qname
- * @param parent
- * @param value
- * @param modifyAction
- */
- public SimpleNodeTOImpl(final QName qname, final CompositeNode parent, final T value, final ModifyAction modifyAction) {
- super(qname, parent, value, modifyAction);
- }
-
- @Override
- public MutableSimpleNode<T> asMutable() {
- throw new IllegalAccessError("cast to mutable is not supported - "+getClass().getSimpleName());
- }
-
- @Override
- public String toString() {
-
- return super.toString() + ", value = "+getValue();
- }
-
- // Serialization related
-
- private void readObject(final ObjectInputStream aStream) throws IOException, ClassNotFoundException {
- aStream.defaultReadObject();
- QName qName = (QName)aStream.readObject();
- CompositeNode parent = (CompositeNode) aStream.readObject();
- T value = (T) aStream.readObject();
- ModifyAction modifyAction = (ModifyAction) aStream.readObject();
-
- init(qName, parent, value, modifyAction);
- }
-
- private void writeObject(final ObjectOutputStream aStream) throws IOException {
- aStream.defaultWriteObject();
- //manually serialize superclass
- aStream.writeObject(getQName());
- aStream.writeObject(getParent());
- aStream.writeObject(getValue());
- aStream.writeObject(getModificationAction());
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import java.io.InputStream;
-import java.net.URI;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Deque;
-
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.events.Characters;
-import javax.xml.stream.events.StartElement;
-import javax.xml.stream.events.XMLEvent;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-
-/**
- * The XML Tree Builder is builder utility class designed to facilitate of
- * loading, reading and parsing XML documents into YANG DOM represented by
- * yang-data-api. <br>
- * The method {@link #buildDataTree(InputStream)} is designed to take and parse
- * XML as {@link InputStream}. The output of the operation SHOULD be root
- * <code>CompositeNode</code> or <code>SimpleElement</code> depends by which
- * element XML begins. The XML header is omitted by XML parser.
- *
- * @author Lukas Sedlak
- *
- * @see CompositeNode
- * @see SimpleNode
- * @see Node
- */
-public final class XmlTreeBuilder {
- private final static XMLInputFactory XML_INPUT_FACTORY = XMLInputFactory.newInstance();
-
- private XmlTreeBuilder() {
- }
-
- /**
- * The method is designed to take and parse XML as {@link InputStream}. The
- * output of the operation SHOULD be root <code>CompositeNode</code> or
- * <code>SimpleElement</code> depends on element that XML document begins.
- * The XML header is omitted by XML parser.
- *
- * @param inputStream
- * XML Input Stream
- * @return root <code>Node</code> element conformant to XML start element in
- * most cases it will be CompositeNode which contains child Nodes
- * @throws XMLStreamException
- */
- public static Node<?> buildDataTree(final InputStream inputStream) throws XMLStreamException {
- final XMLEventReader eventReader = XML_INPUT_FACTORY.createXMLEventReader(inputStream);
-
- final Deque<Node<?>> processingQueue = new ArrayDeque<>();
- Node<?> parentNode = null;
- Node<?> root = null;
- while (eventReader.hasNext()) {
- final XMLEvent event = eventReader.nextEvent();
-
- if (event.isStartElement()) {
- final StartElement startElement = event.asStartElement();
- if (!processingQueue.isEmpty()) {
- parentNode = processingQueue.peek();
- }
- MutableCompositeNode compParentNode = null;
- if (parentNode instanceof MutableCompositeNode) {
- compParentNode = (MutableCompositeNode) parentNode;
- }
- Node<?> newNode = null;
- if (isCompositeNodeEvent(eventReader, event)) {
- newNode = resolveCompositeNodeFromStartElement(startElement, compParentNode);
- } else if (isSimpleNodeEvent(eventReader, event)) {
- newNode = resolveSimpleNodeFromStartElement(eventReader, startElement, compParentNode);
- }
-
- if (newNode != null) {
- processingQueue.push(newNode);
- if (compParentNode != null) {
- compParentNode.getValue().add(newNode);
- }
- }
- } else if (event.isEndElement()) {
- root = processingQueue.pop();
- if (root instanceof MutableCompositeNode) {
- ((MutableCompositeNode) root).init();
- }
- }
- }
- return root;
- }
-
- /**
- * Checks if the XMLEvent is compliant to SimpleNode tag that contains only
- * characters value. If the SimpleNode is composed only by empty XML tag
- * (i.e. {@code <emptyTag />} or {@code<emptyTag></emptyTag>}) the result
- * will be also <code>true</code>.
- *
- * @param event
- * actual XMLEvent that is processed
- * @return <code>true</code> only and only if the XMLEvent Start Element is
- * Simple element tag and contains character values or is empty XML
- * tag.
- * @throws XMLStreamException
- *
- * @see SimpleNode
- */
- private static boolean isSimpleNodeEvent(final XMLEventReader eventReader, final XMLEvent event) throws XMLStreamException {
- checkArgument(event != null, "XML Event cannot be NULL!");
- if (event.isStartElement()) {
- if (eventReader.hasNext()) {
- final XMLEvent innerEvent;
- innerEvent = eventReader.peek();
- if (innerEvent.isCharacters()) {
- final Characters chars = innerEvent.asCharacters();
- if (!chars.isWhiteSpace()) {
- return true;
- }
- } else if (innerEvent.isEndElement()) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Checks if XMLEvent is equivalent to CompositeNode Event. The
- * CompositeNode Event is XML element that conforms to the XML element that
- * contains 1..N XML child elements. (i.e. {@code <compositeNode>
- * <simpleNode>data</simpleNode>
- * </compositeNode>})
- *
- * @param event
- * actual XMLEvent that is processed
- * @return <code>true</code> only if XML Element contains 1..N child
- * elements, otherwise returns <code>false</code>
- * @throws XMLStreamException
- *
- * @see CompositeNode
- */
- private static boolean isCompositeNodeEvent(final XMLEventReader eventReader, final XMLEvent event) throws XMLStreamException {
- checkArgument(event != null, "XML Event cannot be NULL!");
- if (event.isStartElement()) {
- if (eventReader.hasNext()) {
- XMLEvent innerEvent;
- innerEvent = eventReader.peek();
- if (innerEvent.isCharacters()) {
- Characters chars = innerEvent.asCharacters();
- if (chars.isWhiteSpace()) {
- eventReader.nextEvent();
- innerEvent = eventReader.peek();
- }
- }
- if (innerEvent.isStartElement()) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Creates and returns <code>SimpleNode</code> instance from actually
- * processed XML Start Element.
- *
- * @param startElement
- * actual XML Start Element that is processed
- * @param parent
- * Parent CompositeNode
- * @return <code>new SimpleNode</code> instance from actually processed XML
- * Start Element
- * @throws XMLStreamException
- *
- * @see SimpleNode
- */
- private static SimpleNode<String> resolveSimpleNodeFromStartElement(final XMLEventReader eventReader,
- final StartElement startElement, final CompositeNode parent) throws XMLStreamException {
- checkArgument(startElement != null, "Start Element cannot be NULL!");
- String data = null;
-
- if (eventReader.hasNext()) {
- final XMLEvent innerEvent = eventReader.peek();
- if (innerEvent.isCharacters()) {
- final Characters chars = innerEvent.asCharacters();
- if (!chars.isWhiteSpace()) {
- data = innerEvent.asCharacters().getData();
- }
- } else if (innerEvent.isEndElement()) {
- data = "";
- }
- }
- return NodeFactory.createImmutableSimpleNode(resolveElementQName(startElement), parent, data);
- }
-
- /**
- * Creates and returns <code>MutableCompositeNode</code> instance from
- * actually processed XML Start Element.
- *
- * @param startElement
- * actual XML Start Element that is processed
- * @param parent
- * Parent CompositeNode
- * @return <code>new MutableCompositeNode</code> instance from actually
- * processed XML Start Element
- *
- * @see CompositeNode
- * @see MutableCompositeNode
- */
- private static MutableCompositeNode resolveCompositeNodeFromStartElement(final StartElement startElement,
- final CompositeNode parent) {
- checkArgument(startElement != null, "Start Element cannot be NULL!");
-
- return NodeFactory.createMutableCompositeNode(resolveElementQName(startElement), parent,
- new ArrayList<Node<?>>(), ModifyAction.CREATE, null);
- }
-
- /**
- * Extract and retrieve XML Element QName to OpenDaylight QName.
- *
- * @param element
- * Start Element
- * @return QName instance composed of <code>elements</code> Namespace and
- * Local Part.
- *
- * @see QName
- */
- private static QName resolveElementQName(final StartElement element) {
- checkArgument(element != null, "Start Element cannot be NULL!");
-
- final String nsURI = element.getName().getNamespaceURI();
- final String localName = element.getName().getLocalPart();
- return new QName(URI.create(nsURI), localName);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl.codec;
-
-import org.opendaylight.yangtools.yang.binding.BindingCodec;
-import org.opendaylight.yangtools.yang.data.api.Node;
-
-public interface DomCodec<I> extends BindingCodec<Node<?>, ValueWithQName<I>>{
- @Override
- Node<?> serialize(ValueWithQName<I> input);
-
- @Override
- ValueWithQName<I> deserialize(Node<?> input);
-}
*/
package org.opendaylight.yangtools.yang.data.impl.codec.xml;
-import static com.google.common.base.Preconditions.checkState;
-import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Set;
-import javax.activation.UnsupportedDataTypeException;
-import javax.annotation.Nonnull;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.dom.DOMResult;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl;
-import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType;
-import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
public final class XmlDocumentUtils {
throw new UnsupportedOperationException("Utility class should not be instantiated");
}
- private static class ElementWithSchemaContext {
- Element element;
- SchemaContext schemaContext;
-
- ElementWithSchemaContext(final Element element,final SchemaContext schemaContext) {
- this.schemaContext = schemaContext;
- this.element = element;
- }
-
- Element getElement() {
- return element;
- }
-
- SchemaContext getSchemaContext() {
- return schemaContext;
- }
- }
-
public static final QName OPERATION_ATTRIBUTE_QNAME = QName.create(SchemaContext.NAME, "operation");
- private static final QName RPC_REPLY_QNAME = QName.create(SchemaContext.NAME, "rpc-reply");
private static final Logger LOG = LoggerFactory.getLogger(XmlDocumentUtils.class);
- private static final XMLOutputFactory FACTORY = XMLOutputFactory.newFactory();
-
- /**
- * Converts Data DOM structure to XML Document for specified XML Codec Provider and corresponding
- * Data Node Container schema. The CompositeNode data parameter enters as root of Data DOM tree and will
- * be transformed to root in XML Document. Each element of Data DOM tree is compared against specified Data
- * Node Container Schema and transformed accordingly.
- *
- * @param data Data DOM root element
- * @param schemaNode Data Node Container Schema
- * @param codecProvider XML Codec Provider
- * @return new instance of XML Document
- * @throws UnsupportedDataTypeException
- *
- * @deprecated Use {@link #toDocument(org.opendaylight.yangtools.yang.data.api.CompositeNode, com.google.common.base.Optional, org.opendaylight.yangtools.yang.model.api.DataNodeContainer, XmlCodecProvider)} instead.
- * The whole schema context allows for proper serialization of leafrefs.
- */
- @Deprecated
- public static Document toDocument(final CompositeNode data, final DataNodeContainer schemaNode, final XmlCodecProvider codecProvider)
- throws UnsupportedDataTypeException {
- return toDocument(data, Optional.<SchemaContext>absent(), schemaNode, codecProvider);
- }
-
- /**
- * Serializes data DOM node into a w3c DOM document. Whole schema context is used to resolve leafref elements.
- *
- * @param data Data DOM root element
- * @param schemaContext Entire schema context for correct leafref resolution
- * @param schemaNode Data Node Container Schema
- * @param codecProvider XML Codec Provider
- * @return serialized w3c DOM document
- * @throws UnsupportedDataTypeException
- */
- public static Document toDocument(final CompositeNode data, final SchemaContext schemaContext, final DataNodeContainer schemaNode, final XmlCodecProvider codecProvider)
- throws UnsupportedDataTypeException {
- return toDocument(data, Optional.of(schemaContext), schemaNode, codecProvider);
- }
-
- private static Document toDocument(final CompositeNode data, final Optional<SchemaContext> schemaContext, final DataNodeContainer schema, final XmlCodecProvider codecProvider)
- throws UnsupportedDataTypeException {
- Preconditions.checkNotNull(data);
- Preconditions.checkNotNull(schema);
-
- if (!(schema instanceof ContainerSchemaNode || schema instanceof ListSchemaNode)) {
- throw new UnsupportedDataTypeException("Schema can be ContainerSchemaNode or ListSchemaNode. Other types are not supported yet.");
- }
-
- final DOMResult result = new DOMResult(getDocument());
- try {
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(result);
- XmlStreamUtils xmlStreamUtils = schemaContext.isPresent() ? XmlStreamUtils.create(codecProvider, schemaContext.get()) : XmlStreamUtils.create(codecProvider);
- xmlStreamUtils.writeDocument(writer, data, (SchemaNode) schema);
- writer.close();
- return (Document)result.getNode();
- } catch (XMLStreamException e) {
- LOG.error("Failed to serialize data {}", data, e);
- return null;
- }
- }
public static Document getDocument() {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
return doc;
}
- /**
- * Converts Data DOM structure to XML Document for specified XML Codec Provider. The CompositeNode
- * data parameter enters as root of Data DOM tree and will be transformed to root in XML Document. The child
- * nodes of Data Tree are transformed accordingly.
- *
- * @param data Data DOM root element
- * @param codecProvider XML Codec Provider
- * @return new instance of XML Document
- */
- public static Document toDocument(final CompositeNode data, final XmlCodecProvider codecProvider) {
- final DOMResult result = new DOMResult(getDocument());
- try {
- final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(result);
- XmlStreamUtils.create(codecProvider).writeDocument(writer, data);
- writer.close();
- return (Document)result.getNode();
- } catch (XMLStreamException e) {
- LOG.error("Failed to serialize data {}", data, e);
- return null;
- }
- }
-
private static final Element createElementFor(final Document doc, final QName qname, final Object obj) {
final Element ret;
if (qname.getNamespace() != null) {
return ret;
}
- public static Element createElementFor(final Document doc, final Node<?> data) {
- return createElementFor(doc, data.getNodeType(), data);
- }
-
public static Element createElementFor(final Document doc, final NormalizedNode<?, ?> data) {
return createElementFor(doc, data.getNodeType(), data);
}
- public static Node<?> toDomNode(final Element xmlElement, final Optional<DataSchemaNode> schema,
- final Optional<XmlCodecProvider> codecProvider) {
- return toDomNode(xmlElement, schema, codecProvider, Optional.<SchemaContext>absent());
- }
-
- public static Node<?> toDomNode(final Element xmlElement, final Optional<DataSchemaNode> schema,
- final Optional<XmlCodecProvider> codecProvider, final Optional<SchemaContext> schemaContext) {
- if (schema.isPresent()) {
- if(schemaContext.isPresent()) {
- return toNodeWithSchema(xmlElement, schema.get(), codecProvider.or(XmlUtils.DEFAULT_XML_CODEC_PROVIDER), schemaContext.get());
- } else {
- return toNodeWithSchema(xmlElement, schema.get(), codecProvider.or(XmlUtils.DEFAULT_XML_CODEC_PROVIDER));
- }
- }
- return toDomNode(xmlElement);
- }
-
public static QName qNameFromElement(final Element xmlElement) {
String namespace = xmlElement.getNamespaceURI();
String localName = xmlElement.getLocalName();
return QName.create(namespace != null ? URI.create(namespace) : null, null, localName);
}
- private static Node<?> toNodeWithSchema(final Element xmlElement, final DataSchemaNode schema, final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
- checkQName(xmlElement, schema.getQName());
- if (schema instanceof DataNodeContainer) {
- return toCompositeNodeWithSchema(xmlElement, schema.getQName(), (DataNodeContainer) schema, codecProvider,schemaCtx);
- } else if (schema instanceof LeafSchemaNode) {
- return toSimpleNodeWithType(xmlElement, (LeafSchemaNode) schema, codecProvider,schemaCtx);
- } else if (schema instanceof LeafListSchemaNode) {
- return toSimpleNodeWithType(xmlElement, (LeafListSchemaNode) schema, codecProvider,schemaCtx);
- } else if (schema instanceof AnyXmlSchemaNode) {
- return toDomNode(xmlElement);
- }
- return null;
- }
-
- private static Node<?> toNodeWithSchema(final Element xmlElement, final DataSchemaNode schema, final XmlCodecProvider codecProvider) {
- return toNodeWithSchema(xmlElement, schema, codecProvider, null);
- }
- protected static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafSchemaNode schema,
- final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
- final Object value = resolveValueFromSchemaType(xmlElement, schema, schema.getType(), codecProvider, schemaCtx);
- Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
- return new SimpleNodeTOImpl<>(schema.getQName(), null, value, modifyAction.orNull());
- }
-
- private static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafListSchemaNode schema,
- final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
- final Object value = resolveValueFromSchemaType(xmlElement, schema, schema.getType(), codecProvider, schemaCtx);
- Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
- return new SimpleNodeTOImpl<>(schema.getQName(), null, value, modifyAction.orNull());
- }
-
- private static Object resolveValueFromSchemaType(final Element xmlElement, final DataSchemaNode schema, final TypeDefinition<?> type,
- final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
-
- TypeDefinition<?> baseType = XmlUtils.resolveBaseTypeFrom(type);
- if (baseType instanceof LeafrefTypeDefinition) {
- final LeafrefTypeDefinition leafrefTypeDefinition = (LeafrefTypeDefinition) baseType;
- baseType = SchemaContextUtil.getBaseTypeForLeafRef(leafrefTypeDefinition, schemaCtx, schema);
- }
-
- final String text = xmlElement.getTextContent();
- final Object value;
-
- if (baseType instanceof InstanceIdentifierType) {
- value = InstanceIdentifierForXmlCodec.deserialize(xmlElement, schemaCtx);
- } else if (baseType instanceof IdentityrefTypeDefinition) {
- value = InstanceIdentifierForXmlCodec.toIdentity(text, xmlElement, schemaCtx);
- } else {
- final TypeDefinitionAwareCodec<?, ?> codec = codecProvider.codecFor(baseType);
- if (codec == null) {
- LOG.info("No codec for schema {}, falling back to text", schema);
- value = text;
- } else {
- value = codec.deserialize(text);
- }
- }
- return value;
- }
-
- private static Node<?> toCompositeNodeWithSchema(final Element xmlElement, final QName qName, final DataNodeContainer schema,
- final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
- List<Node<?>> values = toDomNodes(xmlElement, Optional.fromNullable(schema.getChildNodes()),schemaCtx);
- Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
- return ImmutableCompositeNode.create(qName, values, modifyAction.orNull());
- }
public static Optional<ModifyAction> getModifyOperationFromAttributes(final Element xmlElement) {
Attr attributeNodeNS = xmlElement.getAttributeNodeNS(OPERATION_ATTRIBUTE_QNAME.getNamespace().toString(), OPERATION_ATTRIBUTE_QNAME.getLocalName());
return Optional.of(action);
}
- private static void checkQName(final Element xmlElement, final QName qName) {
- checkState(Objects.equals(xmlElement.getNamespaceURI(), qName.getNamespace().toString()), "Not equal: %s to: %s for: %s and: %s", qName.getNamespace(), xmlElement.getNamespaceURI(), qName, xmlElement);
- checkState(qName.getLocalName().equals(xmlElement.getLocalName()), "Not equal: %s to: %s for: %s and: %s", qName.getLocalName(), xmlElement.getLocalName(), qName, xmlElement);
- }
public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Iterable<DataSchemaNode> dataSchemaNode) {
if (dataSchemaNode != null && qname != null) {
return Optional.absent();
}
- public static Node<?> toDomNode(final Document doc) {
- return toDomNode(doc.getDocumentElement());
- }
-
- private static Node<?> toDomNode(final Element element) {
- QName qname = qNameFromElement(element);
-
- ImmutableList.Builder<Node<?>> values = ImmutableList.<Node<?>> builder();
- NodeList nodes = element.getChildNodes();
- boolean isSimpleObject = true;
- String value = null;
- for (int i = 0; i < nodes.getLength(); i++) {
- org.w3c.dom.Node child = nodes.item(i);
- if (child instanceof Element) {
- isSimpleObject = false;
- values.add(toDomNode((Element) child));
- }
- if (isSimpleObject && child instanceof org.w3c.dom.Text) {
- value = element.getTextContent();
- if (!Strings.isNullOrEmpty(value)) {
- isSimpleObject = true;
- }
- }
- }
- if (isSimpleObject) {
- return new SimpleNodeTOImpl<>(qname, null, value);
- }
- return ImmutableCompositeNode.create(qname, values.build());
- }
-
- public static List<Node<?>> toDomNodes(final Element element, final Optional<? extends Iterable<DataSchemaNode>> context, final SchemaContext schemaCtx) {
- return forEachChild(element.getChildNodes(), schemaCtx, new Function<ElementWithSchemaContext, Optional<Node<?>>>() {
-
- @Override
- public Optional<Node<?>> apply(final @Nonnull ElementWithSchemaContext input) {
- if (context.isPresent()) {
- Preconditions.checkNotNull(input);
- QName partialQName = qNameFromElement(input.getElement());
- Optional<DataSchemaNode> schemaNode = findFirstSchema(partialQName, context.get());
- if (schemaNode.isPresent()) {
- return Optional.<Node<?>> fromNullable(
- toNodeWithSchema(input.getElement(), schemaNode.get(), XmlUtils.DEFAULT_XML_CODEC_PROVIDER, input.getSchemaContext()));
- }
- }
- return Optional.<Node<?>> fromNullable(toDomNode(input.getElement()));
- }
-
- });
- }
-
- public static List<Node<?>> toDomNodes(final Element element, final Optional<? extends Iterable<DataSchemaNode>> context) {
- return toDomNodes(element, context, null);
- }
-
- /**
- * Converts XML Document containing notification data from Netconf device to
- * Data DOM Nodes. <br>
- * By specification defined in <a
- * href="http://tools.ietf.org/search/rfc6020#section-7.14">RFC 6020</a>
- * there are xml elements containing notifications metadata, like eventTime
- * or root notification element which specifies namespace for which is
- * notification defined in yang model. Those elements MUST be stripped off
- * notifications body. This method returns pure notification body which
- * begins in element which is equal to notifications name defined in
- * corresponding yang model. Rest of notification metadata are obfuscated,
- * thus Data DOM contains only pure notification body.
- *
- * @param document
- * XML Document containing notification body
- * @param notifications
- * Notifications Definition Schema
- * @return Data DOM Nodes containing xml notification body definition or
- * <code>null</code> if there is no NotificationDefinition with
- * Element with equal notification QName defined in XML Document.
- */
- public static CompositeNode notificationToDomNodes(final Document document,
- final Optional<Set<NotificationDefinition>> notifications, final SchemaContext schemaCtx) {
- if (notifications.isPresent() && (document != null) && (document.getDocumentElement() != null)) {
- final NodeList originChildNodes = document.getDocumentElement().getChildNodes();
- for (int i = 0; i < originChildNodes.getLength(); i++) {
- org.w3c.dom.Node child = originChildNodes.item(i);
- if (child instanceof Element) {
- final Element childElement = (Element) child;
- final QName partialQName = qNameFromElement(childElement);
- final Optional<NotificationDefinition> notificationDef = findNotification(partialQName,
- notifications.get());
- if (notificationDef.isPresent()) {
- final Iterable<DataSchemaNode> dataNodes = notificationDef.get().getChildNodes();
- final List<Node<?>> domNodes = toDomNodes(childElement,
- Optional.<Iterable<DataSchemaNode>> fromNullable(dataNodes),schemaCtx);
- return ImmutableCompositeNode.create(notificationDef.get().getQName(), domNodes);
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Transforms XML Document representing Rpc output body into Composite Node structure based on Rpc definition
- * within given Schema Context. The transformation is based on Rpc Definition which is defined in provided Schema Context.
- * If Rpc Definition is missing from given Schema Context the method will return <code>null</code>
- *
- * @param document XML Document containing Output RPC message
- * @param rpcName Rpc QName
- * @param context Schema Context
- * @return Rpc message in Composite Node data structures if Rpc definition is present within provided Schema Context, otherwise
- * returns <code>null</code>
- */
- public static CompositeNode rpcReplyToDomNodes(final Document document, final QName rpcName,
- final SchemaContext context) {
- Preconditions.checkNotNull(document);
- Preconditions.checkNotNull(rpcName);
- Preconditions.checkNotNull(context);
-
- Optional<RpcDefinition> rpcDefinition = findRpc(rpcName, context);
- if (rpcDefinition.isPresent()) {
- RpcDefinition rpc = rpcDefinition.get();
-
- final Collection<DataSchemaNode> outputNode = rpc.getOutput() != null ? rpc.getOutput().getChildNodes() : null;
- final Element rpcReplyElement = document.getDocumentElement();
- final QName partialQName = qNameFromElement(rpcReplyElement);
-
- if (RPC_REPLY_QNAME.equals(partialQName)) {
- final List<Node<?>> domNodes = toDomNodes(rpcReplyElement, Optional.fromNullable(outputNode), context);
- QName qName = rpc.getOutput() != null ? rpc.getOutput().getQName() : QName.cachedReference(QName.create(rpcName, "output"));
- List<Node<?>> rpcOutNodes = Collections.<Node<?>>singletonList(ImmutableCompositeNode.create(
- qName, domNodes));
- return ImmutableCompositeNode.create(rpcName, rpcOutNodes);
- }
- }
- return null;
- }
-
- /**
- * Method searches given schema context for Rpc Definition with given QName.
- * Returns Rpc Definition if is present within given Schema Context, otherwise returns Optional.absent().
- *
- * @param rpc Rpc QName
- * @param context Schema Context
- * @return Rpc Definition if is present within given Schema Context, otherwise returns Optional.absent().
- */
- private static Optional<RpcDefinition> findRpc(final QName rpc, final SchemaContext context) {
- Preconditions.checkNotNull(rpc);
- Preconditions.checkNotNull(context);
- for (final RpcDefinition rpcDefinition : context.getOperations()) {
- if ((rpcDefinition != null) && rpc.equals(rpcDefinition.getQName())) {
- return Optional.of(rpcDefinition);
- }
- }
- return Optional.absent();
- }
-
- public static CompositeNode notificationToDomNodes(final Document document,
- final Optional<Set<NotificationDefinition>> notifications) {
- return notificationToDomNodes(document, notifications,null);
- }
-
- private static Optional<NotificationDefinition> findNotification(final QName notifName,
- final Set<NotificationDefinition> notifications) {
- if ((notifName != null) && (notifications != null)) {
- for (final NotificationDefinition notification : notifications) {
- if ((notification != null) && notifName.isEqualWithoutRevision(notification.getQName())) {
- return Optional.<NotificationDefinition>fromNullable(notification);
- }
- }
- }
- return Optional.<NotificationDefinition>absent();
- }
-
- private static final <T> List<T> forEachChild(final NodeList nodes, final SchemaContext schemaContext, final Function<ElementWithSchemaContext, Optional<T>> forBody) {
- final int l = nodes.getLength();
- if (l == 0) {
- return ImmutableList.of();
- }
-
- final List<T> list = new ArrayList<>(l);
- for (int i = 0; i < l; i++) {
- org.w3c.dom.Node child = nodes.item(i);
- if (child instanceof Element) {
- Optional<T> result = forBody.apply(new ElementWithSchemaContext((Element) child,schemaContext));
- if (result.isPresent()) {
- list.add(result.get());
- }
- }
- }
- return ImmutableList.copyOf(list);
- }
-
public static final XmlCodecProvider defaultValueCodecProvider() {
return XmlUtils.DEFAULT_XML_CODEC_PROVIDER;
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.net.URI;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec;
-import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
return new XmlStreamUtils(codecProvider);
}
- /**
- * Check if a particular data element can be emitted as an empty element, bypassing value encoding. This
- * functionality is optional, as valid XML stream is produced even if start/end element is produced unconditionally.
- *
- * @param data Data node
- * @return True if the data node will result in empty element body.
- */
- public static boolean isEmptyElement(final Node<?> data) {
- if (data == null) {
- return true;
- }
-
- if (data instanceof CompositeNode) {
- return ((CompositeNode) data).getValue().isEmpty();
- }
- if (data instanceof SimpleNode) {
- return data.getValue() == null;
- }
-
- // Safe default
- return false;
- }
-
/**
* Write an InstanceIdentifier into the output stream. Calling corresponding {@link XMLStreamWriter#writeStartElement(String)}
* and {@link XMLStreamWriter#writeEndElement()} is the responsibility of the caller.
writer.writeCharacters(str);
}
- /**
- * Write a full XML document corresponding to a CompositeNode into an XML stream writer.
- *
- * @param writer XML Stream writer
- * @param data data node
- * @param schema corresponding schema node, may be null
- * @throws XMLStreamException if an encoding problem occurs
- */
- public void writeDocument(final @Nonnull XMLStreamWriter writer, final @Nonnull CompositeNode data, final @Nullable SchemaNode schema) throws XMLStreamException {
- // final Boolean repairing = (Boolean) writer.getProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
- // Preconditions.checkArgument(repairing == true, "XML Stream Writer has to be repairing namespaces");
-
- writer.writeStartDocument();
- writeElement(writer, data, schema);
- writer.writeEndDocument();
- writer.flush();
- }
-
- /**
- * Short-hand for {@link #writeDocument(XMLStreamWriter, CompositeNode, SchemaNode)})} with
- * null SchemaNode.
- *
- * @param writer XML Stream writer
- * @param data data node
- * @throws XMLStreamException if an encoding problem occurs
- */
- public void writeDocument(final XMLStreamWriter writer, final CompositeNode data) throws XMLStreamException {
- writeDocument(writer, data, null);
- }
-
- /**
- * Write an element into a XML stream writer. This includes the element start/end tags and
- * the value of the element.
- *
- * @param writer XML Stream writer
- * @param data data node
- * @param schema Schema node
- * @throws XMLStreamException if an encoding problem occurs
- */
- public void writeElement(final XMLStreamWriter writer, final @Nonnull Node<?> data, final SchemaNode schema) throws XMLStreamException {
- final QName qname = data.getNodeType();
- final String ns = qname.getNamespace() != null ? qname.getNamespace().toString() : "";
- final String pfx = "";
-
- if (isEmptyElement(data)) {
- if (hasAttributes(data)) {
- writer.writeStartElement(pfx, qname.getLocalName(), ns);
- final RandomPrefix randomPrefix = new RandomPrefix();
- writeAttributes(writer, (AttributesContainer) data, randomPrefix);
- writer.writeEndElement();
- } else {
- writer.writeEmptyElement(pfx, qname.getLocalName(), ns);
- }
- return;
- }
-
- writer.writeStartElement(pfx, qname.getLocalName(), ns);
- writeValue(writer, data, schema);
- writer.writeEndElement();
- }
-
- /**
- * Write a value into a XML stream writer. This method assumes the start and end of element is
- * emitted by the caller.
- *
- * @param writer XML Stream writer
- * @param data data node
- * @param schema Schema node
- * @throws XMLStreamException if an encoding problem occurs
- */
- public void writeValue(final XMLStreamWriter writer, final @Nonnull Node<?> data, final SchemaNode schema) throws XMLStreamException {
- if (hasAttributes(data)) {
- RandomPrefix randomPrefix = new RandomPrefix();
- writeAttributes(writer, (AttributesContainer) data, randomPrefix);
- }
-
- if (data instanceof SimpleNode<?>) {
- // Simple node
- if (schema instanceof LeafListSchemaNode || schema instanceof LeafSchemaNode) {
- writeValue(writer, schema, data.getValue());
- } else {
- Object value = data.getValue();
- if (value != null) {
- writer.writeCharacters(String.valueOf(value));
- }
- }
- } else {
- // CompositeNode
- final CompositeNode castedData = ((CompositeNode) data);
- final DataNodeContainer castedSchema;
- if (schema instanceof DataNodeContainer) {
- castedSchema = (DataNodeContainer) schema;
- } else {
- castedSchema = null;
- }
- final Collection<QName> keyLeaves;
- if (schema instanceof ListSchemaNode) {
- keyLeaves = ((ListSchemaNode) schema).getKeyDefinition();
-
- } else {
- keyLeaves = Collections.emptyList();
-
- }
- for (QName key : keyLeaves) {
- SimpleNode<?> keyLeaf = castedData.getFirstSimpleByName(key);
- if(keyLeaf != null) {
- writeChildElement(writer,keyLeaf,castedSchema);
- }
- }
-
- for (Node<?> child : castedData.getValue()) {
- if(keyLeaves.contains(child.getNodeType())) {
- // Skip key leaf which was written by previous for loop.
- continue;
- }
- writeChildElement(writer,child,castedSchema);
- }
- }
- }
-
- private void writeChildElement(final XMLStreamWriter writer, final Node<?> child, final DataNodeContainer parentSchema) throws XMLStreamException {
- DataSchemaNode childSchema = null;
- if (parentSchema != null) {
- childSchema = SchemaUtils.findFirstSchema(child.getNodeType(), parentSchema.getChildNodes()).orNull();
- if ((childSchema == null) && LOG.isDebugEnabled()) {
- LOG.debug("Probably the data node \"{}\" does not conform to schema", child == null ? "" : child.getNodeType().getLocalName());
- }
- }
- writeElement(writer, child, childSchema);
- }
-
- private static void writeAttributes(final XMLStreamWriter writer, final AttributesContainer data, final RandomPrefix randomPrefix) throws XMLStreamException {
- for (Entry<QName, String> attribute : data.getAttributes().entrySet()) {
- writeAttribute(writer, attribute, randomPrefix);
- }
- }
-
- private static boolean hasAttributes(final Node<?> data) {
- if (data instanceof AttributesContainer) {
- final Map<QName, String> c = ((AttributesContainer) data).getAttributes();
- return c != null && !c.isEmpty();
- } else {
- return false;
- }
- }
-
@VisibleForTesting
static void writeAttribute(final XMLStreamWriter writer, final Entry<QName, String> attribute, final RandomPrefix randomPrefix)
throws XMLStreamException {
+++ /dev/null
-/*
- * Copyright (c) 2013 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.util;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.collect.Iterables;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
-
-/**
- * @deprecated Use one of the {@link NormalizedNodeContainerBuilder} implementations.
- */
-@Deprecated
-public abstract class AbstractCompositeNodeBuilder<P extends CompositeNode> extends AbstractNodeBuilder<P, CompositeNodeBuilder<P>> implements CompositeNodeBuilder<P> {
-
- final List<Node<?>> childNodes;
-
- public AbstractCompositeNodeBuilder() {
- super();
- childNodes = new ArrayList<>();
- }
-
- public AbstractCompositeNodeBuilder(final QName nodeType, final Map<QName, String> attributes) {
- super(nodeType, attributes);
- childNodes = new ArrayList<>();
- }
-
- public AbstractCompositeNodeBuilder(final QName nodeType, final Iterable<? extends Node<?>> nodes) {
- super(nodeType);
- childNodes = new ArrayList<>();
- }
-
- @Override
- public AbstractCompositeNodeBuilder<P> add(final Node<?> node) {
- childNodes.add(checkNotNull(node, "Node should not be null"));
- return this;
- }
-
- @Override
- public AbstractCompositeNodeBuilder<P> addAll(final Iterable<? extends Node<?>> nodes) {
- Iterables.addAll(childNodes, checkNotNull(nodes, "Node should not be null"));
- return this;
- }
-
- @Override
- public CompositeNodeBuilder<P> addLeaf(final String leafLocalName, final String leafValue) {
- return addLeaf(QName.create(getQName(), leafLocalName), leafValue);
- }
-
- public List<Node<?>> getChildNodes() {
- return childNodes;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.util;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
-
-public abstract class AbstractNodeBuilder<P extends Node<?>, T extends NodeBuilder<P, T>> implements NodeBuilder<P, T> {
-
- private final Map<QName, String> attributes;
- private QName qName;
-
- public AbstractNodeBuilder() {
- this.attributes = new ConcurrentHashMap<>();
- }
-
- public AbstractNodeBuilder(QName nodeType, Map<QName, String> attributes) {
- super();
- this.qName = nodeType;
- this.attributes = new ConcurrentHashMap<>(attributes);
- }
-
- public AbstractNodeBuilder(QName nodeType) {
- this.qName = nodeType;
- this.attributes = new ConcurrentHashMap<>();
- }
-
- @SuppressWarnings("unchecked")
- protected final T thisInstance() {
- return (T) this;
- }
-
- @Override
- public final T setQName(QName name) {
- this.qName = name;
- return thisInstance();
- }
-
- public QName getQName() {
- return qName;
- }
-
- @Override
- public final T setAttribute(QName attrName, String attrValue) {
- attributes.put(attrName, attrValue);
- return thisInstance();
- }
-
- public Map<QName, String> getAttributes() {
- return attributes;
- }
-
- @Override
- public T setAttribute(String attrName, String attrValue) {
- attributes.put(QName.create(qName, attrName), attrValue);
- return thisInstance();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.util;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-
-/*
- * @deprecated Use one of the NormalizedNode builders instead.
- */
-@Deprecated
-public interface CompositeNodeBuilder<P extends CompositeNode> extends NodeBuilder<P,CompositeNodeBuilder<P>> {
-
- CompositeNodeBuilder<P> addLeaf(QName leafName,Object leafValue);
- CompositeNodeBuilder<P> add(Node<?> node);
- CompositeNodeBuilder<P> addAll(Iterable<? extends Node<?>> nodes);
- CompositeNodeBuilder<P> addLeaf(String leafLocalName, String leafValue);
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.util;
-
-import org.opendaylight.yangtools.concepts.Builder;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
-
-public interface NodeBuilder<P extends Node<?>, T extends NodeBuilder<P, T>> extends Builder<P> {
-
- T setQName(QName name);
-
- QName getQName();
-
- T setAttribute(QName attrName, String attrValue);
-
- T setAttribute(String attrName, String attrValue);
-
- /**
- * @deprecated use {@link #build()}.
- */
- @Deprecated
- P toInstance();
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.codec.xml.test;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-/**
- *
- * @author Lukas Sedlak <lsedlak@cisco.com>
- */
-public class RpcReplyToDomTest {
-
- private static final DocumentBuilderFactory BUILDER_FACTORY;
- private static final String RES_SCHEMA_DIR = "/org/opendaylight/yangtools/yang/data/impl/schema";
-
- private final static String MODEL_NAMESPACE = "org:opendaylight:rpc-reply:test:ns:yang";
- private final static String MODEL_REVISION = "2014-07-17";
-
- private final static QName RPC_OUTPUT_QNAME = QName.create(MODEL_NAMESPACE, MODEL_REVISION, "output");
- private final static QName ROCK_THE_HOUSE_QNAME = QName.create(MODEL_NAMESPACE, MODEL_REVISION, "rock-the-house");
- private final static QName ACTIV_SW_IMAGE_QNAME = QName.create(MODEL_NAMESPACE, MODEL_REVISION, "activate-software-image");
-
- private SchemaContext schemaContext;
- private Document testPayload1;
- private Document testPayload2;
-
- static {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- factory.setCoalescing(true);
- factory.setIgnoringElementContentWhitespace(true);
- factory.setIgnoringComments(true);
- BUILDER_FACTORY = factory;
- }
-
- @Before
- public void setup() throws Exception {
- final List<InputStream> modelsToParse = Collections
- .singletonList(getClass().getResourceAsStream(RES_SCHEMA_DIR + "/rpc-test-model.yang"));
- assertNotNull(modelsToParse);
- assertNotNull(modelsToParse.get(0));
-
- final YangContextParser parser = new YangParserImpl();
- final Set<Module> modules = parser.parseYangModelsFromStreams(modelsToParse);
- assertTrue(!modules.isEmpty());
- schemaContext = parser.resolveSchemaContext(modules);
- assertNotNull(schemaContext);
-
- final InputStream rpcPayloadStream1 = getClass().getResourceAsStream(RES_SCHEMA_DIR + "/rpc-test-payload1.xml");
- InputStream rpcPayloadStream2 = getClass().getResourceAsStream(RES_SCHEMA_DIR + "/rpc-test-payload2.xml");
-
- assertNotNull(rpcPayloadStream1);
- assertNotNull(rpcPayloadStream2);
-
- testPayload1 = readXmlToDocument(rpcPayloadStream1);
- testPayload2 = readXmlToDocument(rpcPayloadStream2);
-
- assertNotNull(testPayload1);
- assertNotNull(testPayload2);
- }
-
- private static Document readXmlToDocument(final InputStream xmlContent) throws SAXException, IOException {
- DocumentBuilder dBuilder;
- try {
- dBuilder = BUILDER_FACTORY.newDocumentBuilder();
- } catch (ParserConfigurationException e) {
- throw new IllegalStateException("Failed to parse XML document", e);
- }
- Document doc = dBuilder.parse(xmlContent);
-
- doc.getDocumentElement().normalize();
- return doc;
- }
-
- @Test
- public void test() {
- final CompositeNode rockNode = XmlDocumentUtils
- .rpcReplyToDomNodes(testPayload1, ROCK_THE_HOUSE_QNAME, schemaContext);
- assertNotNull(rockNode);
-
- final String namespace = "org:opendaylight:rpc-reply:test:ns:yang";
- final String revision = "2014-07-17";
-
- CompositeNode output = rockNode.getFirstCompositeByName(RPC_OUTPUT_QNAME);
- assertNotNull(output);
-
- final SimpleNode<?> zipCode = output.getFirstSimpleByName(
- QName.create(namespace, revision, "zip-code"));
- assertNotNull(zipCode);
-
- final CompositeNode activNode = XmlDocumentUtils
- .rpcReplyToDomNodes(testPayload2, ACTIV_SW_IMAGE_QNAME, schemaContext);
- assertNotNull(activNode);
-
- output = activNode.getFirstCompositeByName(RPC_OUTPUT_QNAME);
- assertNotNull(output);
-
- final CompositeNode imgProps = output
- .getFirstCompositeByName(QName.create(namespace, revision, "image-properties"));
- assertNotNull(imgProps);
- final CompositeNode imgProperty = imgProps
- .getFirstCompositeByName(QName.create(namespace, revision, "image-property"));
- assertNotNull(imgProperty);
-
- final SimpleNode<?> imgId = imgProperty
- .getFirstSimpleByName(QName.create(namespace, revision, "image-id"));
- assertNotNull(imgId);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.lang.SerializationUtils;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.Node;
-
-@Deprecated
-public class CompositeNodeTOImplTest {
- @Test
- public void testSerialization() throws Exception{
- CompositeNodeTOImpl child1 = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "child1"), null, new ArrayList<Node<?>>(), ModifyAction.REPLACE);
- CompositeNodeTOImpl child2 = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "child2"), null, new ArrayList<Node<?>>(), ModifyAction.REPLACE);
- SimpleNodeTOImpl child3 = new SimpleNodeTOImpl(QName.create("ns", "2013-12-09", "child2"), null, "foo");
-
- List<Node<?>> children = new ArrayList<Node<?>>();
- children.add(child1);
- children.add(child2);
- children.add(child3);
-
- CompositeNodeTOImpl parent = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "parent"), null, new ArrayList<Node<?>>(), ModifyAction.REPLACE);
-
- CompositeNodeTOImpl object = new CompositeNodeTOImpl(QName.create("ns", "2013-12-09", "root"), parent, children , ModifyAction.MERGE);
-
- CompositeNodeTOImpl clone = (CompositeNodeTOImpl) SerializationUtils.clone(object);
-
- assertNotNull(clone.getNodeType());
- assertEquals(ModifyAction.MERGE, clone.getModificationAction());
- assertNotNull(clone.getParent());
- assertNotNull(clone.getParent().getNodeType());
- assertNotNull(clone.getValue());
- assertEquals(3, clone.getValue().size());
- assertNotNull(clone.getValue().get(0).getNodeType());
- assertNotNull(clone.getValue().get(1).getNodeType());
-
- SimpleNodeTOImpl child3Clone = (SimpleNodeTOImpl) clone.getValue().get(2);
-
- assertNotNull(child3Clone.getNodeType());
- assertTrue(child3Clone instanceof SimpleNodeTOImpl);
- assertEquals("foo", child3Clone.getValue());
-
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.net.URI;
-import java.util.Date;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-
-/**
- * @author michal.rehak
- *
- */
-@Deprecated
-public class LazyNodeToNodeMapTest {
-
- private LazyNodeToNodeMap lazyN2N;
- private CompositeNode tree;
-
- /**
- * prepare test values
- * @throws Exception
- */
- @Before
- public void setUp() throws Exception {
- lazyN2N = new LazyNodeToNodeMap();
-
- QName qName = QName.create(
- new URI("urn:ietf:params:xml:ns:netconf:base:1.0"),
- new Date(42), "yang-data-impl-mutableTest");
-
- tree = NodeHelper.buildTestConfigTree(qName);
- }
-
- /**
- * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)}.
- */
- @Test
- public void testGetMutableEquivalent() {
- MutableCompositeNode mutableTree = (MutableCompositeNode) lazyN2N.getMutableEquivalent(tree);
-
- Assert.assertNull(mutableTree.getParent());
- Assert.assertEquals(tree.getNodeType(), mutableTree.getNodeType());
- Assert.assertEquals(1, lazyN2N.getKeyNodes().size());
-
- Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
- Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
-
- Assert.assertNotNull(subMutant.getParent());
- Assert.assertEquals(subNode.getNodeType(), subMutant.getNodeType());
- Assert.assertEquals(2, lazyN2N.getKeyNodes().size());
-
- Assert.assertEquals(mutableTree, subMutant.getParent());
- Assert.assertEquals(mutableTree.getValue().size(), 1);
- Assert.assertEquals(mutableTree.getValue().iterator().next(), subMutant);
- }
-
- /**
- * Test method for {@link org.opendaylight.yangtools.yang.data.impl.LazyNodeToNodeMap#getMutableRoot()}.
- */
- @Test
- public void testGetMutableRoot() {
- Node<?> subNode = tree.getCompositesByName("topologies").iterator().next();
- Node<?> subMutant = lazyN2N.getMutableEquivalent(subNode);
-
- Assert.assertNotNull(subMutant.getParent());
- Assert.assertEquals(subMutant.getParent(), lazyN2N.getMutableRoot());
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import groovy.util.BuilderSupport;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Date;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author michal.rehak
- */
-@Deprecated
-public class MyNodeBuilder extends BuilderSupport {
-
- private static final Logger LOG = LoggerFactory.getLogger(MyNodeBuilder.class);
-
- private URI qnNamespace;
- private final Date qnRevision;
-
- private CompositeNode rootNode;
-
- /**
- * @param baseQName
- */
- private MyNodeBuilder(final QName baseQName) {
- qnNamespace = baseQName.getNamespace();
- qnRevision = baseQName.getRevision();
- }
-
- /**
- * @return initialized singleton instance
- */
- public static MyNodeBuilder newInstance() {
- QName qName = null;
- try {
- qName = QName.create(
- new URI("urn:opendaylight:controller:network"),
- new Date(42), "node");
- } catch (URISyntaxException e) {
- LOG.error(e.getMessage(), e);
- }
- return new MyNodeBuilder(qName);
- }
-
- @Override
- protected void setParent(final Object parent, final Object child) {
- // do nothing
- if (child instanceof AbstractNodeTO<?>) {
- ((AbstractNodeTO<?>) child).setParent((CompositeNode) parent);
- } else {
- LOG.error("PARENTING FAILED: "+parent + " -> " + child);
- }
- }
-
- @Override
- protected Object createNode(final Object name) {
- MutableCompositeNode newNode = NodeFactory.createMutableCompositeNode(
- createQName(name), getCurrentNode(), null, null, null);
- NodeUtils.fixParentRelation(newNode);
- return newNode;
- }
-
- @Override
- protected Object createNode(final Object name, @SuppressWarnings("rawtypes") final Map attributes) {
- ModifyAction modifyAction = processAttributes(attributes);
- MutableCompositeNode newNode = NodeFactory.createMutableCompositeNode(
- createQName(name), getCurrentNode(), null, modifyAction, null);
- NodeUtils.fixParentRelation(newNode);
- return newNode;
- }
-
-
- @Override
- protected Object createNode(final Object name, @SuppressWarnings("rawtypes") final Map attributes, final Object value) {
- ModifyAction modifyAction = processAttributes(attributes);
- SimpleNode<Object> newNode = NodeFactory.createImmutableSimpleNode(
- createQName(name), (CompositeNode) getCurrent(), value, modifyAction);
- NodeUtils.fixParentRelation(newNode);
- return newNode;
- }
-
- /**
- * @param attributes
- * @return
- */
- private ModifyAction processAttributes(@SuppressWarnings("rawtypes") final Map attributes) {
- LOG.debug("attributes:" + attributes);
- ModifyAction modAction = null;
-
- @SuppressWarnings("unchecked")
- Map<String, String> attributesSane = attributes;
- for (Entry<String, String> attr : attributesSane.entrySet()) {
- switch (attr.getKey()) {
- case "xmlns":
- try {
- qnNamespace = new URI(attr.getValue());
- } catch (URISyntaxException e) {
- LOG.error(e.getMessage(), e);
- }
- break;
- case "modifyAction":
- modAction = ModifyAction.valueOf(attr.getValue());
- break;
-
- default:
- throw new IllegalArgumentException("Attribute not supported: "+attr.getKey());
- }
- }
- return modAction;
- }
-
- @Override
- protected Object createNode(final Object name, final Object value) {
- SimpleNode<Object> newNode = NodeFactory.createImmutableSimpleNode(createQName(name), (CompositeNode) getCurrent(), value);
- NodeUtils.fixParentRelation(newNode);
- return newNode;
- }
-
- private QName createQName(final Object localName) {
- LOG.debug("qname for: "+localName);
- return QName.create(qnNamespace, qnRevision, (String) localName);
- }
-
- protected CompositeNode getCurrentNode() {
- if (getCurrent() != null) {
- if (getCurrent() instanceof CompositeNode) {
- return (CompositeNode) getCurrent();
-
- } else {
- throw new IllegalAccessError("current node is not of type CompositeNode, but: "
- +getCurrent().getClass().getSimpleName());
- }
- }
-
- return null;
- }
-
- @Override
- protected Object postNodeCompletion(final Object parent, final Object node) {
- Node<?> nodeRevisited = (Node<?>) node;
- LOG.debug("postNodeCompletion at: \n "+ nodeRevisited+"\n "+parent);
- if (nodeRevisited instanceof MutableCompositeNode) {
- MutableCompositeNode mutant = (MutableCompositeNode) nodeRevisited;
- if (mutant.getValue().isEmpty()) {
- LOG.error("why is it having empty value? -- " + mutant);
- }
- nodeRevisited = NodeFactory.createImmutableCompositeNode(
- mutant.getNodeType(), mutant.getParent(), mutant.getValue(), mutant.getModificationAction());
- NodeUtils.fixChildrenRelation((CompositeNode) nodeRevisited);
-
- if (parent == null) {
- rootNode = (CompositeNode) nodeRevisited;
- } else {
- NodeUtils.fixParentRelation(nodeRevisited);
- nodeRevisited.getParent().getValue().remove(mutant);
- }
- }
-
-
- return nodeRevisited;
- }
-
- /**
- * @return tree root
- */
- public CompositeNode getRootNode() {
- return rootNode;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.NodeModification;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.w3c.dom.Document;
-
-/**
- * @author michal.rehak
- *
- */
-@Deprecated
-public class NodeFactoryTest {
-
- private QName qName;
- private CompositeNode network;
-
- private String ns;
- private Document networkShadow;
-
-
- /**
- * @throws Exception
- */
- @Before
- public void setUp() throws Exception {
- ns = "urn:ietf:params:xml:ns:netconf:base:1.0";
- qName = QName.create(
- new URI(ns),
- new Date(42), "node");
- network = NodeHelper.buildTestConfigTree(qName);
- networkShadow = NodeUtils.buildShadowDomTree(network);
- NodeHelper.compareXmlTree(networkShadow, "./config02-shadow.xml", getClass());
- }
-
- /**
- * Test method for methods creating immutable nodes in
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeFactory}.
- * @throws Exception
- */
- @Test
- public void testImmutableNodes() throws Exception {
- Assert.assertEquals(2, network.getValue().size());
- CompositeNode tpList = NodeUtils.findNodeByXpath(networkShadow,
- NodeHelper.AddNamespaceToPattern(
- "//{0}node[{0}node-id/text()='nodeId_19']/{0}termination-points", ns));
-
-
- Assert.assertEquals(2, tpList.getCompositesByName("termination-point").size());
- }
-
- /**
- * Test method for methods creating immutable and mutable nodes:
- * {@link NodeFactory#createMutableCompositeNode(QName, CompositeNode, List, ModifyAction, CompositeNode)},
- * {@link NodeFactory#createMutableSimpleNode(QName, CompositeNode, Object, ModifyAction, SimpleNode)}
- * @throws Exception
- */
- @Test
- public void testMutableNodes() throws Exception {
- // <config>
- // <top xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
- // <interface xc:operation="delete">
- // <name>Ethernet0/0</name>
- // <mtu>1500</mtu>
- // </interface>
- // <interface>
- // <name>Ethernet0/1</name>
- // <mtu>1501</mtu>
- // </interface>
- // </top>
- // </config>
-
-
- List<Node<?>> value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "name"), null, "Ethernet0/0"));
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "mtu"), null, 1500));
-
- MutableCompositeNode ifNode = NodeFactory.createMutableCompositeNode(
- QName.create(qName, "interface"), null,
- value, ModifyAction.DELETE, null);
- ifNode.init();
- NodeHelper.assignParentToChildren(ifNode);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "name"), null, "Ethernet1/0"));
- value.add(NodeFactory.createMutableSimpleNode(QName.create(qName, "mtu"), null, 1501, ModifyAction.REMOVE, null));
-
- CompositeNode ifNode2 = NodeFactory.createImmutableCompositeNode(QName.create(qName, "interface"), null, value);
- NodeHelper.assignParentToChildren(ifNode2);
-
- value = new ArrayList<Node<?>>();
- value.add(ifNode);
- value.add(ifNode2);
-
- CompositeNode topNode = NodeFactory.createImmutableCompositeNode(QName.create(qName, "top"), null, value);
- NodeHelper.assignParentToChildren(topNode);
- value = new ArrayList<Node<?>>();
- value.add(topNode);
-
- CompositeNode root = NodeFactory.createImmutableCompositeNode(QName.create(qName, "config"), null, value);
- Document shadowConfig = NodeUtils.buildShadowDomTree(root);
- NodeHelper.compareXmlTree(shadowConfig, "./mutableNodesConfig.xml", getClass());
-
- Assert.assertEquals(1, root.getValue().size());
- Assert.assertEquals(1, ifNode.getSimpleNodesByName("name").size());
- Assert.assertEquals(1, ifNode.getSimpleNodesByName("mtu").size());
- Assert.assertEquals(2, topNode.getCompositesByName("interface").size());
- NodeModification interfaceMod = topNode.getCompositesByName("interface").get(0);
- Assert.assertEquals(ModifyAction.DELETE, interfaceMod.getModificationAction());
- }
-
- /**
- * test of {@link NodeFactory#copyDeepAsMutable(CompositeNode, Map)}
- * @throws Exception
- */
- @Test
- public void testCopyDeepAsMutable() throws Exception {
- Map<Node<?>, Node<?>> mutableToOrig = new HashMap<>();
- CompositeNode mutableNetwork = NodeFactory.copyDeepAsMutable(network, mutableToOrig);
-
- Document mutableNetworkShadow = NodeUtils.buildShadowDomTree(mutableNetwork);
-
- NodeHelper.compareXmlTree(mutableNetworkShadow, "./config02-shadow.xml", getClass());
-
- CompositeNode immutableNetwork = NodeFactory.copyDeepAsImmutable(mutableNetwork, null);
- Assert.assertEquals(network, immutableNetwork);
- }
-
-
- /**
- * test of {@link NodeFactory#copyDeepAsImmutable(CompositeNode, Map)}
- * @throws Exception
- */
- @Test
- public void testCopyDeepAsImmutable() throws Exception {
- Map<Node<?>, Node<?>> mutableToOrig = new HashMap<>();
- CompositeNode immutableNetwork = NodeFactory.copyDeepAsImmutable(network, mutableToOrig);
-
- Document mutableNetworkShadow = NodeUtils.buildShadowDomTree(immutableNetwork);
- NodeHelper.compareXmlTree(mutableNetworkShadow, "./config02-shadow.xml", getClass());
-
- Assert.assertEquals(network, immutableNetwork);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import groovy.lang.Binding;
-import groovy.lang.GroovyShell;
-import groovy.lang.Script;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import org.custommonkey.xmlunit.Diff;
-import org.junit.Assert;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-/**
- * @author michal.rehak
- *
- * @deprecated Use {@link NormalizedNodes} instead.
- */
-@Deprecated
-public abstract class NodeHelper {
-
- private static final Logger LOG = LoggerFactory.getLogger(NodeHelper.class);
-
- /** xml source of example network configuration */
- public static final String NETWORK_XML =
- "<network xmlns=\"urn:opendaylight:controller:network\">\n" +
- //"<network>\n" +
- " <topologies>\n" +
- " <topology>\n" +
- " <topology-id>topId_01</topology-id>\n" +
- " <nodes>\n" +
- " <node>\n" +
- " <node-id>nodeId_02</node-id>\n" +
- " <supporting-ne>networkId_02</supporting-ne>\n" +
- " <termination-points>\n" +
- " <termination-point>\n" +
- " <tp-id>tpId_03</tp-id>\n" +
- " </termination-point>\n" +
- " </termination-points>\n" +
- " </node>\n" +
- " <node>\n" +
- " <node-id>nodeId_16</node-id>\n" +
- " <supporting-ne>networkId_17</supporting-ne>\n" +
- " <termination-points>\n" +
- " <termination-point>\n" +
- " <tp-id>tpId_18</tp-id>\n" +
- " </termination-point>\n" +
- " </termination-points>\n" +
- " </node>\n" +
- " <node>\n" +
- " <node-id>nodeId_19</node-id>\n" +
- " <supporting-ne>networkId_20</supporting-ne>\n" +
- " <termination-points>\n" +
- " <termination-point>\n" +
- " <tp-id>tpId_18</tp-id>\n" +
- " </termination-point>\n" +
- " <termination-point>\n" +
- " <tp-id>tpId_19</tp-id>\n" +
- " </termination-point>\n" +
- " </termination-points>\n" +
- " </node>\n" +
- " </nodes>\n" +
- " <links>\n" +
- " <link>\n" +
- " <link-id>linkId_04</link-id>\n" +
- " <source>\n" +
- " <source-node>nodeId_05</source-node>\n" +
- " <source-tp>tpId_06</source-tp>\n" +
- " </source>\n" +
- " <destination>\n" +
- " <dest-node>nodeId_07</dest-node>\n" +
- " <dest-tp>tpId_08</dest-tp>\n" +
- " </destination>\n" +
- " </link>\n" +
- " <link>\n" +
- " <link-id>linkId_11</link-id>\n" +
- " <source>\n" +
- " <source-node>nodeId_12</source-node>\n" +
- " <source-tp>tpId_13</source-tp>\n" +
- " </source>\n" +
- " <destination>\n" +
- " <dest-node>nodeId_14</dest-node>\n" +
- " <dest-tp>tpId_15</dest-tp>\n" +
- " </destination>\n" +
- " </link>\n" +
- " </links>\n" +
- " </topology>\n" +
- " </topologies>\n" +
- " <network-elements>\n" +
- " <network-element>\n" +
- " <element-id>ntElementId_09</element-id>\n" +
- " </network-element>\n" +
- " <network-element>\n" +
- " <element-id>ntElementId_10</element-id>\n" +
- " </network-element>\n" +
- " </network-elements>\n" +
- "</network>";
-
- private static String domTreeString(final Document domTree) throws TransformerException {
- TransformerFactory transformerFact = TransformerFactory.newInstance();
- transformerFact.setAttribute("indent-number", 4);
- Transformer transformer = transformerFact.newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- //initialize StreamResult with File object to save to file
- StreamResult result = new StreamResult(new StringWriter());
- DOMSource source = new DOMSource(domTree);
- transformer.transform(source, result);
- return result.getWriter().toString();
- }
-
- /**
- * @param domTree
- * @param out
- * @throws Exception
- */
- private static void dumpDoc(final Document domTree, final PrintStream out) throws Exception {
- out.println(domTreeString(domTree));
- }
-
- public static void dumpDoc(final Document domTree, final Logger logger) throws TransformerException {
- logger.info("{}", domTreeString(domTree));
- }
-
- /**
- * @param qName
- * @return example tree, see {@link #NETWORK_XML}
- */
- public static CompositeNode buildTestConfigTree(final QName qName) {
- List<Node<?>> value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "element-id"), null, "ntElementId_09"));
- CompositeNode ntElementNode1 = NodeFactory.createImmutableCompositeNode(QName.create(qName, "network-element"),
- null, value);
- assignParentToChildren(ntElementNode1);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "element-id"), null, "ntElementId_10"));
- CompositeNode ntElementNode2 = NodeFactory.createImmutableCompositeNode(QName.create(qName, "network-element"),
- null, value);
- assignParentToChildren(ntElementNode2);
-
- value = new ArrayList<Node<?>>();
- value.add(ntElementNode1);
- value.add(ntElementNode2);
- CompositeNode ntElementsNode = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "network-elements"), null, value);
- assignParentToChildren(ntElementsNode);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "dest-node"), null, "nodeId_07"));
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "dest-tp"), null, "tpId_08"));
- CompositeNode destination = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "destination"), null,
- value);
- assignParentToChildren(destination);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "source-node"), null, "nodeId_05"));
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "source-tp"), null, "tpId_06"));
- CompositeNode source = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "source"), null, value);
- assignParentToChildren(source);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "link-id"), null, "linkId_04"));
- value.add(source);
- value.add(destination);
- CompositeNode link1 = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "link"), null, value);
- assignParentToChildren(link1);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "dest-node"), null, "nodeId_14"));
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "dest-tp"), null, "tpId_15"));
- destination = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "destination"), null, value);
- assignParentToChildren(destination);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "source-node"), null, "nodeId_12"));
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "source-tp"), null, "tpId_13"));
- source = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "source"), null, value);
- assignParentToChildren(source);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "link-id"), null, "linkId_11"));
- value.add(source);
- value.add(destination);
- CompositeNode link2 = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "link"), null, value);
- assignParentToChildren(link2);
-
- value = new ArrayList<Node<?>>();
- value.add(link1);
- value.add(link2);
- CompositeNode links = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "links"), null, value);
- assignParentToChildren(links);
-
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "tp-id"), null, "tpId_03"));
- CompositeNode terminationPointNode1 = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "termination-point"), null, value);
- assignParentToChildren(terminationPointNode1);
-
- value = new ArrayList<Node<?>>();
- value.add(terminationPointNode1);
- CompositeNode terminationPointsNode = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "termination-points"), null, value);
- assignParentToChildren(terminationPointsNode);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "node-id"), null, "nodeId_02"));
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "supporting-ne"), null, "networkId_02"));
- value.add(terminationPointsNode);
- CompositeNode node1Node = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "node"), null, value);
- assignParentToChildren(node1Node);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "tp-id"), null, "tpId_18"));
- terminationPointNode1 = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "termination-point"),
- null, value);
- assignParentToChildren(terminationPointNode1);
-
- value = new ArrayList<Node<?>>();
- value.add(terminationPointNode1);
- terminationPointsNode = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "termination-points"),
- null, value);
- assignParentToChildren(terminationPointsNode);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "node-id"), null, "nodeId_16"));
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "supporting-ne"), null, "networkId_17"));
- value.add(terminationPointsNode);
- CompositeNode node2Node = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "node"), null, value);
- assignParentToChildren(node2Node);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "tp-id"), null, "tpId_18"));
- terminationPointNode1 = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "termination-point"),
- null, value);
- assignParentToChildren(terminationPointNode1);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "tp-id"), null, "tpId_19"));
- CompositeNode terminationPointNode2 = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "termination-point"), null, value);
- assignParentToChildren(terminationPointNode2);
-
- value = new ArrayList<Node<?>>();
- value.add(terminationPointNode1);
- value.add(terminationPointNode2);
- terminationPointsNode = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "termination-points"),
- null, value);
- assignParentToChildren(terminationPointsNode);
-
- value = new ArrayList<Node<?>>();
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "node-id"), null, "nodeId_19"));
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "supporting-ne"), null, "networkId_20"));
- value.add(terminationPointsNode);
- CompositeNode node3Node = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "node"), null, value);
- assignParentToChildren(node3Node);
-
- value = new ArrayList<Node<?>>();
- value.add(node1Node);
- value.add(node2Node);
- value.add(node3Node);
- CompositeNode nodesNode = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "nodes"), null, value);
- assignParentToChildren(nodesNode);
-
- value = new ArrayList<Node<?>>();
- value.add(links);
- value.add(nodesNode);
- value.add(NodeFactory.createImmutableSimpleNode(QName.create(qName, "topology-id"), null, "topId_01"));
- CompositeNode topology = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "topology"), null, value);
- assignParentToChildren(topology);
-
- value = new ArrayList<Node<?>>();
- value.add(topology);
- CompositeNode topologies = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "topologies"), null,
- value);
- assignParentToChildren(topologies);
-
- value = new ArrayList<Node<?>>();
- value.add(topologies);
- value.add(ntElementsNode);
- CompositeNode network = NodeFactory.createImmutableCompositeNode(
- QName.create(qName, "network"), null, value);
- assignParentToChildren(network);
-
- return network;
- }
-
- /**
- * @param parentNode
- */
- public static void assignParentToChildren(final CompositeNode parentNode) {
- for (Node<?> child : parentNode.getValue()) {
- ((AbstractNodeTO<?>) child).setParent(parentNode);
- }
- }
-
- /**
- * @return schema context of controller-network.yang
- */
- public static SchemaContext loadSchemaContext() {
- YangModelParser yParser = new YangParserImpl();
- List<InputStream> yangInputStreams = new ArrayList<>();
- yangInputStreams.add(NodeHelper.class.getResourceAsStream(
- "/controller-network.yang"));
- yangInputStreams.add(NodeHelper.class.getResourceAsStream(
- "/ietf-inet-types@2010-09-24.yang"));
- Set<Module> modules = yParser
- .parseYangModelsFromStreams(yangInputStreams);
- return yParser.resolveSchemaContext(modules);
- }
-
- /**
- * @param scriptName
- * @return tree root
- * @throws Exception
- */
- public static CompositeNode loadConfigByGroovy(final String scriptName) throws Exception {
- InputStream configStream = NodeHelper.class.getResourceAsStream(scriptName);
- Binding binding = new Binding();
- GroovyShell gShell = new GroovyShell(binding);
- LOG.debug("groovy: starting script parse.. {}", scriptName);
- Script configScript = gShell.parse(new InputStreamReader(configStream));
- LOG.debug("groovy: starting script.. {}", scriptName);
- configScript.run();
- LOG.debug("groovy: digging result");
- Object xmlGen = binding.getVariable("xmlGen");
- LOG.debug("xmlGen = {}", xmlGen);
- Method getter = xmlGen.getClass().getDeclaredMethod("getBuilder", new Class[0]);
- MyNodeBuilder builder = (MyNodeBuilder) getter.invoke(xmlGen, new Object[0]);
-
- return builder.getRootNode();
- }
-
- /**
- * @param pattern , e.g.: <pre>"//{0}:network/{1}:xx[text() = 'sss']"</pre>
- * @param nsArg , e.g.: <pre>{"uri:ns1", "uri:ns2"}</pre>
- * @return pattern with namespaces: <pre>//uri:ns1:network/uri:ns2:xx[text() = ''sss'']"</pre>
- */
- public static String AddNamespaceToPattern(final String pattern, final Object... nsArg) {
- Object[] ns = nsArg;
- String patternNs = pattern.replaceAll("'", "''");
- if (ns == null) {
- ns = new Object[]{""};
- } else {
- // add ':' into pattern after placeholders
- patternNs = patternNs.replaceAll("(\\{[0-9]+\\})", "$1:");
- }
-
- return MessageFormat.format(patternNs, ns);
- }
-
- /**
- * @param tree
- * @param xmlFile
- * @param clazz
- * @throws Exception
- * @throws SAXException
- * @throws IOException
- */
- public static void compareXmlTree(final Document tree, final String xmlFile, final Class<?> clazz) throws Exception,
- SAXException, IOException {
- ByteArrayOutputStream actualRaw = new ByteArrayOutputStream();
- dumpDoc(tree, new PrintStream(actualRaw));
- Reader actualReader = new InputStreamReader(new ByteArrayInputStream(actualRaw.toByteArray()));
-
- Reader expectedReader = new InputStreamReader(clazz.getResourceAsStream(xmlFile));
- Diff myDiff = new Diff(expectedReader, actualReader);
- myDiff.overrideDifferenceListener(new IgnoreWhiteCharsDiffListener());
-
- boolean similar = myDiff.similar();
- if (! similar) {
- LOG.info("{}", new String(actualRaw.toByteArray()));
- }
- Assert.assertEquals(myDiff.toString(), true, similar);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import static org.junit.Assert.assertSame;
-
-import java.net.URI;
-import java.util.Date;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-
-/**
- * @author michal.rehak
- *
- */
-@Deprecated
-public class NodeModificationBuilderImplTest {
-
- private static final Logger LOG = LoggerFactory.getLogger(NodeModificationBuilderImplTest.class);
-
- private SchemaContext schemaCtx;
- private QName qName;
- private CompositeNode network;
- private NodeModificationBuilderImpl nodeModificationBuilder;
-
- private String ns;
-
- /**
- * @throws Exception
- */
- private void dumpResult() throws Exception {
- CompositeNode diffTree = nodeModificationBuilder.buildDiffTree();
- CompositeNode diffTreeImmutable = NodeFactory.copyDeepAsImmutable(diffTree, null);
-
- Document diffShadow = NodeUtils.buildShadowDomTree(diffTreeImmutable);
- NodeHelper.dumpDoc(diffShadow, LOG);
- }
-
- /**
- * prepare schemaContext
- *
- * @throws Exception
- */
- @Before
- public void setUp() throws Exception {
- schemaCtx = NodeHelper.loadSchemaContext();
-
- ns = "urn:opendaylight:controller:network";
- qName = QName.create(new URI(ns), new Date(1369000800000L), "topos");
- network = NodeHelper.buildTestConfigTree(qName);
-
- nodeModificationBuilder = new NodeModificationBuilderImpl(schemaCtx);
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#getMutableEquivalent(org.opendaylight.yangtools.yang.data.api.Node)}
- * .
- */
- @Test
- public void testGetMutableEquivalent() {
- MutableCompositeNode rootMutable = (MutableCompositeNode) nodeModificationBuilder.getMutableEquivalent(network);
-
- CompositeNode topologies = network.getCompositesByName("topologies").iterator().next();
- Node<?> mutableEquivalent = nodeModificationBuilder.getMutableEquivalent(topologies);
- CompositeNode topologiesMutable = rootMutable.getCompositesByName("topologies").iterator().next();
-
- assertSame(topologiesMutable, mutableEquivalent);
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testBuildDiffTreeAddSimple() throws Exception {
- LOG.debug("testBuildDiffTreeAddSimple");
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow,
- NodeHelper.AddNamespaceToPattern("//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns));
-
- MutableCompositeNode mutableParent = (MutableCompositeNode) nodeModificationBuilder
- .getMutableEquivalent(needle);
-
- MutableSimpleNode<String> newMutable = NodeFactory.createMutableSimpleNode(
- QName.create(needle.getNodeType(),
- "anySubNode"), mutableParent, "42", null, null);
-
- nodeModificationBuilder.addNode(newMutable);
- dumpResult();
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testBuildDiffTreeAddComposite() throws Exception {
- LOG.debug("testBuildDiffTreeAddComposite");
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- CompositeNode needle = NodeUtils.findNodeByXpath(networkShadow,
- NodeHelper.AddNamespaceToPattern("//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]", ns));
-
- MutableCompositeNode mutableParent = (MutableCompositeNode) nodeModificationBuilder
- .getMutableEquivalent(needle);
-
- MutableSimpleNode<String> newMutable = NodeFactory.createMutableSimpleNode(
- QName.create(needle.getNodeType(),
- "anySubNode"), null, "42", null, null);
-
- MutableCompositeNode newMutableCom = NodeFactory.createMutableCompositeNode(
- QName.create(needle.getNodeType(),
- "anySubNode"), mutableParent, NodeUtils.buildChildrenList(newMutable), null, null);
- NodeUtils.fixChildrenRelation(newMutableCom);
- newMutableCom.init();
-
- nodeModificationBuilder.addNode(newMutableCom);
- dumpResult();
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testBuildDiffTreeDeleteComposite() throws Exception {
- LOG.debug("testBuildDiffTreeDeleteComposite");
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
-
- @SuppressWarnings("unchecked")
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
- .getMutableEquivalent(needle);
-
- nodeModificationBuilder.deleteNode(mutableNeedle.getParent().asMutable());
- dumpResult();
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testBuildDiffTreeDeleteSimple() throws Exception {
- LOG.debug("testBuildDiffTreeDeleteSimple");
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
-
- @SuppressWarnings("unchecked")
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
- .getMutableEquivalent(needle);
-
- nodeModificationBuilder.deleteNode(mutableNeedle);
- dumpResult();
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testBuildDiffTreeMerge() throws Exception {
- LOG.debug("testBuildDiffTreeMerge");
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
-
- @SuppressWarnings("unchecked")
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
- .getMutableEquivalent(needle);
-
- mutableNeedle.setValue("tpId_18x");
- nodeModificationBuilder.mergeNode(mutableNeedle.getParent().asMutable());
- dumpResult();
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testBuildDiffTreeRemoveComposite() throws Exception {
- LOG.debug("testBuildDiffTreeRemoveComposite");
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
-
- @SuppressWarnings("unchecked")
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
- .getMutableEquivalent(needle);
-
- nodeModificationBuilder.removeNode(mutableNeedle.getParent().asMutable());
- dumpResult();
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testBuildDiffTreeRemoveSimple() throws Exception {
- LOG.debug("testBuildDiffTreeRemoveSimple");
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
-
- @SuppressWarnings("unchecked")
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
- .getMutableEquivalent(needle);
-
- nodeModificationBuilder.removeNode(mutableNeedle);
- dumpResult();
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testBuildDiffTreeReplaceComposite() throws Exception {
- LOG.debug("testBuildDiffTreeReplaceComposite");
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
-
- @SuppressWarnings("unchecked")
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
- .getMutableEquivalent(needle);
-
- mutableNeedle.setValue("tpId_18x");
- nodeModificationBuilder.replaceNode(mutableNeedle.getParent().asMutable());
- dumpResult();
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.yangtools.yang.data.impl.NodeModificationBuilderImpl#buildDiffTree()}
- * .
- *
- * @throws Exception
- */
- @Test
- public void testBuildDiffTreeReplaceSimple() throws Exception {
- LOG.debug("testBuildDiffTreeReplaceSimple");
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- SimpleNode<?> needle = NodeUtils.findNodeByXpath(networkShadow, NodeHelper.AddNamespaceToPattern(
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
-
- @SuppressWarnings("unchecked")
- MutableSimpleNode<String> mutableNeedle = (MutableSimpleNode<String>) nodeModificationBuilder
- .getMutableEquivalent(needle);
-
- mutableNeedle.setValue("tpId_18x");
- nodeModificationBuilder.replaceNode(mutableNeedle);
- dumpResult();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Date;
-import java.util.Deque;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-
-/**
- * @author michal.rehak
- *
- */
-@Deprecated
-public class NodeUtilsTest {
-
- private static final Logger LOG = LoggerFactory
- .getLogger(NodeUtilsTest.class);
-
- private QName qName;
- private CompositeNode network;
-
- private String ns;
-
-
- /**
- * @throws Exception
- */
- @Before
- public void setUp() throws Exception {
- ns = "urn:ietf:params:xml:ns:netconf:base:1.0";
- qName = QName.create(
- new URI(ns),
- new Date(42), "yang-data-impl-mutableTest");
- network = NodeHelper.buildTestConfigTree(qName);
- }
-
- /**
- * Test method for {@link org.opendaylight.yangtools.yang.data.impl.NodeUtils#buildPath(org.opendaylight.yangtools.yang.data.api.Node)}.
- * @throws Exception
- */
- @Test
- public void testBuildPath() throws Exception {
- SimpleNode<?> needle = network.getCompositesByName("topologies").iterator().next()
- .getCompositesByName("topology").iterator().next()
- .getSimpleNodesByName("topology-id").iterator().next();
- String breadCrumbs = NodeUtils.buildPath(needle);
-
- Assert.assertEquals("network.topologies.topology.topology-id", breadCrumbs);
- }
-
- /**
- * Test method for {@link org.opendaylight.yangtools.yang.data.impl.NodeUtils#buildShadowDomTree(org.opendaylight.yangtools.yang.data.api.CompositeNode)}.
- * @throws Exception
- */
- @Test
- public void testBuildShadowDomTree() throws Exception {
- MemoryConsumption mc = new MemoryConsumption();
- mc.startObserving();
-
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
-
- LOG.debug("After dom built: "+mc.finishObserving());
- NodeHelper.compareXmlTree(networkShadow, "./config02-shadow.xml", getClass());
- }
-
- /**
- * Test method for {@link org.opendaylight.yangtools.yang.data.impl.NodeUtils#findNodeByXpath(org.w3c.dom.Document, java.lang.String)}.
- * @throws Exception
- */
- @Test
- public void testFindNodeByXpath() throws Exception {
- Document networkShadow = NodeUtils.buildShadowDomTree(network);
- MemoryConsumption mc = new MemoryConsumption();
- mc.startObserving();
-
- SimpleNode<String> needle = NodeUtils.findNodeByXpath(networkShadow,
- NodeHelper.AddNamespaceToPattern(
- "//{0}node[{0}node-id='nodeId_19']//{0}termination-point[2]/{0}tp-id", ns));
-
- LOG.debug("After xpath executed: "+mc.finishObserving());
-
- Assert.assertNotNull(needle);
- Assert.assertEquals("tpId_18", needle.getValue());
- }
-
- /**
- * Test method for {@link org.opendaylight.yangtools.yang.data.impl.NodeUtils#buildNodeMap(java.util.List)}.
- */
- @Test
- public void testBuildNodeMap() {
- CompositeNode topology = network.getCompositesByName("topologies").iterator().next()
- .getCompositesByName("topology").iterator().next();
-
- Map<QName, List<Node<?>>> nodeMap = NodeUtils.buildNodeMap(topology.getValue());
- Assert.assertEquals(3, nodeMap.size());
- }
-
- /**
- * Test method for {@link org.opendaylight.yangtools.yang.data.impl.NodeUtils#buildMapOfListNodes(org.opendaylight.yangtools.yang.model.api.SchemaContext)}.
- */
- @Test
- public void testBuildMapOfListNodes() {
- SchemaContext schemaCtx = NodeHelper.loadSchemaContext();
- Map<String, ListSchemaNode> mapOfLists = NodeUtils.buildMapOfListNodes(schemaCtx);
- Assert.assertEquals(5, mapOfLists.size());
- }
-
- /**
- * Test method for {@link org.opendaylight.yangtools.yang.data.impl.NodeUtils#buildMapOfListNodes(org.opendaylight.yangtools.yang.model.api.SchemaContext)}.
- * @throws Exception
- * @throws IOException
- */
- @Test
- public void testLoadConfigByGroovy() throws IOException, Exception {
- CompositeNode treeRoot = NodeHelper.loadConfigByGroovy("./config02.groovy");
- Document shadowTree = NodeUtils.buildShadowDomTree(treeRoot);
- try {
- checkFamilyBinding(treeRoot);
- } catch (Exception e) {
- LOG.error(e.getMessage());
- throw e;
- }
-
- NodeHelper.compareXmlTree(shadowTree, "./config02g-shadow.xml", getClass());
- }
-
- private static void checkFamilyBinding(final CompositeNode treeRoot) throws Exception {
- Deque<CompositeNode> jobQueue = new LinkedList<>();
- jobQueue.push(treeRoot);
-
- while (!jobQueue.isEmpty()) {
- CompositeNode job = jobQueue.pop();
- for (Node<?> child : job.getValue()) {
- if (child instanceof CompositeNode) {
- jobQueue.push((CompositeNode) child);
- }
-
- if (job != child.getParent()) {
- throw new Exception("binding mismatch occured: \nPARENT["+job+"]\n CHILD[" + child+"]\n +-> "+child.getParent());
- }
- }
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.List;
-
-import javax.xml.stream.XMLStreamException;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-
-/**
- * The class <code>XmlTreeBuilderTest</code> contains tests for the class
- * {@link <code>XmlTreeBuilder</code>}
- *
- * @author Lukas Sedlak
- */
-public class XmlTreeBuilderTest {
-
- private InputStream inputStream;
-
- /**
- * Perform pre-test initialization
- *
- * @throws Exception
- */
- @Before
- public void setUp() throws Exception {
- final URI inputFile = getClass().getResource("/rpc-getDeviceEquipment.xml").toURI();
- inputStream = new FileInputStream(new File(inputFile));
- }
-
- /**
- * Run the Node<?> buildDataTree(InputStream) method test
- */
- @SuppressWarnings("unchecked")
- @Test
- public void testBuildDataTree()
- {
- Node<?> rootNode = null;
- try {
- rootNode = XmlTreeBuilder.buildDataTree(inputStream);
- } catch (XMLStreamException e) {
- e.printStackTrace();
- }
- assertNotNull(rootNode);
- assertTrue(rootNode instanceof CompositeNode);
-
- CompositeNode compRootNode = (CompositeNode)rootNode;
- assertNotNull(compRootNode.getValue());
-
- SimpleNode<String> methodName = null;
- SimpleNode<String> emptyTag = null;
- CompositeNode params = null;
- for (final Node<?> childNode : compRootNode.getValue()) {
- if (childNode instanceof SimpleNode) {
- if ("emptyTag".equals(childNode.getNodeType().getLocalName())) {
- emptyTag = (SimpleNode<String>) childNode;
- } else if ("methodName".equals(childNode.getNodeType().getLocalName())) {
- methodName = (SimpleNode<String>) childNode;
- }
-
- } else if (childNode instanceof CompositeNode) {
- params = (CompositeNode) childNode;
- }
- }
-
- assertNotNull(methodName);
- assertNotNull(params);
- assertTrue(emptyTag.getValue().isEmpty());
- assertEquals(methodName.getValue(), "getDeviceEquipment");
-
- String deviceId = null;
- String deviceIP = null;
- for (final Node<?> param : params.getValue()) {
- if (param instanceof CompositeNode) {
- final Node<?> valueNode = ((CompositeNode) param).getValue().get(0);
-
- assertTrue(valueNode instanceof CompositeNode);
- final CompositeNode value = (CompositeNode) valueNode;
- final Node<?> stringNode = value.getValue().get(0);
- assertTrue(stringNode instanceof SimpleNode);
-
- final SimpleNode<String> string = (SimpleNode<String>) stringNode;
- if ("DeviceID123".equals(string.getValue())) {
- deviceId = string.getValue();
- } else if ("172.23.218.75".equals(string.getValue())) {
- deviceIP = string.getValue();
- }
- }
- }
-
- assertNotNull(deviceId);
- assertNotNull(deviceIP);
- }
-
- @Test
- public void nodeMapInCompositeNodeTest() {
- Node<?> rootNode = null;
- try {
- rootNode = XmlTreeBuilder.buildDataTree(inputStream);
- } catch (XMLStreamException e) {
- e.printStackTrace();
- }
-
- CompositeNode compRootNode = (CompositeNode)rootNode;
- List<CompositeNode> params = compRootNode.getCompositesByName("params");
- assertEquals(1, params.size());
- List<CompositeNode> compositesByName = params.get(0).getCompositesByName("param");
- assertEquals(2, compositesByName.size());
- }
-}
package org.opendaylight.yangtools.yang.data.impl.codec.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import com.google.common.base.Charsets;
-import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.io.ByteSource;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import javax.activation.UnsupportedDataTypeException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.xml.sax.SAXException;
public class XmlDocumentUtilsTest {
testRpc = rpcTestModule.getRpcs().iterator().next();
}
- @Test
- public void testRpcInputTransform() throws Exception {
-
- final Document inputDocument = readXmlToDocument(XML_CONTENT);
- final Element input = inputDocument.getDocumentElement();
-
- final CompositeNode node = inputXmlToCompositeNode(input);
- final SimpleNode<?> refParsed = node.getSimpleNodesByName("ref").iterator().next();
- assertEquals(YangInstanceIdentifier.class, refParsed.getValue().getClass());
- final Document serializedDocument = inputCompositeNodeToXml(node);
-
- XMLUnit.compareXML(inputDocument, serializedDocument);
- }
-
- @Test
- public void testRpcReplyToDom() throws Exception {
- final Document reply = readXmlToDocument(RPC_REPLY);
- final CompositeNode domNodes = XmlDocumentUtils.rpcReplyToDomNodes(reply, QName.create("urn:opendaylight:controller:rpc:test", "2014-07-28", "test"), schema);
- assertEquals(1, domNodes.getValue().size());
- final Node<?> outputNode = domNodes.getValue().get(0);
- assertTrue(outputNode instanceof CompositeNode);
- assertEquals(1, ((CompositeNode) outputNode).getValue().size());
- final Node<?> okNode = ((CompositeNode) outputNode).getValue().get(0);
- assertEquals("ok", okNode.getNodeType().getLocalName());
- }
-
public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException {
return readXmlToDocument(new ByteArrayInputStream(xmlContent.getBytes(Charsets.UTF_8)));
}
doc.getDocumentElement().normalize();
return doc;
}
-
- public Document inputCompositeNodeToXml(final CompositeNode cNode)
- throws UnsupportedDataTypeException {
- return XmlDocumentUtils.toDocument(cNode, testRpc.getInput(), XmlDocumentUtils.defaultValueCodecProvider());
- }
-
- public CompositeNode inputXmlToCompositeNode(final Element e) {
- return (CompositeNode) XmlDocumentUtils.toDomNode(e, Optional.<DataSchemaNode>of(testRpc.getInput()),
- Optional.of(XmlDocumentUtils.defaultValueCodecProvider()), Optional.of(schema));
- }
}
import java.net.URISyntaxException;
import java.util.AbstractMap;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Map;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
return targetBaseType;
}
- @Test
- public void testEmptyNodeWithAttribute() throws Exception {
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- final XMLStreamWriter writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
-
- final Map<QName, String> attrs = Maps.newHashMap();
- attrs.put(QName.create("namespaceAttr", "2012-12-12", "attr1"), "value");
- final QName qName = QName.create("urn:opendaylight:controller:rpc:test", "2014-07-28", "cont");
- final ImmutableCompositeNode dataAttributes = ImmutableCompositeNode.create(qName, attrs, Collections.<Node<?>>emptyList());
- XmlStreamUtils.create(XmlUtils.DEFAULT_XML_CODEC_PROVIDER).writeDocument(writer, dataAttributes);
-
- writer.close();
- out.close();
-
- final String xmlAsString = new String(out.toByteArray());
-
- // TODO why resulting xml does not have namespace definition ? If sending xml by e.g. netconf the namespace is there but not here in test
- final String expectedXmlAsString = "<cont xmlns:a=\"namespaceAttr\" a:attr1=\"value\"></cont>";
-
- XMLUnit.setIgnoreAttributeOrder(true);
- final Document control = XMLUnit.buildControlDocument(expectedXmlAsString);
- final Document test = XMLUnit.buildTestDocument(xmlAsString);
- final Diff diff = XMLUnit.compareXML(control, test);
-
- final boolean identical = diff.identical();
- assertTrue("Xml differs: " + diff.toString(), identical);
- }
-
private Map<String, String> mapPrefixed(final Iterable<Map.Entry<URI, String>> prefixes) {
final Map<String, String> mappedPrefixes = Maps.newHashMap();
for (final Map.Entry<URI, String> prefix : prefixes) {
package org.opendaylight.yangtools.yang.data.operations;
import com.google.common.base.Optional;
-
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
super(String.format("Data missing for node: %s", nodeType), nodeType);
}
- public DataMissingException(final QName nodeType, final Node<?> modificationNode) {
- super(String.format("Data missing for node: %s, %s", nodeType, modificationNode), nodeType);
- }
-
public DataMissingException(final QName nodeType, final NormalizedNode<?, ?> modificationNode) {
super(String.format("Data missing for node: %s, %s", nodeType, modificationNode), nodeType);
}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
-
-/**
- * @deprecated Use one of the {@link NormalizedNodeContainer} implementation packages.
- */
-@Deprecated
-public abstract class AbstractContainerNode extends AbstractNode<List<Node<?>>> implements CompositeNode {
-
- @Override
- public SimpleNode<?> getFirstSimpleByName(final QName leaf) {
- List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
- if (list.size() == 0) {
- return null;
- }
- return list.get(0);
- }
-
- protected AbstractContainerNode(final QName name, final CompositeNode parent) {
- super(name, parent);
- }
-
- public AbstractContainerNode(final QName name) {
- super(name, null);
- }
-
- @Override
- public List<Node<?>> getChildren() {
- return getValue();
- }
-
- @Override
- public List<Node<?>> getValue() {
- Map<QName, List<Node<?>>> map = getNodeMap();
- if (map == null) {
- throw new IllegalStateException("nodeMap should not be null");
- }
- List<Node<?>> ret = new ArrayList<Node<?>>();
- Collection<List<Node<?>>> values = map.values();
- for (List<Node<?>> list : values) {
- ret.addAll(list);
- }
- return ret;
- }
-
- protected abstract Map<QName, List<Node<?>>> getNodeMap();
-
- @Override
- public List<CompositeNode> getCompositesByName(final QName children) {
- Map<QName, List<Node<?>>> map = getNodeMap();
- if (map == null) {
- throw new IllegalStateException("nodeMap should not be null");
- }
- List<Node<?>> toFilter = map.get(children);
- List<CompositeNode> list = new ArrayList<CompositeNode>();
- for (Node<?> node : toFilter) {
- if (node instanceof CompositeNode) {
- list.add((CompositeNode) node);
- }
- }
- return list;
- }
-
- @Override
- public List<SimpleNode<?>> getSimpleNodesByName(final QName children) {
- Map<QName, List<Node<?>>> map = getNodeMap();
- if (map == null) {
- throw new IllegalStateException("nodeMap should not be null");
- }
- List<Node<?>> toFilter = map.get(children);
- List<SimpleNode<?>> list = new ArrayList<SimpleNode<?>>();
-
- for (Node<?> node : toFilter) {
- if (node instanceof SimpleNode<?>) {
- list.add((SimpleNode<?>) node);
- }
- }
- return list;
- }
-
- @Override
- public CompositeNode getFirstCompositeByName(final QName container) {
- List<CompositeNode> list = getCompositesByName(container);
- if (list.size() == 0) {
- return null;
- }
- return list.get(0);
- }
-
- public SimpleNode<?> getFirstLeafByName(final QName leaf) {
- List<SimpleNode<?>> list = getSimpleNodesByName(leaf);
- if (list.size() == 0) {
- return null;
- }
- return list.get(0);
- }
-
- @Override
- public List<CompositeNode> getCompositesByName(final String children) {
- return getCompositesByName(localQName(children));
- }
-
- @Override
- public List<SimpleNode<?>> getSimpleNodesByName(final String children) {
- return getSimpleNodesByName(localQName(children));
- }
-
- private QName localQName(final String str) {
- return QName.create(getNodeType(), str);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.util;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.ModifyAction;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * @deprecated Use one of the {@link NormalizedNode} implementation packages.
- */
-@Deprecated
-public abstract class AbstractNode<T> implements Node<T> {
-
- private final QName nodeName;
- private final CompositeNode parent;
-
- protected AbstractNode(final QName name, final CompositeNode parent) {
- nodeName = name;
- this.parent = parent;
- }
-
- @Override
- public QName getNodeType() {
- return this.nodeName;
- }
-
- @Override
- public CompositeNode getParent() {
- return parent;
- }
-
- /* (non-Javadoc)
- */
- /**
- * @see org.opendaylight.yangtools.yang.data.api.NodeModification#getModificationAction()
- */
- public ModifyAction getModificationAction() {
- // TODO Auto-generated method stub
- return null;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
-import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-
-/**
- * @deprecated Use one of the {@link NormalizedNode} implementation packages.
- */
-@Deprecated
-public final class Nodes {
-
- private Nodes() {
- }
-
- public static <T> SimpleNode<T> leafNode(final QName name, final T value) {
- return new SimpleNodeTO<T>(name, value, null);
- }
-
- public static CompositeNode containerNode(final QName name, final List<Node<?>> children) {
- return containerNode(name, children, null);
- }
-
- public static CompositeNode containerNode(final QName name, final List<Node<?>> children, final CompositeNode parent) {
- return new ContainerNodeTO(name, parent, nodeMapFromList(children));
- }
-
- public static Map<QName, List<Node<?>>> nodeMapFromList(final List<Node<?>> children) {
- Map<QName, List<Node<?>>> map = new HashMap<QName, List<Node<?>>>();
- for (Node<?> node : children) {
-
- QName name = node.getNodeType();
- List<Node<?>> targetList = map.get(name);
- if (targetList == null) {
- targetList = new ArrayList<Node<?>>();
- map.put(name, targetList);
- }
- targetList.add(node);
- }
- return map;
- }
-
- /**
- * @deprecated Use one of the {@link NormalizedNode} implementation packages.
- */
- @Deprecated
- private static class ContainerNodeTO extends AbstractContainerNode {
-
- private final Map<QName, List<Node<?>>> nodeMap;
-
- public ContainerNodeTO(final QName name, final Map<QName, List<Node<?>>> nodeMap) {
- super(name);
- this.nodeMap = nodeMap;
- }
-
- public ContainerNodeTO(final QName name, final CompositeNode parent, final Map<QName, List<Node<?>>> nodeMap) {
- super(name, parent);
- this.nodeMap = nodeMap;
- }
-
- @Override
- protected Map<QName, List<Node<?>>> getNodeMap() {
-
- return nodeMap;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.opendaylight.yangtools.yang.data.api.CompositeNode#asMutable()
- */
- @Override
- public MutableCompositeNode asMutable() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public QName getKey() {
- return getNodeType();
- }
-
- @Override
- public List<Node<?>> setValue(final List<Node<?>> value) {
- return null;
- }
-
- @Override
- public int size() {
- return nodeMap.size();
- }
-
- @Override
- public boolean isEmpty() {
- return nodeMap.isEmpty();
- }
-
- @Override
- public boolean containsKey(final Object key) {
- return nodeMap.containsKey(key);
- }
-
- @Override
- public boolean containsValue(final Object value) {
- return nodeMap.containsValue(value);
- }
-
- @Override
- public List<Node<?>> get(final Object key) {
- return nodeMap.get(key);
- }
-
- @Override
- public List<Node<?>> put(final QName key, final List<Node<?>> value) {
- return nodeMap.put(key, value);
- }
-
- @Override
- public List<Node<?>> remove(final Object key) {
- return nodeMap.remove(key);
- }
-
- @Override
- public void putAll(final Map<? extends QName, ? extends List<Node<?>>> m) {
- nodeMap.putAll(m);
- }
-
- @Override
- public void clear() {
- nodeMap.clear();
- }
-
- @Override
- public Set<QName> keySet() {
- return nodeMap.keySet();
- }
-
- @Override
- public Collection<List<Node<?>>> values() {
- return nodeMap.values();
- }
-
- @Override
- public Set<java.util.Map.Entry<QName, List<Node<?>>>> entrySet() {
-
- return nodeMap.entrySet();
- }
-
- }
-
- /**
- * @deprecated Use one of the {@link NormalizedNode} implementation packages.
- */
- @Deprecated
- private static class SimpleNodeTO<T> extends AbstractNode<T> implements SimpleNode<T> {
-
- private final T value;
-
- protected SimpleNodeTO(final QName name, final T val, final CompositeNode parent) {
- super(name, parent);
- value = val;
-
- }
-
- @Override
- public T getValue() {
- return value;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.opendaylight.yangtools.yang.data.api.SimpleNode#asMutable()
- */
- @Override
- public MutableSimpleNode<T> asMutable() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public T setValue(final T value) {
- return null;
- }
-
- @Override
- public QName getKey() {
- return getNodeType();
- }
- }
-
-}