Bump yangtools to 3.0.0 29/81129/31
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 22 Mar 2019 18:32:29 +0000 (19:32 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 16 Apr 2019 08:13:31 +0000 (08:13 +0000)
This is bumps yangtools to 3.0.0, adjusting for changed APIs. The
changes specifically include:

- use ListenerRegistry.getRegistrations() instead of it implementing
  Iterable
- adjust for NormalizedNodeStreamWriter interface change
- remove use of *AttrBuilder, as NormalizedNodes no longer hold
  attributes
- DataTreeCandidateNodes.empty() instead of home-grown implementation
- adjust for DataTreeCandidateNode.getModifiedChild() returning Optional
- use QueuedNotificationManager.BatchedInvoker

Change-Id: Ia30d73ccf6380e3759414b3026b822df0950a481
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
21 files changed:
features/mdsal/odl-mdsal-broker-local/pom.xml
features/mdsal/odl-mdsal-broker-local/src/main/feature/feature.xml
opendaylight/blueprint/pom.xml
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/compat/HeliumNotificationProviderServiceWithInterestListeners.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/LazyDataObjectModification.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/LazySerializedContainerNode.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/MockSchemaService.java
opendaylight/md-sal/sal-binding-dom-it/pom.xml
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/AbstractNormalizedNodePruner.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/transformer/NormalizedNodeBuilderWrapper.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/AbstractDataTreeCandidateNode.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModification.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardChangePublisher.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/CompositeModel.java
opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMDataTreeListenerTest.java
opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java
opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/AbstractDataTreeChangeListenerTest.java

index 82daf29..6adf223 100644 (file)
@@ -34,7 +34,7 @@
             <dependency>
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yangtools-artifacts</artifactId>
-                <version>2.1.8</version>
+                <version>3.0.0</version>
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
index 6d51823..27ae27c 100644 (file)
@@ -9,7 +9,7 @@
 <features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="odl-mdsal-${project.version}">
     <feature name="odl-mdsal-broker-local" version="${project.version}">
         <feature version="[5,6)">odl-lmax-3</feature>
-        <feature version="[2.1,3)">odl-yangtools-codec</feature>
+        <feature version="[3,4)">odl-yangtools-codec</feature>
         <bundle start-level="40">mvn:org.opendaylight.controller/blueprint/${blueprint.version}</bundle>
     </feature>
 </features>
index 660648f..5944d69 100644 (file)
@@ -41,7 +41,7 @@
       <dependency>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>yangtools-artifacts</artifactId>
-        <version>2.1.8</version>
+        <version>3.0.0</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
index 2a07b03..4dd3521 100644 (file)
@@ -60,7 +60,8 @@ public class HeliumNotificationProviderServiceWithInterestListeners extends Heli
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     private void notifyAllListeners(final Set<SchemaPath> added) {
-        final Iterator<ListenerRegistration<NotificationInterestListener>> listeners = interestListeners.iterator();
+        final Iterator<? extends ListenerRegistration<? extends NotificationInterestListener>> listeners =
+                interestListeners.getRegistrations().iterator();
         if (listeners.hasNext()) {
             final Set<Class<? extends Notification>> baEvent = translate(added);
             while (listeners.hasNext()) {
index 1a21b98..b163285 100644 (file)
@@ -238,7 +238,7 @@ final class LazyDataObjectModification<T extends DataObject> implements DataObje
         final Iterator<YangInstanceIdentifier.PathArgument> toEnter = domArgumentList.iterator();
         DataTreeCandidateNode current = domData;
         while (toEnter.hasNext() && current != null) {
-            current = current.getModifiedChild(toEnter.next());
+            current = current.getModifiedChild(toEnter.next()).orElse(null);
         }
         return current != null && current.getModificationType() != UNMODIFIED ? create(childCodec, current) : null;
     }
index bed7d31..0fed59f 100644 (file)
@@ -5,11 +5,9 @@
  * 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.controller.md.sal.binding.impl;
 
 import java.util.Collection;
-import java.util.Map;
 import java.util.Optional;
 import org.opendaylight.mdsal.binding.dom.adapter.BindingDataAware;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
@@ -50,11 +48,6 @@ class LazySerializedContainerNode implements ContainerNode, BindingDataAware {
         return new WithContextRef(rpcName.getLastComponent(), data, contextRef, codec);
     }
 
-    @Override
-    public Map<QName, String> getAttributes() {
-        return delegate().getAttributes();
-    }
-
     private ContainerNode delegate() {
         if (domData == null) {
             domData = registry.toNormalizedNodeRpcData(bindingData);
@@ -83,11 +76,6 @@ class LazySerializedContainerNode implements ContainerNode, BindingDataAware {
         return delegate().getChild(child);
     }
 
-    @Override
-    public final Object getAttributeValue(final QName name) {
-        return delegate().getAttributeValue(name);
-    }
-
     @Override
     public final DataObject bindingData() {
         return bindingData;
index 39a6db2..df192a7 100644 (file)
@@ -51,7 +51,7 @@ public final class MockSchemaService implements DOMSchemaService, SchemaContextP
 
     public synchronized void changeSchema(final SchemaContext newContext) {
         schemaContext = newContext;
-        for (ListenerRegistration<SchemaContextListener> listener : listeners) {
+        for (ListenerRegistration<? extends SchemaContextListener> listener : listeners.getRegistrations()) {
             listener.getInstance().onGlobalContextUpdated(schemaContext);
         }
     }
index 0fe38b3..bc2c70c 100644 (file)
@@ -18,7 +18,7 @@
       <dependency>
         <groupId>org.opendaylight.yangtools</groupId>
         <artifactId>yangtools-artifacts</artifactId>
-        <version>2.1.8</version>
+        <version>3.0.0</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
index 02bebeb..cddcd8d 100755 (executable)
@@ -44,6 +44,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     private NormalizedNodeWriter normalizedNodeWriter;
     private boolean headerWritten;
     private QName lastLeafSetQName;
+    private boolean inSimple;
 
     AbstractNormalizedNodeDataOutput(final DataOutput output) {
         this.output = Preconditions.checkNotNull(output);
@@ -162,18 +163,15 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void leafNode(final NodeIdentifier name, final Object value) throws IOException, IllegalArgumentException {
+    public void startLeafNode(final NodeIdentifier name) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
-        LOG.trace("Writing a new leaf node");
+        LOG.trace("Starting a new leaf node");
         startNode(name.getNodeType(), NodeTypes.LEAF_NODE);
-
-        writeObject(value);
+        inSimple = true;
     }
 
     @Override
-    public void startLeafSet(final NodeIdentifier name, final int childSizeHint)
-
-            throws IOException, IllegalArgumentException {
+    public void startLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.trace("Starting a new leaf set");
 
@@ -182,8 +180,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startOrderedLeafSet(final NodeIdentifier name, final int childSizeHint)
-            throws IOException, IllegalArgumentException {
+    public void startOrderedLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.trace("Starting a new ordered leaf set");
 
@@ -192,23 +189,21 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void leafSetEntryNode(final QName name, final Object value) throws IOException, IllegalArgumentException {
-        LOG.trace("Writing a new leaf set entry node");
+    public void startLeafSetEntryNode(final NodeWithValue<?> name) throws IOException {
+        LOG.trace("Starting a new leaf set entry node");
 
         output.writeByte(NodeTypes.LEAF_SET_ENTRY_NODE);
 
         // lastLeafSetQName is set if the parent LeafSetNode was previously written. Otherwise this is a
         // stand alone LeafSetEntryNode so write out it's name here.
         if (lastLeafSetQName == null) {
-            writeQName(name);
+            writeQName(name.getNodeType());
         }
-
-        writeObject(value);
+        inSimple = true;
     }
 
     @Override
-    public void startContainerNode(final NodeIdentifier name, final int childSizeHint)
-            throws IOException, IllegalArgumentException {
+    public void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
 
         LOG.trace("Starting a new container node");
@@ -217,8 +212,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startYangModeledAnyXmlNode(final NodeIdentifier name, final int childSizeHint)
-            throws IOException, IllegalArgumentException {
+    public void startYangModeledAnyXmlNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
 
         LOG.trace("Starting a new yang modeled anyXml node");
@@ -227,8 +221,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint)
-            throws IOException, IllegalArgumentException {
+    public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.trace("Starting a new unkeyed list");
 
@@ -236,8 +229,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint)
-            throws IOException, IllegalStateException {
+    public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.trace("Starting a new unkeyed list item");
 
@@ -245,8 +237,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startMapNode(final NodeIdentifier name, final int childSizeHint)
-            throws IOException, IllegalArgumentException {
+    public void startMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.trace("Starting a new map node");
 
@@ -255,18 +246,16 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
 
     @Override
     public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint)
-            throws IOException, IllegalArgumentException {
+            throws IOException {
         Preconditions.checkNotNull(identifier, "Node identifier should not be null");
         LOG.trace("Starting a new map entry node");
         startNode(identifier.getNodeType(), NodeTypes.MAP_ENTRY_NODE);
 
         writeKeyValueMap(identifier.getKeyValues());
-
     }
 
     @Override
-    public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint)
-            throws IOException, IllegalArgumentException {
+    public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.trace("Starting a new ordered map node");
 
@@ -274,8 +263,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startChoiceNode(final NodeIdentifier name, final int childSizeHint)
-            throws IOException, IllegalArgumentException {
+    public void startChoiceNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
         LOG.trace("Starting a new choice node");
 
@@ -283,8 +271,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void startAugmentationNode(final AugmentationIdentifier identifier)
-            throws IOException, IllegalArgumentException {
+    public void startAugmentationNode(final AugmentationIdentifier identifier) throws IOException {
         Preconditions.checkNotNull(identifier, "Node identifier should not be null");
         LOG.trace("Starting a new augmentation node");
 
@@ -293,15 +280,23 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void anyxmlNode(final NodeIdentifier name, final Object value) throws IOException, IllegalArgumentException {
+    public void startAnyxmlNode(final NodeIdentifier name) throws IOException {
         Preconditions.checkNotNull(name, "Node identifier should not be null");
-        LOG.trace("Writing any xml node");
-
+        LOG.trace("Starting any xml node");
         startNode(name.getNodeType(), NodeTypes.ANY_XML_NODE);
+        inSimple = true;
+    }
 
+    @Override
+    public void scalarValue(final Object value) throws IOException {
+        writeObject(value);
+    }
+
+    @Override
+    public void domSourceValue(final DOMSource value) throws IOException {
         try {
             StreamResult xmlOutput = new StreamResult(new StringWriter());
-            TransformerFactory.newInstance().newTransformer().transform((DOMSource)value, xmlOutput);
+            TransformerFactory.newInstance().newTransformer().transform(value, xmlOutput);
             writeObject(xmlOutput.getWriter().toString());
         } catch (TransformerException | TransformerFactoryConfigurationError e) {
             throw new IOException("Error writing anyXml", e);
@@ -309,10 +304,13 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
     }
 
     @Override
-    public void endNode() throws IOException, IllegalStateException {
+    public void endNode() throws IOException {
         LOG.trace("Ending the node");
-        lastLeafSetQName = null;
-        output.writeByte(NodeTypes.END_NODE);
+        if (!inSimple) {
+            lastLeafSetQName = null;
+            output.writeByte(NodeTypes.END_NODE);
+        }
+        inSimple = false;
     }
 
     @Override
@@ -329,6 +327,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
 
     private void startNode(final QName qname, final byte nodeType) throws IOException {
         Preconditions.checkNotNull(qname, "QName of node identifier should not be null.");
+        Preconditions.checkState(!inSimple, "Attempted to start a child in a simple node");
 
         ensureHeaderWritten();
 
index b042963..4b845ef 100755 (executable)
@@ -39,7 +39,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.slf4j.Logger;
@@ -65,11 +65,10 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
 
     private QName lastLeafSetQName;
 
-    private NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier,
-                                      Object, LeafNode<Object>> leafBuilder;
+    private NormalizedNodeBuilder<YangInstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> leafBuilder;
 
     @SuppressWarnings("rawtypes")
-    private NormalizedNodeAttrBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder;
+    private NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder;
 
     private final StringBuilder reusableStringBuilder = new StringBuilder(50);
 
@@ -149,8 +148,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
         }
     }
 
-    private NormalizedNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier,
-                                      Object, LeafNode<Object>> leafBuilder() {
+    private NormalizedNodeBuilder<YangInstanceIdentifier.NodeIdentifier, Object, LeafNode<Object>> leafBuilder() {
         if (leafBuilder == null) {
             leafBuilder = Builders.leafBuilder();
         }
@@ -159,8 +157,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeDataInput
     }
 
     @SuppressWarnings("rawtypes")
-    private NormalizedNodeAttrBuilder<NodeWithValue, Object,
-                                      LeafSetEntryNode<Object>> leafSetEntryBuilder() {
+    private NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafSetEntryBuilder() {
         if (leafSetEntryBuilder == null) {
             leafSetEntryBuilder = Builders.leafSetEntryBuilder();
         }
index 9ce039c..03467f3 100644 (file)
@@ -10,24 +10,22 @@ package org.opendaylight.controller.cluster.datastore.node.utils.transformer;
 import static com.google.common.base.Preconditions.checkState;
 import static java.util.Objects.requireNonNull;
 
+import java.io.IOException;
 import java.util.ArrayDeque;
 import java.util.Deque;
 import java.util.NoSuchElementException;
 import java.util.Optional;
 import javax.xml.transform.dom.DOMSource;
-import org.opendaylight.yangtools.yang.common.QName;
 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.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -75,25 +73,9 @@ abstract class AbstractNormalizedNodePruner implements NormalizedNodeStreamWrite
         state = State.OPEN;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
-    public void leafNode(final NodeIdentifier nodeIdentifier, final Object value) {
-        checkNotSealed();
-
-        NormalizedNodeBuilderWrapper parent = stack.peek();
-        LeafNode<Object> leafNode = Builders.leafBuilder().withNodeIdentifier(nodeIdentifier).withValue(value).build();
-        if (parent != null) {
-            if (hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
-                parent.builder().addChild(leafNode);
-            }
-        } else {
-            // If there's no parent node then this is a stand alone LeafNode.
-            if (nodePathSchemaNode != null) {
-                this.normalizedNode = leafNode;
-            }
-
-            state = State.CLOSED;
-        }
+    public void startLeafNode(final NodeIdentifier name) {
+        addBuilder(Builders.leafBuilder().withNodeIdentifier(name), name);
     }
 
     @Override
@@ -106,28 +88,9 @@ abstract class AbstractNormalizedNodePruner implements NormalizedNodeStreamWrite
         addBuilder(Builders.orderedLeafSetBuilder().withNodeIdentifier(nodeIdentifier), nodeIdentifier);
     }
 
-    @SuppressWarnings("unchecked")
     @Override
-    public void leafSetEntryNode(final QName name, final Object value) {
-        checkNotSealed();
-
-        NormalizedNodeBuilderWrapper parent = stack.peek();
-        if (parent != null) {
-            if (hasValidSchema(name, parent)) {
-                parent.builder().addChild(Builders.leafSetEntryBuilder().withValue(value)
-                        .withNodeIdentifier(new NodeWithValue<>(parent.nodeType(), value))
-                        .build());
-            }
-        } else {
-            // If there's no parent LeafSetNode then this is a stand alone
-            // LeafSetEntryNode.
-            if (nodePathSchemaNode != null) {
-                this.normalizedNode = Builders.leafSetEntryBuilder().withValue(value).withNodeIdentifier(
-                        new NodeWithValue<>(name, value)).build();
-            }
-
-            state = State.CLOSED;
-        }
+    public void startLeafSetEntryNode(final NodeWithValue<?> name) throws IOException {
+        addBuilder(Builders.leafSetEntryBuilder().withNodeIdentifier(name), name);
     }
 
     @Override
@@ -176,29 +139,21 @@ abstract class AbstractNormalizedNodePruner implements NormalizedNodeStreamWrite
         addBuilder(Builders.augmentationBuilder().withNodeIdentifier(augmentationIdentifier), augmentationIdentifier);
     }
 
-    @SuppressWarnings("unchecked")
     @Override
-    public void anyxmlNode(final NodeIdentifier nodeIdentifier, final Object value) {
-        checkNotSealed();
+    public void startAnyxmlNode(final NodeIdentifier name) {
+        addBuilder(Builders.anyXmlBuilder().withNodeIdentifier(name), name);
+    }
 
-        NormalizedNodeBuilderWrapper parent = stack.peek();
-        AnyXmlNode anyXmlNode = Builders.anyXmlBuilder().withNodeIdentifier(nodeIdentifier).withValue((DOMSource) value)
-                .build();
-        if (parent != null) {
-            if (hasValidSchema(nodeIdentifier.getNodeType(), parent)) {
-                parent.builder().addChild(anyXmlNode);
-            }
-        } else {
-            // If there's no parent node then this is a stand alone AnyXmlNode.
-            if (nodePathSchemaNode != null) {
-                this.normalizedNode = anyXmlNode;
-            }
+    @Override
+    public void domSourceValue(final DOMSource value) {
+        setValue(value);
+    }
 
-            state = State.CLOSED;
-        }
+    @Override
+    public void scalarValue(final Object value) {
+        setValue(value);
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public void endNode() {
         checkNotSealed();
@@ -219,13 +174,13 @@ abstract class AbstractNormalizedNodePruner implements NormalizedNodeStreamWrite
             return;
         }
 
-        final NormalizedNode<?, ?> newNode = child.builder().build();
+        final NormalizedNode<?, ?> newNode = child.build();
         final NormalizedNodeBuilderWrapper parent = stack.peek();
         if (parent == null) {
             normalizedNode = newNode;
             state = State.CLOSED;
         } else {
-            parent.builder().addChild(newNode);
+            parent.addChild(newNode);
         }
     }
 
@@ -255,25 +210,21 @@ abstract class AbstractNormalizedNodePruner implements NormalizedNodeStreamWrite
         checkState(state == State.OPEN, "Illegal operation in state %s", state);
     }
 
-    private static boolean hasValidSchema(final QName name, final NormalizedNodeBuilderWrapper parent) {
-        final DataSchemaContextNode<?> parentSchema = parent.getSchema();
-        final boolean valid = parentSchema != null && parentSchema.getChild(name) != null;
-        if (!valid) {
-            LOG.debug("Schema not found for {}", name);
-        }
-
-        return valid;
+    private void setValue(final Object value) {
+        checkNotSealed();
+        final NormalizedNodeBuilderWrapper current = stack.peek();
+        checkState(current != null, "Attempted to set value %s while no node is open", value);
+        current.setValue(value);
     }
 
-    private NormalizedNodeBuilderWrapper addBuilder(final NormalizedNodeContainerBuilder<?, ?, ?, ?> builder,
+    private <T extends NormalizedNodeBuilder<?, ?, ?>> NormalizedNodeBuilderWrapper addBuilder(final T builder,
             final PathArgument identifier) {
         checkNotSealed();
 
         final DataSchemaContextNode<?> schemaNode;
         final NormalizedNodeBuilderWrapper parent = stack.peek();
         if (parent != null) {
-            final DataSchemaContextNode<?> parentSchema = parent.getSchema();
-            schemaNode = parentSchema == null ? null : parentSchema.getChild(identifier);
+            schemaNode = parent.childSchema(identifier);
         } else {
             schemaNode = nodePathSchemaNode;
         }
index 726f69e..385376c 100644 (file)
@@ -7,35 +7,29 @@
  */
 package org.opendaylight.controller.cluster.datastore.node.utils.transformer;
 
+import static com.google.common.base.Preconditions.checkState;
 import static java.util.Objects.requireNonNull;
 
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
 
 final class NormalizedNodeBuilderWrapper {
-    private final NormalizedNodeContainerBuilder<?, ?, ?, ?> builder;
+    @SuppressWarnings("rawtypes")
+    private final NormalizedNodeBuilder builder;
     private final PathArgument identifier;
     private final DataSchemaContextNode<?> schemaNode;
 
-    NormalizedNodeBuilderWrapper(final NormalizedNodeContainerBuilder<?, ?, ?, ?> builder,
+    NormalizedNodeBuilderWrapper(final NormalizedNodeBuilder<?, ?, ?> builder,
             final PathArgument identifier, final @Nullable DataSchemaContextNode<?> schemaNode) {
         this.builder = requireNonNull(builder);
         this.identifier = requireNonNull(identifier);
         this.schemaNode = schemaNode;
     }
 
-    @SuppressWarnings("rawtypes")
-    NormalizedNodeContainerBuilder builder() {
-        return builder;
-    }
-
-    QName nodeType() {
-        return identifier.getNodeType();
-    }
-
     PathArgument identifier() {
         return identifier;
     }
@@ -43,4 +37,32 @@ final class NormalizedNodeBuilderWrapper {
     @Nullable DataSchemaContextNode<?> getSchema() {
         return schemaNode;
     }
+
+    @Nullable DataSchemaContextNode<?> childSchema(final PathArgument child) {
+        if (schemaNode == null) {
+            return null;
+        }
+
+        checkState(builder instanceof NormalizedNodeContainerBuilder,
+            "Attempted to lookup child %s in non-container %s", schemaNode);
+        return schemaNode.getChild(child);
+    }
+
+    NormalizedNode<?, ?> build() {
+        return builder.build();
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    void addChild(final NormalizedNode<?, ?> child) {
+        checkState(builder instanceof NormalizedNodeContainerBuilder,
+            "Attempted to add child %s to non-container builder %s", child, builder);
+        ((NormalizedNodeContainerBuilder) builder).addChild(child);
+    }
+
+    @SuppressWarnings("unchecked")
+    void setValue(final Object value) {
+        checkState(!(builder instanceof NormalizedNodeContainerBuilder),
+            "Attempted to set value %s on container builder %s", value, builder);
+        builder.withValue(value);
+    }
 }
index 7cdd783..add933c 100644 (file)
@@ -39,9 +39,8 @@ 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.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
@@ -213,7 +212,7 @@ public final class TestModel {
 
     }
 
-    public static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createBaseTestContainerBuilder() {
+    public static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> createBaseTestContainerBuilder() {
         // Create a list of shoes
         // This is to test leaf list entry
         final LeafSetEntryNode<Object> nike = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
@@ -274,7 +273,7 @@ public final class TestModel {
         MapEntryNode augMapEntry = createAugmentedListEntry(1, "First Test");
 
         // Create a bits leaf
-        NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>>
+        NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>>
                 myBits = Builders.leafBuilder()
                 .withNodeIdentifier(new NodeIdentifier(QName.create(TEST_QNAME, "my-bits")))
                 .withValue(ImmutableSet.of("foo", "bar"));
@@ -368,7 +367,7 @@ public final class TestModel {
 
 
     public static ContainerNode createFamily() {
-        final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode>
+        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode>
             familyContainerBuilder = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
                         new YangInstanceIdentifier.NodeIdentifier(FAMILY_QNAME));
 
index e2a1d55..667e45d 100644 (file)
@@ -29,7 +29,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
@@ -224,7 +224,7 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
         @Override
         @SuppressFBWarnings("BC_UNCONFIRMED_CAST")
         public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
-            final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = Builders
+            final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = Builders
                     .mapEntryBuilder().withNodeIdentifier((NodeIdentifierWithPredicates) currentArg);
             for (final Entry<QName, Object> keyValue :
                     ((NodeIdentifierWithPredicates) currentArg).getKeyValues().entrySet()) {
index 6c6a5af..640ce37 100644 (file)
@@ -30,7 +30,7 @@ abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
     }
 
     @Override
-    public final DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
+    public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
         throw new UnsupportedOperationException("Not implemented");
     }
 
index f56d027..5f6ef15 100644 (file)
@@ -62,6 +62,11 @@ public class PruningDataTreeModification extends ForwardingObject implements Dat
         return delegate;
     }
 
+    @Override
+    public SchemaContext getSchemaContext() {
+        return delegate.getSchemaContext();
+    }
+
     @Override
     public void delete(final YangInstanceIdentifier yangInstanceIdentifier) {
         try {
index 0e7216f..4f79600 100644 (file)
@@ -17,7 +17,6 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import org.checkerframework.checker.lock.qual.GuardedBy;
@@ -33,15 +32,14 @@ import org.opendaylight.mdsal.dom.spi.store.DOMStoreTreeChangePublisher;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNodes;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException;
 import org.slf4j.Logger;
@@ -218,11 +216,12 @@ public class DistributedShardChangePublisher
         DataTreeCandidateNode modifiedChild = candidate.getRootNode();
 
         for (final PathArgument pathArgument : listenerPath.getPathArguments()) {
-            modifiedChild = modifiedChild.getModifiedChild(pathArgument);
+            modifiedChild = modifiedChild.getModifiedChild(pathArgument).orElse(null);
         }
 
+
         if (modifiedChild == null) {
-            modifiedChild = new EmptyDataTreeCandidateNode(dataTree.getRootPath().getLastPathArgument());
+            modifiedChild = DataTreeCandidateNodes.empty(dataTree.getRootPath().getLastPathArgument());
         }
 
         return DataTreeCandidates.newDataTreeCandidate(dataTree.getRootPath(), modifiedChild);
@@ -317,44 +316,4 @@ public class DistributedShardChangePublisher
             registrations.clear();
         }
     }
-
-    private static final class EmptyDataTreeCandidateNode implements DataTreeCandidateNode {
-
-        private final PathArgument identifier;
-
-        EmptyDataTreeCandidateNode(final PathArgument identifier) {
-            this.identifier = requireNonNull(identifier, "Identifier should not be null");
-        }
-
-        @Override
-        public PathArgument getIdentifier() {
-            return identifier;
-        }
-
-        @Override
-        public Collection<DataTreeCandidateNode> getChildNodes() {
-            return Collections.emptySet();
-        }
-
-        @Override
-        @SuppressWarnings("checkstyle:hiddenField")
-        public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
-            return null;
-        }
-
-        @Override
-        public ModificationType getModificationType() {
-            return ModificationType.UNMODIFIED;
-        }
-
-        @Override
-        public Optional<NormalizedNode<?, ?>> getDataAfter() {
-            return Optional.empty();
-        }
-
-        @Override
-        public Optional<NormalizedNode<?, ?>> getDataBefore() {
-            return Optional.empty();
-        }
-    }
 }
index 17f1c61..4c3c5f7 100644 (file)
@@ -25,7 +25,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
@@ -178,8 +177,8 @@ public final class CompositeModel {
     }
 
     public static ContainerNode createFamily() {
-        final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode>
-            familyContainerBuilder = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
+        final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> familyContainerBuilder =
+            ImmutableContainerNodeBuilder.create().withNodeIdentifier(
                     new YangInstanceIdentifier.NodeIdentifier(FAMILY_QNAME));
 
         final CollectionNodeBuilder<MapEntryNode, MapNode> childrenBuilder = mapNodeBuilder(CHILDREN_QNAME);
index 57dbf83..edc5561 100644 (file)
@@ -264,8 +264,7 @@ public class DOMDataTreeListenerTest {
         candidateRoot = candidate.getRootNode();
         checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.SUBTREE_MODIFIED, candidateRoot);
         final DataTreeCandidateNode modifiedChild = candidateRoot
-                .getModifiedChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME));
-        assertNotNull(modifiedChild);
+                .getModifiedChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).get();
         checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, modifiedChild);
         listenerReg.close();
     }
@@ -368,11 +367,11 @@ public class DOMDataTreeListenerTest {
         assertNotNull(candidate);
         candidateRoot = candidate.getRootNode();
         checkChange(OUTER_LIST, listAfter, ModificationType.SUBTREE_MODIFIED, candidateRoot);
-        final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1);
+        final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1).get();
         checkChange(outerListEntry1, null, ModificationType.DELETE, entry1Canditate);
-        final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2);
+        final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2).get();
         checkChange(null, outerListEntry2, ModificationType.WRITE, entry2Canditate);
-        final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3);
+        final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3).get();
         checkChange(null, outerListEntry3, ModificationType.WRITE, entry3Canditate);
         listenerReg.close();
     }
index e9b5594..3337d1c 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.md.sal.dom.store.impl;
 
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Optional;
 import java.util.concurrent.ExecutorService;
 import org.eclipse.jdt.annotation.NonNull;
@@ -17,7 +16,6 @@ import org.opendaylight.controller.md.sal.dom.spi.AbstractDOMDataTreeChangeListe
 import org.opendaylight.controller.sal.core.spi.data.AbstractDOMStoreTreeChangePublisher;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
-import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager.Invoker;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
@@ -28,22 +26,20 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChangePublisher {
-    private static final Invoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> MANAGER_INVOKER =
-        (listener, notification) -> {
-            // FIXME: this is inefficient, as we could grab the entire queue for the listener and post it
-            listener.getInstance().onDataTreeChanged(Collections.singletonList(notification));
-        };
-
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMStoreTreeChangePublisher.class);
+
     private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
             notificationManager;
 
     InMemoryDOMStoreTreeChangePublisher(final ExecutorService listenerExecutor, final int maxQueueSize) {
-        notificationManager = new QueuedNotificationManager<>(listenerExecutor, MANAGER_INVOKER, maxQueueSize,
+        notificationManager = QueuedNotificationManager.create(listenerExecutor, (listener, notifications) -> {
+            // FIXME: we are not checking for listener being closed
+            listener.getInstance().onDataTreeChanged(notifications);
+        }, maxQueueSize,
                 "DataTreeChangeListenerQueueMgr");
     }
 
-    private InMemoryDOMStoreTreeChangePublisher(QueuedNotificationManager<
+    private InMemoryDOMStoreTreeChangePublisher(final QueuedNotificationManager<
             AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> notificationManager) {
         this.notificationManager = notificationManager;
     }
index 5dd1f55..fe845d7 100644 (file)
@@ -32,7 +32,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
@@ -98,7 +97,7 @@ public abstract class AbstractDataTreeChangeListenerTest {
                         NAME_QNAME, topName));
     }
 
-    protected static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> top() {
+    protected static DataContainerNodeBuilder<NodeIdentifier, ContainerNode> top() {
         return Builders.containerBuilder().withNodeIdentifier(
                 new NodeIdentifier(Top.QNAME));
     }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.