Merge "Bug 2906 - Added support of entering notification by #streamChild()"
authorRobert Varga <nite@hq.sk>
Fri, 27 Mar 2015 10:52:48 +0000 (10:52 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 27 Mar 2015 10:52:48 +0000 (10:52 +0000)
86 files changed:
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/builder/MethodSignatureBuilder.java
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/builder/package-info.java
code-generator/binding-model-api/src/main/java/org/opendaylight/yangtools/sal/binding/model/api/type/provider/package-info.java
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/ClassBasedPropertyBuilder.java
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/CompositeObjectRegistration.java
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/Deserializer.java
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/InvertibleTransformator.java
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/Mutable.java
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/ProductAwareBuilder.java
common/mockito-configuration/src/main/java/org/mockito/configuration/ArgumentsExtractorVerifier.java
common/mockito-configuration/src/main/java/org/mockito/configuration/MockitoConfiguration.java
common/mockito-configuration/src/main/java/org/mockito/configuration/ThrowsUnstubbedMethodException.java
common/mockito-configuration/src/main/java/org/mockito/configuration/UnstubbedMethodException.java
common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/ObjectCache.java
common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java
common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/AbstractObjectCache.java
common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/AbstractObjectCacheBinder.java
common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/IObjectCacheFactory.java
common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/NoopObjectCache.java
common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/ObjectCacheFactoryBinder.java
common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/guava/GuavaObjectCacheFactory.java
common/object-cache-guava/src/main/java/org/opendaylight/yangtools/objcache/impl/StaticObjectCacheBinder.java
common/util/src/main/java/org/opendaylight/yangtools/util/UnmodifiableCollection.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/AsyncNotifyingListeningExecutorService.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/CachedThreadPoolExecutor.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/FastThreadPoolExecutor.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/ListenerNotificationQueueStats.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/BindingMapping.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifierBuilderImpl.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/DataObjectReadingUtil.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/util/NotificationListenerInvoker.java
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/OperationFailedException.java
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/RpcResultBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XMLStreamNormalizedNodeStreamWriter.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataNodeContainerModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractNodeContainerModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractValueNodeModificationStrategy.java [moved from yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ValueNodeModificationStrategy.java with 54% similarity]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AlwaysFailOperation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AugmentationModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChildTrackingPolicy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChoiceModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ContainerModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataNodeContainerModificationStrategy.java [deleted file]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeCandidate.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeFactory.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LatestOperationHolder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LeafModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LeafSetEntryModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListEntryModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModificationApplyOperation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ModifiedNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NormalizedNodeContainerModificationStrategy.java [deleted file]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OperationWithModification.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedLeafSetModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedMapModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/RootModificationApplyOperation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaAwareApplyOperation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnkeyedListItemModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnkeyedListModificationStrategy.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnorderedLeafSetModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnorderedMapModificationStrategy.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UpgradableModificationApplyOperation.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/SchemaAwareApplyOperationRoot.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/AugmentationSchema.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DerivableSchemaNode.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DocumentedNode.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/NamespaceRevisionAware.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContextHolder.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/ModuleStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/MissingSchemaSourceException.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaContextFactory.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaRepository.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaResolutionException.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaSourceException.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaSourceFilter.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaSourceRepresentation.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SourceIdentifier.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinSchemaSource.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/SchemaListenerRegistration.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/SchemaSourceListener.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/SchemaSourceProvider.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/SchemaSourceRegistration.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/SchemaSourceRegistry.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java

index ecdf997e316d807dcc2e981edb9d3a74e7e92d52..71374525b752f1e7b0d5a8a7236700c7ea26978f 100644 (file)
@@ -1,10 +1,9 @@
-/**
-
- *
- * March 2013
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
- * Copyright (c) 2013 by Cisco Systems, Inc.
- * 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.sal.binding.model.api.type.builder;
 
@@ -22,8 +21,8 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type;
  * The methods as {@link #addAnnotation(String, String)} and
  * {@link #setComment(String)} can be used as optional because not all methods
  * MUST contain annotation or comment definitions.
- * 
- * 
+ *
+ *
  * @see MethodSignature
  */
 public interface MethodSignatureBuilder extends TypeMemberBuilder<MethodSignatureBuilder> {
@@ -33,7 +32,7 @@ public interface MethodSignatureBuilder extends TypeMemberBuilder<MethodSignatur
      * the flag <code>isAbstract == true</code> The instantiated Method
      * Signature MUST have return value for {@link MethodSignature#isAbstract()}
      * also equals to <code>true</code>.
-     * 
+     *
      * @param isAbstract
      *            is abstract flag
      */
@@ -42,11 +41,11 @@ public interface MethodSignatureBuilder extends TypeMemberBuilder<MethodSignatur
     /**
      * Adds Parameter into the List of method parameters. Neither the Name or
      * Type of parameter can be <code>null</code>.
-     * 
+     *
      * <br>
      * In case that any of parameters are defined as <code>null</code> the
      * method SHOULD throw an {@link IllegalArgumentException}
-     * 
+     *
      * @param type
      *            Parameter Type
      * @param name
@@ -61,7 +60,7 @@ public interface MethodSignatureBuilder extends TypeMemberBuilder<MethodSignatur
      * <code>class</code> or <code>interface</code> definition. In case that
      * defining Type will be passed as <code>null</code> reference the method
      * SHOULD thrown {@link IllegalArgumentException}.
-     * 
+     *
      * @param definingType
      *            Defining Type of Method Signature
      * @return <code>new</code> <i>immutable</i> instance of Method Signature.
index e4ac5a8505394da281d914c216445f103ed06e47..f46cc4c35535a4640572dd20d082b965b17ea370 100644 (file)
@@ -1,9 +1,8 @@
-/**
-
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
- * March 2013
- *
- * Copyright (c) 2013 by Cisco Systems, Inc.
- * 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.sal.binding.model.api.type.builder;
\ No newline at end of file
index 4763f3931e95efb0c7f35902f3d9c5aa553be28a..b88b1abf9f136ceaea411c569899685661a729f5 100644 (file)
@@ -1,9 +1,8 @@
-/**
-
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
- * March 2013
- *
- * Copyright (c) 2013 by Cisco Systems, Inc.
- * 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.sal.binding.model.api.type.provider;
\ No newline at end of file
index 85016b8e10835f4b172a3d8d75445a0642e0a2fd..2a2e70315edb0a060a814187302b1bf3a83b9a90 100644 (file)
@@ -7,21 +7,20 @@
  */
 package org.opendaylight.yangtools.concepts;
 
-public interface ClassBasedPropertyBuilder<P,T extends ClassBasedPropertyBuilder<P,T>> extends Builder<P> {
-
+public interface ClassBasedPropertyBuilder<P, T extends ClassBasedPropertyBuilder<P, T>> extends Builder<P> {
     /**
      * Sets a value of property uniquely identified by its
      * class.
-     * 
+     *
      * @param type Type of property to set
-     * @param value Value of property 
+     * @param value Value of property
      * @return Builder instance
      */
     <V> T set(Class<V> type, V value);
-    
+
     /**
      * Gets a value of property based on its type.
-     * 
+     *
      * @param type Type of property to get
      * @return Builder instance
      */
index 34bafc2dc1a285517c220bb22795e1a0e736e513..ab3c91e01c43590b014b4ef2a21a0c5ab61669c0 100644 (file)
@@ -39,8 +39,7 @@ public final class CompositeObjectRegistration<T> extends AbstractObjectRegistra
         return new CompositeObjectRegistrationBuilder<>(instance);
     }
 
-    public static final class CompositeObjectRegistrationBuilder<T> implements //
-    Builder<CompositeObjectRegistration<T>> {
+    public static final class CompositeObjectRegistrationBuilder<T> implements Builder<CompositeObjectRegistration<T>> {
 
         private final T instance;
         private final Set<Registration> registrations;
index 77034b8b2578eb437667c1a07d584be74f5e10d3..11dffc455bc59464c43da36fe35d3691db4263c9 100644 (file)
@@ -7,7 +7,18 @@
  */
 package org.opendaylight.yangtools.concepts;
 
-public interface Deserializer<P,I> {
-
+/**
+ * The concept of a serializer, which produces an object from some input.
+ *
+ * @param <P> Product type
+ * @param <I> Input type
+ */
+public interface Deserializer<P, I> {
+    /**
+     * Produce an object base on input.
+     *
+     * @param input Input object
+     * @return Product derived from input
+     */
     P deserialize(I input);
 }
index 31ca3b5ca741b9e70182c4639686b2fff450b616..51ebc22cc71080b4a45af34e80f6cfe0d3ba32e7 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.concepts;
 
-public interface InvertibleTransformator<P, I> extends Transformator<P, I>{
+public interface InvertibleTransformator<P, I> extends Transformator<P, I> {
 
     I fromProduct(P product);
 
index af08aa1d88ab7b3fd6dccbaf3f3cb1e54590db96..82b2bb11571f8da41e8ef9f894b766c8f46e1009 100644 (file)
@@ -9,13 +9,13 @@ package org.opendaylight.yangtools.concepts;
 
 /**
  * Mutable object - object may change it's state during lifecycle.
- * 
+ *
  * This interface is mutually exclusive with {@link Immutable}  and other
  * {@link MutationBehaviour}s.
- * 
+ *
  * @author Tony Tkacik
  *
  */
-public interface Mutable extends MutationBehaviour<Mutable>{
-    
+public interface Mutable extends MutationBehaviour<Mutable> {
+
 }
index 771ceb2cac976dc35addf4ed4f57620d1de1e6dd..0ac9fdabe12769096f462cc99e1d5e46816f50d5 100644 (file)
@@ -15,22 +15,22 @@ package org.opendaylight.yangtools.concepts;
  * @param <P> Product type
  */
 public interface ProductAwareBuilder<P> extends Builder<P> {
-       /**
-        * Return the hash code of the product. This has to be equivalent
-        * of calling {@link #build()}.{@link Object#hashCode()}.
-        *
-        * @return the hash code of the product.
-        */
-       int productHashCode();
+    /**
+     * Return the hash code of the product. This has to be equivalent
+     * of calling {@link #build()}.{@link Object#hashCode()}.
+     *
+     * @return the hash code of the product.
+     */
+    int productHashCode();
 
-       /**
-        * Check whether an instance of the product that would be created
-        * by the builder is equal to an existing instance. This has to
-        * be equivalent of calling {@link #build()}.{@link Object#equals(Object)}.
-        *
-        * @param product Product instance
-        * @return Return true if the product is equal to the would-be
-        *         product of the builder.
-        */
-       boolean productEquals(Object product);
+    /**
+     * Check whether an instance of the product that would be created
+     * by the builder is equal to an existing instance. This has to
+     * be equivalent of calling {@link #build()}.{@link Object#equals(Object)}.
+     *
+     * @param product Product instance
+     * @return Return true if the product is equal to the would-be
+     *         product of the builder.
+     */
+    boolean productEquals(Object product);
 }
index 53db342c071d28a62b6e4396a44cfb038c33b7db..d8983f40fbac5062cf694e36f2f12c92b122d1e5 100644 (file)
@@ -7,34 +7,32 @@
  */
 package org.mockito.configuration;
 
+import java.util.List;
 import org.mockito.exceptions.base.MockitoException;
 import org.mockito.internal.invocation.InvocationsFinder;
 import org.mockito.internal.verification.api.VerificationData;
 import org.mockito.invocation.Invocation;
 import org.mockito.verification.VerificationMode;
 
-import java.util.List;
-
 /**
  * Verifier that extracts arguments from actual invocation. Useful when deeper validation of arguments is needed.
- *
  */
 public class ArgumentsExtractorVerifier implements VerificationMode {
-               private Object[] arguments;
+    private Object[] arguments;
 
-               @Override
-               public void verify(VerificationData data) {
-                       InvocationsFinder finder = new InvocationsFinder();
-                       List<Invocation> actualInvocations = finder.findInvocations(data.getAllInvocations(), data.getWanted());
-                       if (actualInvocations.size() != 1) {
-                               throw new MockitoException("This verifier can only be used with 1 invocation, got " + actualInvocations.size());
-                       }
-                       Invocation invocation = actualInvocations.get(0);
-                       arguments = invocation.getArguments();
-                       invocation.markVerified();
+    @Override
+    public void verify(final VerificationData data) {
+        InvocationsFinder finder = new InvocationsFinder();
+        List<Invocation> actualInvocations = finder.findInvocations(data.getAllInvocations(), data.getWanted());
+        if (actualInvocations.size() != 1) {
+            throw new MockitoException("This verifier can only be used with 1 invocation, got " + actualInvocations.size());
+        }
+        Invocation invocation = actualInvocations.get(0);
+        arguments = invocation.getArguments();
+        invocation.markVerified();
 
-               }
-               public Object[] getArguments(){
-                       return arguments;
-               }
-       }
+    }
+    public Object[] getArguments() {
+        return arguments;
+    }
+}
index 6c783e005d6654aff84ef38314f40186270d3221..b6909b5c443520ab24c009adeed75b191c8e22b5 100644 (file)
@@ -13,9 +13,8 @@ import org.mockito.stubbing.Answer;
  * Configuration customization for Mockito. Change default answer to {@link ThrowsUnstubbedMethodException}.
  */
 public class MockitoConfiguration extends DefaultMockitoConfiguration {
-
-       @Override
-       public Answer<Object> getDefaultAnswer() {
-               return new ThrowsUnstubbedMethodException();
-       }
+    @Override
+    public Answer<Object> getDefaultAnswer() {
+        return new ThrowsUnstubbedMethodException();
+    }
 }
index 83262bc5185ee9bdf768f7359dde3ce7bf4ac6f5..95b5c2054d41b32242b69676e50447178e414110 100644 (file)
@@ -8,7 +8,6 @@
 package org.mockito.configuration;
 
 import java.io.Serializable;
-
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -16,14 +15,10 @@ import org.mockito.stubbing.Answer;
  * Answer that throws {@link UnstubbedMethodException}.
  */
 public class ThrowsUnstubbedMethodException implements Answer<Object>, Serializable {
-       private static final long serialVersionUID = 1L;
-
-    public ThrowsUnstubbedMethodException() {
-    }
+    private static final long serialVersionUID = 1L;
 
     @Override
-       public Object answer(InvocationOnMock invocation) throws Throwable {
-        Throwable t = new UnstubbedMethodException(invocation.toString() + " was not stubbed");
-        throw t;
+    public Object answer(final InvocationOnMock invocation) throws UnstubbedMethodException {
+        throw new UnstubbedMethodException(invocation.toString() + " was not stubbed");
     }
 }
index ac748661c03b8eaa404719f6531bf2d8fae9391f..5432e7c83260402451c7293f27730495c8b7ff73 100644 (file)
@@ -7,16 +7,13 @@
  */
 package org.mockito.configuration;
 
-
 /**
  * Exception to be thrown on unstubbed method call.
  */
 public class UnstubbedMethodException extends RuntimeException {
+    private static final long serialVersionUID = 1L;
 
-       private static final long serialVersionUID = 1L;
-
-       public UnstubbedMethodException(String message) {
-               super(message);
-       }
-
+    public UnstubbedMethodException(final String message) {
+        super(message);
+    }
 }
index 9f3276837d035e989c25b446dbb9f1f53b2bd18b..4e275924248252ac351f971dcc026f1b4d93337e 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.objcache;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
-
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.concepts.ProductAwareBuilder;
 
@@ -19,32 +18,35 @@ import org.opendaylight.yangtools.concepts.ProductAwareBuilder;
  * a cache in the instantiation path, one can expend some memory on
  * indexes and spend some CPU cycles on walking the index to potentially
  * end up with a reused object.
- * 
+ *
  * Note that the cached objects should really be semantically {@link Immutable}.
  * This interface does not enforce that interface contract simply because
  * there are third-party objects which fulfill this contract.
  */
 public interface ObjectCache {
-       /**
-        * Get a reference for an object which is equal to specified object.
-        * The cache is free return either a cached instance, or retain the
-        * object and return it back.
-        *
-        * @param object Requested object, may be null
-        * @return Reference to an object which is equal to the one passed in.
-        *         If @object was @null, this method returns @null.
-        */
-       <T> T getReference(@Nullable T object);
+    /**
+     * Get a reference for an object which is equal to specified object.
+     * The cache is free return either a cached instance, or retain the
+     * object and return it back.
+     *
+     * @param <T> object type
+     * @param object Requested object, may be null
+     * @return Reference to an object which is equal to the one passed in.
+     *         If @object was @null, this method returns @null.
+     */
+    <T> T getReference(@Nullable T object);
 
-       /**
-        * Get a reference to an object equal to the product of a builder.
-        * The builder is expected to remain constant while this method
-        * executes. Unlike {@link #getReference(Object)}, this method has
-        * the potential of completely eliding the product instantiation.
-        * 
-        * @param builder Builder instance, may not be null
-        * @return Result of builder's toInstance() product, or an equal
-        *         object.
-        */
-       <B extends ProductAwareBuilder<P>, P> P getProduct(@Nonnull B builder);
+    /**
+     * Get a reference to an object equal to the product of a builder.
+     * The builder is expected to remain constant while this method
+     * executes. Unlike {@link #getReference(Object)}, this method has
+     * the potential of completely eliding the product instantiation.
+     *
+     * @param <P> produced object type
+     * @param <B> builder type
+     * @param builder Builder instance, may not be null
+     * @return Result of builder's toInstance() product, or an equal
+     *         object.
+     */
+    <B extends ProductAwareBuilder<P>, P> P getProduct(@Nonnull B builder);
 }
index 59cd30f05a2fedeb8ff841e1985e1347034f0b2c..352d7df6250339976a87dc6b8a3e0d861d499d5d 100644 (file)
@@ -14,11 +14,11 @@ import org.opendaylight.yangtools.objcache.spi.AbstractObjectCacheBinder;
  * it at compile-time, but it is not packaged and thus not present at run-time.
  */
 public final class StaticObjectCacheBinder extends AbstractObjectCacheBinder {
-       private StaticObjectCacheBinder() {
-               super(null);
-       }
+    private StaticObjectCacheBinder() {
+        super(null);
+    }
 
-       public static StaticObjectCacheBinder getInstance() {
-               throw new IllegalStateException("This class should have been replaced");
-       }
+    public static StaticObjectCacheBinder getInstance() {
+        throw new IllegalStateException("This class should have been replaced");
+    }
 }
index 3e09e967ca8fdd86765cb4f9343bc3e1fae1ad8d..51ed7ae4acfc9c224aeb42def0e91855e20867e0 100644 (file)
@@ -84,8 +84,8 @@ public abstract class AbstractObjectCache implements ObjectCache {
     protected abstract static class SoftKey<T> extends FinalizableSoftReference<T> {
         private final int hashCode;
 
-        public SoftKey(final T referent, final FinalizableReferenceQueue q) {
-            super(Preconditions.checkNotNull(referent), q);
+        public SoftKey(final T referent, final FinalizableReferenceQueue queue) {
+            super(Preconditions.checkNotNull(referent), queue);
             hashCode = referent.hashCode();
         }
 
index be860eadcf8d160431cf681313bc0ac8794bf785..776f7273a8655a9ff6ecc9f60aea6d1bf49d34a2 100644 (file)
@@ -7,19 +7,18 @@
  */
 package org.opendaylight.yangtools.objcache.spi;
 
-import javax.annotation.Nonnull;
-
 import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
 
 public abstract class AbstractObjectCacheBinder implements ObjectCacheFactoryBinder {
-       private final IObjectCacheFactory factory;
+    private final IObjectCacheFactory factory;
 
-       protected AbstractObjectCacheBinder(@Nonnull final IObjectCacheFactory factory) {
-               this.factory = Preconditions.checkNotNull(factory);
-       }
+    protected AbstractObjectCacheBinder(@Nonnull final IObjectCacheFactory factory) {
+        this.factory = Preconditions.checkNotNull(factory);
+    }
 
-       @Override
-       public final IObjectCacheFactory getProductCacheFactory() {
-               return factory;
-       }
+    @Override
+    public final IObjectCacheFactory getProductCacheFactory() {
+        return factory;
+    }
 }
index 7ee6bc411f2685cc9f2f5468f130cfc3820d9ee4..8a5047aa4fb5f981d9183377e2c15aff40807a8b 100644 (file)
@@ -8,9 +8,8 @@
 package org.opendaylight.yangtools.objcache.spi;
 
 import javax.annotation.Nonnull;
-
 import org.opendaylight.yangtools.objcache.ObjectCache;
 
 public interface IObjectCacheFactory {
-       ObjectCache getObjectCache(@Nonnull Class<?> objClass);
+    ObjectCache getObjectCache(@Nonnull Class<?> objClass);
 }
index a44543bfb2014569676117ec53ed636a9cc528da..e55f590ac6397c55d92c3e86c1e7b17e6fc0eec3 100644 (file)
@@ -15,29 +15,29 @@ import org.opendaylight.yangtools.objcache.ObjectCache;
  * does not do any caching, so it only returns the request object.
  */
 public final class NoopObjectCache implements ObjectCache {
-       private static final NoopObjectCache INSTANCE = new NoopObjectCache();
+    private static final NoopObjectCache INSTANCE = new NoopObjectCache();
 
-       private NoopObjectCache() {
+    private NoopObjectCache() {
 
-       }
+    }
 
-       /**
-        * Get the cache instance. Since the cache does not have any state,
-        * this method always returns a singleton instance.
-        *
-        * @return Cache instance.
-        */
-       public static NoopObjectCache getInstance() {
-               return INSTANCE;
-       }
+    /**
+     * Get the cache instance. Since the cache does not have any state,
+     * this method always returns a singleton instance.
+     *
+     * @return Cache instance.
+     */
+    public static NoopObjectCache getInstance() {
+        return INSTANCE;
+    }
 
-       @Override
-       public <T> T getReference(final T object) {
-               return object;
-       }
+    @Override
+    public <T> T getReference(final T object) {
+        return object;
+    }
 
-       @Override
-       public <B extends ProductAwareBuilder<P>, P> P getProduct(final B builder) {
-               return builder.build();
-       }
+    @Override
+    public <B extends ProductAwareBuilder<P>, P> P getProduct(final B builder) {
+        return builder.build();
+    }
 }
index 012428c04490061d957489bbda92e1db1f43f130..ab6f49bac261c7dcdc6580189aa721762b0eac42 100644 (file)
@@ -11,10 +11,10 @@ package org.opendaylight.yangtools.objcache.spi;
  * Interface binding an implementation into ObjectCacheFactory.
  */
 public interface ObjectCacheFactoryBinder {
-       /**
-        * Get the implementation-specific cache factory.
-        * 
-        * @return Implementation-specific factory.
-        */
-       IObjectCacheFactory getProductCacheFactory();
+    /**
+     * Get the implementation-specific cache factory.
+     *
+     * @return Implementation-specific factory.
+     */
+    IObjectCacheFactory getProductCacheFactory();
 }
index 895037625ddbf04e778f5cf4829da7a1b63de073..1ee0750b65a348d5ff70917571923e4b0cf0b12f 100644 (file)
@@ -7,11 +7,10 @@
  */
 package org.opendaylight.yangtools.objcache.guava;
 
+import com.google.common.base.FinalizableReferenceQueue;
 import org.opendaylight.yangtools.objcache.ObjectCache;
 import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory;
 
-import com.google.common.base.FinalizableReferenceQueue;
-
 public final class GuavaObjectCacheFactory implements AutoCloseable, IObjectCacheFactory {
     private static final GuavaObjectCacheFactory INSTANCE = new GuavaObjectCacheFactory();
     private final FinalizableReferenceQueue  queue = new FinalizableReferenceQueue();
@@ -29,9 +28,14 @@ public final class GuavaObjectCacheFactory implements AutoCloseable, IObjectCach
 
     @Override
     public void close() {
-       queue.close();
+        queue.close();
     }
 
+    /**
+     * Return a factory instance.
+     *
+     * @return A factory instance.
+     */
     public static GuavaObjectCacheFactory getInstance() {
         return INSTANCE;
     }
index 5867d556c9f2a763a5262cbefbe47e41ef37166a..ff46d729921395066d800bf37565eab1073cee6c 100644 (file)
@@ -11,13 +11,13 @@ import org.opendaylight.yangtools.objcache.guava.GuavaObjectCacheFactory;
 import org.opendaylight.yangtools.objcache.spi.AbstractObjectCacheBinder;
 
 public final class StaticObjectCacheBinder extends AbstractObjectCacheBinder {
-       private static final StaticObjectCacheBinder INSTANCE = new StaticObjectCacheBinder();
+    private static final StaticObjectCacheBinder INSTANCE = new StaticObjectCacheBinder();
 
-       private StaticObjectCacheBinder() {
-               super(GuavaObjectCacheFactory.getInstance());
-       }
+    private StaticObjectCacheBinder() {
+        super(GuavaObjectCacheFactory.getInstance());
+    }
 
-       public static StaticObjectCacheBinder getInstance() {
-               return INSTANCE;
-       }
+    public static StaticObjectCacheBinder getInstance() {
+        return INSTANCE;
+    }
 }
index 5b9d98a641dac4a26bd6306977679efab303a882..dc090a4c5bb90dd9f4f18e9cfa2980c340072470 100644 (file)
@@ -58,10 +58,11 @@ public final class UnmodifiableCollection<E> implements Collection<E>, Serializa
      * @param collection Target collection
      * @return An unmodifiable view of the collection
      */
-    public static <T> Collection<T> create(final @Nonnull Collection<T> collection) {
-        if (collection instanceof UnmodifiableCollection || collection instanceof ImmutableCollection ||
-                Collections.EMPTY_LIST == collection || Collections.EMPTY_SET == collection ||
-                UNMODIFIABLE_COLLECTION_CLASS.isInstance(collection) || SINGLETON_CLASSES.contains(collection.getClass())) {
+    public static <T> Collection<T> create(@Nonnull final Collection<T> collection) {
+        if (collection instanceof UnmodifiableCollection || collection instanceof ImmutableCollection
+                || Collections.EMPTY_LIST == collection || Collections.EMPTY_SET == collection
+                || UNMODIFIABLE_COLLECTION_CLASS.isInstance(collection)
+                || SINGLETON_CLASSES.contains(collection.getClass())) {
             return collection;
         }
 
index c5d00771ea27bde932207f741e3c76f910629ee8..d57ded358f4ab7b1013c84ab4edd03119ceb327c 100644 (file)
@@ -8,20 +8,18 @@
 
 package org.opendaylight.yangtools.util.concurrent;
 
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.AbstractListeningExecutorService;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
-
 import javax.annotation.Nullable;
 
-import com.google.common.base.MoreObjects;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.AbstractListeningExecutorService;
-import com.google.common.util.concurrent.ListenableFuture;
-
 /**
  * An {@link com.google.common.util.concurrent.ListeningExecutorService} implementation that also allows for an {@link Executor} to be
  * specified on construction that is used to execute {@link ListenableFuture} callback Runnables,
@@ -56,8 +54,8 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe
      * @param listenableFutureExecutor the executor used to run listener callbacks asynchronously.
      *     If null, no executor is used.
      */
-    public AsyncNotifyingListeningExecutorService( ExecutorService delegate,
-            @Nullable Executor listenableFutureExecutor ) {
+    public AsyncNotifyingListeningExecutorService( final ExecutorService delegate,
+            @Nullable final Executor listenableFutureExecutor ) {
         this.delegate = Preconditions.checkNotNull( delegate );
         this.listenableFutureExecutor = listenableFutureExecutor;
     }
@@ -67,7 +65,7 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe
      *
      * @param task the Callable to execute
      */
-    private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask( Callable<T> task ) {
+    private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask( final Callable<T> task ) {
         return AsyncNotifyingListenableFutureTask.create( task, listenableFutureExecutor );
     }
 
@@ -76,7 +74,7 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe
      *
      * @param task the Runnable to execute
      */
-    private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask( Runnable task, T result ) {
+    private <T> AsyncNotifyingListenableFutureTask<T> newFutureTask( final Runnable task, final T result ) {
         return AsyncNotifyingListenableFutureTask.create( task, result, listenableFutureExecutor );
     }
 
@@ -88,7 +86,7 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe
     }
 
     @Override
-    public boolean awaitTermination( long timeout, TimeUnit unit ) throws InterruptedException {
+    public boolean awaitTermination( final long timeout, final TimeUnit unit ) throws InterruptedException {
         return delegate.awaitTermination( timeout, unit );
     }
 
@@ -113,37 +111,37 @@ public class AsyncNotifyingListeningExecutorService extends AbstractListeningExe
     }
 
     @Override
-    public void execute( Runnable command ) {
+    public void execute( final Runnable command ) {
         delegate.execute( command );
     }
 
     @Override
-    public <T> ListenableFuture<T> submit( Callable<T> task ) {
+    public <T> ListenableFuture<T> submit( final Callable<T> task ) {
         AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask( task );
         delegate.execute( futureTask );
         return futureTask;
     }
 
     @Override
-    public ListenableFuture<?> submit( Runnable task ) {
+    public ListenableFuture<?> submit( final Runnable task ) {
         AsyncNotifyingListenableFutureTask<Void> futureTask = newFutureTask( task, null );
         delegate.execute( futureTask );
         return futureTask;
     }
 
     @Override
-    public <T> ListenableFuture<T> submit( Runnable task, T result ) {
+    public <T> ListenableFuture<T> submit( final Runnable task, final T result ) {
         AsyncNotifyingListenableFutureTask<T> futureTask = newFutureTask( task, result );
         delegate.execute( futureTask );
         return futureTask;
     }
 
-    protected ToStringHelper addToStringAttributes( ToStringHelper toStringHelper ) {
+    protected ToStringHelper addToStringAttributes( final ToStringHelper toStringHelper ) {
         return toStringHelper;
     }
 
     @Override
-    public final String toString(){
+    public final String toString() {
         return addToStringAttributes( MoreObjects.toStringHelper( this )
                 .add( "delegate", delegate ) ).toString();
     }
index 66d332b5d7c6468b0aff6a1088dcd380fdef30a0..e7672ac4586351f81e8e977c649c2ed3d2a47df8 100644 (file)
@@ -7,6 +7,10 @@
  */
 package org.opendaylight.yangtools.util.concurrent;
 
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.RejectedExecutionException;
@@ -14,10 +18,6 @@ import java.util.concurrent.RejectedExecutionHandler;
 import java.util.concurrent.SynchronousQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
 
 /**
  * A ThreadPoolExecutor with a specified bounded queue capacity that favors reusing previously
@@ -50,7 +50,7 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
      * @param threadPrefix
      *            the name prefix for threads created by this executor.
      */
-    public CachedThreadPoolExecutor( int maximumPoolSize, int maximumQueueSize, String threadPrefix ) {
+    public CachedThreadPoolExecutor( final int maximumPoolSize, final int maximumQueueSize, final String threadPrefix ) {
         // We're using a custom SynchronousQueue that has a backing bounded LinkedBlockingQueue.
         // We don't specify any core threads (first parameter) so, when a task is submitted,
         // the base class will always try to offer to the queue. If there is an existing waiting
@@ -77,18 +77,18 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
     }
 
     @Override
-    public void setRejectedExecutionHandler( RejectedExecutionHandler handler ) {
+    public void setRejectedExecutionHandler( final RejectedExecutionHandler handler ) {
         Preconditions.checkNotNull( handler );
         rejectedTaskHandler.setDelegateRejectedExecutionHandler( handler );
     }
 
     @Override
-    public RejectedExecutionHandler getRejectedExecutionHandler(){
+    public RejectedExecutionHandler getRejectedExecutionHandler() {
         return rejectedTaskHandler.getDelegateRejectedExecutionHandler();
     }
 
     @Override
-    public BlockingQueue<Runnable> getQueue(){
+    public BlockingQueue<Runnable> getQueue() {
         return executorQueue.getBackingQueue();
     }
 
@@ -96,7 +96,7 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
         return ((TrackingLinkedBlockingQueue<?>)executorQueue.getBackingQueue()).getLargestQueueSize();
     }
 
-    protected ToStringHelper addToStringAttributes( ToStringHelper toStringHelper ) {
+    protected ToStringHelper addToStringAttributes( final ToStringHelper toStringHelper ) {
         return toStringHelper;
     }
 
@@ -130,7 +130,7 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
 
         private final LinkedBlockingQueue<Runnable> backingQueue;
 
-        ExecutorQueue( int maxBackingQueueSize ) {
+        ExecutorQueue( final int maxBackingQueueSize ) {
             backingQueue = new TrackingLinkedBlockingQueue<>( maxBackingQueueSize );
         }
 
@@ -139,7 +139,7 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
         }
 
         @Override
-        public Runnable poll( long timeout, TimeUnit unit ) throws InterruptedException {
+        public Runnable poll( final long timeout, final TimeUnit unit ) throws InterruptedException {
             long totalWaitTime = unit.toMillis( timeout );
             long waitTime = Math.min( totalWaitTime, POLL_WAIT_TIME_IN_MS );
             Runnable task = null;
@@ -156,10 +156,10 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
             //   periods, one thread will eventually wake up and get the task from the backingQueue
             //   and execute it, although slightly delayed.
 
-            while( task == null ) {
+            while (task == null) {
                 // First try to get a task from the backing queue.
                 task = backingQueue.poll();
-                if( task == null ) {
+                if (task == null) {
                     // No task in backing - call the base class to wait for one to be offered.
                     task = super.poll( waitTime, TimeUnit.MILLISECONDS );
 
@@ -193,14 +193,14 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
         private final LinkedBlockingQueue<Runnable> backingQueue;
         private volatile RejectedExecutionHandler delegateRejectedExecutionHandler;
 
-        RejectedTaskHandler( LinkedBlockingQueue<Runnable> backingQueue,
-                             RejectedExecutionHandler delegateRejectedExecutionHandler ) {
+        RejectedTaskHandler( final LinkedBlockingQueue<Runnable> backingQueue,
+                             final RejectedExecutionHandler delegateRejectedExecutionHandler ) {
             this.backingQueue = backingQueue;
             this.delegateRejectedExecutionHandler = delegateRejectedExecutionHandler;
         }
 
         void setDelegateRejectedExecutionHandler(
-                RejectedExecutionHandler delegateRejectedExecutionHandler ) {
+                final RejectedExecutionHandler delegateRejectedExecutionHandler ) {
             this.delegateRejectedExecutionHandler = delegateRejectedExecutionHandler;
         }
 
@@ -209,12 +209,12 @@ public class CachedThreadPoolExecutor extends ThreadPoolExecutor {
         }
 
         @Override
-        public void rejectedExecution( Runnable task, ThreadPoolExecutor executor ) {
-            if( executor.isShutdown() ) {
+        public void rejectedExecution( final Runnable task, final ThreadPoolExecutor executor ) {
+            if (executor.isShutdown()) {
                 throw new RejectedExecutionException( "Executor has been shutdown." );
             }
 
-            if( !backingQueue.offer( task ) ) {
+            if (!backingQueue.offer(task)) {
                 delegateRejectedExecutionHandler.rejectedExecution( task, executor );
             }
         }
index 60a1b674609f6ef8268439e952f3fbdb260b432b..77a5846419e9db142c172d4dd30782a2827dbd37 100644 (file)
@@ -8,12 +8,11 @@
 
 package org.opendaylight.yangtools.util.concurrent;
 
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 
 /**
  * A ThreadPoolExecutor with a specified bounded queue capacity that favors creating new threads
@@ -41,7 +40,7 @@ public class FastThreadPoolExecutor extends ThreadPoolExecutor {
      * @param threadPrefix
      *            the name prefix for threads created by this executor.
      */
-    public FastThreadPoolExecutor( int maximumPoolSize, int maximumQueueSize, String threadPrefix ) {
+    public FastThreadPoolExecutor( final int maximumPoolSize, final int maximumQueueSize, final String threadPrefix ) {
         this( maximumPoolSize, maximumQueueSize, DEFAULT_IDLE_TIMEOUT_IN_SEC, TimeUnit.SECONDS,
               threadPrefix );
     }
@@ -60,8 +59,8 @@ public class FastThreadPoolExecutor extends ThreadPoolExecutor {
      * @param threadPrefix
      *            the name prefix for threads created by this executor.
      */
-    public FastThreadPoolExecutor( int maximumPoolSize, int maximumQueueSize, long keepAliveTime,
-            TimeUnit unit, String threadPrefix ) {
+    public FastThreadPoolExecutor( final int maximumPoolSize, final int maximumQueueSize, final long keepAliveTime,
+            final TimeUnit unit, final String threadPrefix ) {
         // We use all core threads (the first 2 parameters below equal) so, when a task is submitted,
         // if the thread limit hasn't been reached, a new thread will be spawned to execute
         // the task even if there is an existing idle thread in the pool. This is faster than
@@ -77,7 +76,7 @@ public class FastThreadPoolExecutor extends ThreadPoolExecutor {
         setThreadFactory( new ThreadFactoryBuilder().setDaemon( true )
                                                  .setNameFormat( threadPrefix + "-%d" ).build() );
 
-        if( keepAliveTime > 0 ) {
+        if (keepAliveTime > 0) {
             // Need to specifically configure core threads to timeout.
             allowCoreThreadTimeOut( true );
         }
@@ -89,7 +88,7 @@ public class FastThreadPoolExecutor extends ThreadPoolExecutor {
         return ((TrackingLinkedBlockingQueue<?>)getQueue()).getLargestQueueSize();
     }
 
-    protected ToStringHelper addToStringAttributes( ToStringHelper toStringHelper ) {
+    protected ToStringHelper addToStringAttributes( final ToStringHelper toStringHelper ) {
         return toStringHelper;
     }
 
index a8edd9ab462cf3cca541cec9e6cb0f114a576ca8..7da1e4bddc2261282dcdab42fcb1253c2145b0eb 100644 (file)
@@ -22,8 +22,8 @@ public class ListenerNotificationQueueStats {
     private final String listenerClassName;
     private final int currentQueueSize;
 
-    @ConstructorProperties({"listenerClassName","currentQueueSize"})
-    public ListenerNotificationQueueStats( String listenerClassName, int currentQueueSize ) {
+    @ConstructorProperties({ "listenerClassName","currentQueueSize" })
+    public ListenerNotificationQueueStats( final String listenerClassName, final int currentQueueSize ) {
         this.listenerClassName = listenerClassName;
         this.currentQueueSize = currentQueueSize;
     }
@@ -31,14 +31,14 @@ public class ListenerNotificationQueueStats {
     /**
      * Returns the name of the listener class.
      */
-    public String getListenerClassName(){
+    public String getListenerClassName() {
         return listenerClassName;
     }
 
     /**
      * Returns the current notification queue size.
      */
-    public int getCurrentQueueSize(){
+    public int getCurrentQueueSize() {
         return currentQueueSize;
     }
 }
index d628de016c44354fd721b5ba3f9a094799795d87..b13ab14043c44bdcce8863dacc8d858495c33121 100644 (file)
@@ -8,16 +8,13 @@
 package org.opendaylight.yangtools.yang.binding;
 
 import static com.google.common.base.Preconditions.checkArgument;
-
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Splitter;
 import com.google.common.collect.ImmutableSet;
-
 import java.text.SimpleDateFormat;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 
@@ -156,7 +153,7 @@ public final class BindingMapping {
 
     public static String getPropertyName(final String yangIdentifier) {
         final String potential = toFirstLower(toCamelCase(yangIdentifier));
-        if("class".equals(potential)) {
+        if ("class".equals(potential)) {
             return "xmlClass";
         }
         return potential;
index 5be717b574dbba76ea56458a0bb95fb8e7dd8bf0..6060f57c35ce33b701670a553242cdc4cd35a3f6 100644 (file)
@@ -7,15 +7,14 @@
  */
 package org.opendaylight.yangtools.yang.binding;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 import org.opendaylight.yangtools.util.HashCodeBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Item;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
 final class InstanceIdentifierBuilderImpl<T extends DataObject> implements InstanceIdentifier.InstanceIdentifierBuilder<T> {
     private final ImmutableList.Builder<PathArgument> pathBuilder = ImmutableList.builder();
     private final HashCodeBuilder<PathArgument> hashBuilder;
@@ -54,7 +53,7 @@ final class InstanceIdentifierBuilderImpl<T extends DataObject> implements Insta
     }
 
     @SuppressWarnings("unchecked")
-    <N extends DataObject & Identifiable<K> , K extends Identifier<N>> InstanceIdentifierBuilderImpl<N> addNode(final Class<N> listItem, final K listKey) {
+    <N extends DataObject & Identifiable<K>, K extends Identifier<N>> InstanceIdentifierBuilderImpl<N> addNode(final Class<N> listItem, final K listKey) {
         arg = new IdentifiableItem<N, K>(listItem, listKey);
         hashBuilder.addArgument(arg);
         pathBuilder.add(arg);
@@ -103,6 +102,7 @@ final class InstanceIdentifierBuilderImpl<T extends DataObject> implements Insta
     /*
      * @deprecated Use #build() instead.
      */
+    @Override
     @Deprecated
     public InstanceIdentifier<T> toInstance() {
         return build();
index b187013b179a0c5a89f481570f15ccf554ee0044..23bb4ccde1f05a320e811b172a5c7a54392a36de 100644 (file)
@@ -1,8 +1,14 @@
+/*
+ * 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.binding.util;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
-
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap.Builder;
@@ -41,8 +47,8 @@ public class DataObjectReadingUtil {
      *            Path, which is nested to parent, and should be readed.
      * @return Value of object.
      */
-    public static final <T extends DataObject, P extends DataObject> Map<InstanceIdentifier<T>, T> readData(P parent,
-            InstanceIdentifier<P> parentPath, InstanceIdentifier<T> childPath) {
+    public static final <T extends DataObject, P extends DataObject> Map<InstanceIdentifier<T>, T> readData(final P parent,
+            final InstanceIdentifier<P> parentPath, final InstanceIdentifier<T> childPath) {
         checkArgument(parent != null, "Parent must not be null.");
         checkArgument(parentPath != null, "Parent path must not be null");
         checkArgument(childPath != null, "Child path must not be null");
@@ -70,12 +76,12 @@ public class DataObjectReadingUtil {
     }
 
     @SuppressWarnings("rawtypes")
-    private static Map<InstanceIdentifier, DataContainer> readData(Entry<InstanceIdentifier, DataContainer> entry,
-            PathArgument pathArgument) {
+    private static Map<InstanceIdentifier, DataContainer> readData(final Entry<InstanceIdentifier, DataContainer> entry,
+            final PathArgument pathArgument) {
         return readData(entry.getValue(), entry.getKey(), pathArgument);
     }
 
-    public static final <T extends DataObject> Optional<T> readData(DataObject source, Class<T> child) {
+    public static final <T extends DataObject> Optional<T> readData(final DataObject source, final Class<T> child) {
         checkArgument(source != null, "Object should not be null.");
         checkArgument(child != null, "Child type should not be null");
         Class<? extends DataContainer> parentClass = source.getImplementedInterface();
@@ -86,24 +92,24 @@ public class DataObjectReadingUtil {
     }
 
     @SuppressWarnings("rawtypes")
-    private static final Map<InstanceIdentifier, DataContainer> readData(DataContainer parent,
-            InstanceIdentifier parentPath, PathArgument child) {
+    private static final Map<InstanceIdentifier, DataContainer> readData(final DataContainer parent,
+            final InstanceIdentifier parentPath, final PathArgument child) {
         checkArgument(parent != null, "Object should not be null.");
         checkArgument(child != null, "Child argument should not be null");
         Class<? extends DataContainer> parentClass = parent.getImplementedInterface();
         return resolveReadStrategy(parentClass, child.getType()).readUsingPathArgument(parent, child, parentPath);
     }
 
-    private static DataObjectReadingStrategy resolveReadStrategy(Class<? extends DataContainer> parentClass,
-            Class<? extends DataContainer> type) {
+    private static DataObjectReadingStrategy resolveReadStrategy(final Class<? extends DataContainer> parentClass,
+            final Class<? extends DataContainer> type) {
 
         DataObjectReadingStrategy strategy = createReadStrategy(parentClass, type);
         // FIXME: Add caching of strategies
         return strategy;
     }
 
-    private static DataObjectReadingStrategy createReadStrategy(Class<? extends DataContainer> parent,
-            Class<? extends DataContainer> child) {
+    private static DataObjectReadingStrategy createReadStrategy(final Class<? extends DataContainer> parent,
+            final Class<? extends DataContainer> child) {
 
         if (Augmentable.class.isAssignableFrom(parent) && Augmentation.class.isAssignableFrom(child)) {
             return REAUSABLE_AUGMENTATION_READING_STRATEGY;
@@ -122,7 +128,7 @@ public class DataObjectReadingUtil {
         return new ContainerReadingStrategy(parent, child);
     }
 
-    private static Method resolveGetterMethod(Class<? extends DataContainer> parent, Class<?> child) {
+    private static Method resolveGetterMethod(final Class<? extends DataContainer> parent, final Class<?> child) {
         String methodName = "get" + child.getSimpleName();
         try {
             return parent.getMethod(methodName);
@@ -141,7 +147,7 @@ public class DataObjectReadingUtil {
         private final Method getterMethod;
 
         @SuppressWarnings("unchecked")
-        public DataObjectReadingStrategy(Class parentType, Class childType) {
+        public DataObjectReadingStrategy(final Class parentType, final Class childType) {
             super();
             checkArgument(DataContainer.class.isAssignableFrom(parentType));
             checkArgument(DataContainer.class.isAssignableFrom(childType));
@@ -151,7 +157,7 @@ public class DataObjectReadingUtil {
         }
 
         @SuppressWarnings("unchecked")
-        public DataObjectReadingStrategy(Class parentType, Class childType, Method getter) {
+        public DataObjectReadingStrategy(final Class parentType, final Class childType, final Method getter) {
             this.parentType = parentType;
             this.childType = childType;
             this.getterMethod = getter;
@@ -180,14 +186,14 @@ public class DataObjectReadingUtil {
     @SuppressWarnings("rawtypes")
     private static class ContainerReadingStrategy extends DataObjectReadingStrategy {
 
-        public ContainerReadingStrategy(Class<? extends DataContainer> parent, Class<? extends DataContainer> child) {
+        public ContainerReadingStrategy(final Class<? extends DataContainer> parent, final Class<? extends DataContainer> child) {
             super(parent, child);
             checkArgument(child.isAssignableFrom(getGetterMethod().getReturnType()));
         }
 
         @Override
-        public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(DataContainer parent,
-                PathArgument childArgument, InstanceIdentifier parentPath) {
+        public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(final DataContainer parent,
+                final PathArgument childArgument, final InstanceIdentifier parentPath) {
             final DataContainer result = read(parent, childArgument.getType());
             if (result != null) {
                 @SuppressWarnings("unchecked")
@@ -198,7 +204,7 @@ public class DataObjectReadingUtil {
         }
 
         @Override
-        public DataContainer read(DataContainer parent, Class<?> childType) {
+        public DataContainer read(final DataContainer parent, final Class<?> childType) {
             try {
                 Object potentialData = getGetterMethod().invoke(parent);
                 checkState(potentialData instanceof DataContainer);
@@ -213,21 +219,21 @@ public class DataObjectReadingUtil {
     @SuppressWarnings("rawtypes")
     private static class ListItemReadingStrategy extends DataObjectReadingStrategy {
 
-        public ListItemReadingStrategy(Class<? extends DataContainer> parent, Class child) {
+        public ListItemReadingStrategy(final Class<? extends DataContainer> parent, final Class child) {
             super(parent, child);
             checkArgument(Iterable.class.isAssignableFrom(getGetterMethod().getReturnType()));
         }
 
         @Override
-        public DataContainer read(DataContainer parent, Class<?> childType) {
+        public DataContainer read(final DataContainer parent, final Class<?> childType) {
             // This will always fail since we do not have key.
             return null;
         }
 
         @SuppressWarnings("unchecked")
         @Override
-        public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(DataContainer parent,
-                PathArgument childArgument, InstanceIdentifier builder) {
+        public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(final DataContainer parent,
+                final PathArgument childArgument, final InstanceIdentifier builder) {
             try {
                 Object potentialList = getGetterMethod().invoke(parent);
                 if (potentialList instanceof Iterable) {
@@ -249,8 +255,8 @@ public class DataObjectReadingUtil {
             return Collections.emptyMap();
         }
 
-        private Map<InstanceIdentifier, DataContainer> readAll(Iterable<Identifiable> dataList,
-                InstanceIdentifier parentPath) {
+        private Map<InstanceIdentifier, DataContainer> readAll(final Iterable<Identifiable> dataList,
+                final InstanceIdentifier parentPath) {
             Builder<InstanceIdentifier, DataContainer> result = ImmutableMap
                     .<InstanceIdentifier, DataContainer> builder();
             for (Identifiable item : dataList) {
@@ -262,8 +268,8 @@ public class DataObjectReadingUtil {
         }
 
         @SuppressWarnings("unchecked")
-        private Map<InstanceIdentifier, DataContainer> readUsingIdentifiableItem(Iterable<Identifiable> dataList,
-                IdentifiableItem childArgument, InstanceIdentifier parentPath) {
+        private Map<InstanceIdentifier, DataContainer> readUsingIdentifiableItem(final Iterable<Identifiable> dataList,
+                final IdentifiableItem childArgument, final InstanceIdentifier parentPath) {
             final Identifier<?> key = childArgument.getKey();
             for (Identifiable item : dataList) {
                 if (key.equals(item.getKey()) && item instanceof DataContainer) {
@@ -289,8 +295,8 @@ public class DataObjectReadingUtil {
 
         @SuppressWarnings("rawtypes")
         @Override
-        public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(DataContainer parent,
-                PathArgument childArgument, InstanceIdentifier builder) {
+        public Map<InstanceIdentifier, DataContainer> readUsingPathArgument(final DataContainer parent,
+                final PathArgument childArgument, final InstanceIdentifier builder) {
             checkArgument(childArgument instanceof Item<?>, "Path Argument must be Item without keys");
             DataContainer aug = read(parent, childArgument.getType());
             if (aug != null) {
@@ -303,7 +309,7 @@ public class DataObjectReadingUtil {
         }
 
         @Override
-        public DataContainer read(DataContainer parent, Class<?> childType) {
+        public DataContainer read(final DataContainer parent, final Class<?> childType) {
             checkArgument(Augmentation.class.isAssignableFrom(childType), "Parent must be Augmentable.");
             checkArgument(parent instanceof Augmentable<?>, "Parent must be Augmentable.");
 
@@ -324,7 +330,7 @@ public class DataObjectReadingUtil {
      * @throws IllegalArgumentException
      *             if parent argument is bigger than child
      */
-    private static <P, C> List<C> subList(Iterable<P> parent, Iterable<C> child) {
+    private static <P, C> List<C> subList(final Iterable<P> parent, final Iterable<C> child) {
         Iterator<P> iParent = parent.iterator();
         List<C> result = new ArrayList<>();
         for (C arg : child) {
index ca37fc167d9bc921a66323dbf7c4a5b937260844..dce403e1d08e86f3badbce5de32017301ece2fe1 100644 (file)
@@ -42,7 +42,7 @@ public final class NotificationListenerInvoker {
             .build(new CacheLoader<Class<? extends NotificationListener>, NotificationListenerInvoker>() {
 
                 @Override
-                public NotificationListenerInvoker load(Class<? extends NotificationListener> key) throws Exception {
+                public NotificationListenerInvoker load(final Class<? extends NotificationListener> key) throws Exception {
                     return createInvoker(key);
                 }
 
@@ -50,7 +50,7 @@ public final class NotificationListenerInvoker {
 
     private final Map<QName, MethodHandle> methodInvokers;
 
-    public NotificationListenerInvoker(Map<QName, MethodHandle> map) {
+    public NotificationListenerInvoker(final Map<QName, MethodHandle> map) {
         this.methodInvokers = map;
     }
 
@@ -64,7 +64,7 @@ public final class NotificationListenerInvoker {
      *         supplied RPC type.
      *
      */
-    public static NotificationListenerInvoker from(Class<? extends NotificationListener> type) {
+    public static NotificationListenerInvoker from(final Class<? extends NotificationListener> type) {
         Preconditions.checkArgument(type.isInterface());
         Preconditions.checkArgument(BindingReflections.isBindingClass(type));
         return INVOKERS.getUnchecked(type);
@@ -82,8 +82,8 @@ public final class NotificationListenerInvoker {
      *            Input data for RPC.
      *
      */
-    public void invokeNotification(@Nonnull NotificationListener impl, @Nonnull QName rpcName,
-            @Nullable DataContainer input) {
+    public void invokeNotification(@Nonnull final NotificationListener impl, @Nonnull final QName rpcName,
+            @Nullable final DataContainer input) {
         Preconditions.checkNotNull(impl, "implemetation must be supplied");
         MethodHandle invoker = methodInvokers.get(rpcName);
         Preconditions.checkArgument(invoker != null, "Supplied notification is not valid for implementation %s", impl);
@@ -94,12 +94,12 @@ public final class NotificationListenerInvoker {
         }
     }
 
-    private static NotificationListenerInvoker createInvoker(Class<? extends NotificationListener> key) {
+    private static NotificationListenerInvoker createInvoker(final Class<? extends NotificationListener> key) {
         return new NotificationListenerInvoker(createInvokerMap(key));
     }
 
-    private static Map<QName, MethodHandle> createInvokerMap(Class<? extends NotificationListener> key) {
-        Builder<QName, MethodHandle> ret = ImmutableMap.<QName, MethodHandle> builder();
+    private static Map<QName, MethodHandle> createInvokerMap(final Class<? extends NotificationListener> key) {
+        Builder<QName, MethodHandle> ret = ImmutableMap.<QName, MethodHandle>builder();
         for (Method method : key.getMethods()) {
             if (BindingReflections.isNotificationCallback(method)) {
 
index b1ea0e437bbdc4b8cbaa445591d6994ed1810fa0..55974a3f87dda49ced9014273e1d763a79125390 100644 (file)
@@ -49,10 +49,9 @@ public class OperationFailedException extends Exception {
                                     final RpcError... errors) {
         super(Preconditions.checkNotNull(message), cause);
 
-        if( errors != null && errors.length > 0 ) {
+        if (errors != null && errors.length > 0) {
             errorList = ImmutableList.<RpcError>copyOf( Arrays.asList( errors ) );
-        }
-        else {
+        } else {
             // Add a default RpcError.
             errorList = ImmutableList.of(RpcResultBuilder.newError(ErrorType.APPLICATION, null,
                     getMessage(), null, null, getCause()));
index c063366a476945a068e3795718712085d8c0aa04..690e29517dde914ae3c3dac9add327431d474f40 100644 (file)
@@ -11,11 +11,9 @@ package org.opendaylight.yangtools.yang.common;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.Collections;
-
 import org.opendaylight.yangtools.concepts.Builder;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
@@ -59,7 +57,7 @@ public final class RpcResultBuilder<T> implements Builder<RpcResult<T>> {
         }
 
         @Override
-        public String toString(){
+        public String toString() {
             return "RpcResult [successful=" + successful + ", result="
                     + result + ", errors=" + errors + "]";
         }
@@ -109,7 +107,7 @@ public final class RpcResultBuilder<T> implements Builder<RpcResult<T>> {
         }
 
         @Override
-        public String getMessage(){
+        public String getMessage() {
             return message;
         }
 
@@ -124,7 +122,7 @@ public final class RpcResultBuilder<T> implements Builder<RpcResult<T>> {
         }
 
         @Override
-        public String toString(){
+        public String toString() {
             return "RpcError [message=" + message + ", severity="
                     + severity + ", errorType=" + errorType + ", tag=" + tag
                     + ", applicationTag=" + applicationTag + ", info=" + info
@@ -154,7 +152,7 @@ public final class RpcResultBuilder<T> implements Builder<RpcResult<T>> {
      * @param result the result value
      */
     public static <T> RpcResultBuilder<T> success( final T result ) {
-         return new RpcResultBuilder<T>( true, result );
+        return new RpcResultBuilder<T>( true, result );
     }
 
     /**
@@ -291,7 +289,7 @@ public final class RpcResultBuilder<T> implements Builder<RpcResult<T>> {
 
     private void addError( final RpcError error ) {
 
-        if( errors == null ) {
+        if (errors == null) {
             errors = new ImmutableList.Builder<RpcError>();
         }
 
@@ -400,8 +398,8 @@ public final class RpcResultBuilder<T> implements Builder<RpcResult<T>> {
      * @param errors the list of RpcErrors
      */
     public RpcResultBuilder<T> withRpcErrors( final Collection<RpcError> errors ) {
-        if( errors != null ) {
-            for( RpcError error: errors ) {
+        if (errors != null) {
+            for (RpcError error : errors) {
                 addError( error );
             }
         }
index 66b36fc71f988e8b6bb379881b4a2b2cb7b1aeda..9c62fbb1d0bc212b27e82a7f1c718cad5c74e85f 100644 (file)
@@ -13,7 +13,6 @@ import java.io.IOException;
 import java.io.StringWriter;
 import java.util.Map;
 import javax.xml.XMLConstants;
-import java.io.StringWriter;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
@@ -55,7 +54,7 @@ public final class XMLStreamNormalizedNodeStreamWriter implements NormalizedNode
     private final XMLStreamWriter writer;
     private final SchemaTracker tracker;
     private final XmlStreamUtils streamUtils;
-    private RandomPrefix randomPrefix;
+    private final RandomPrefix randomPrefix;
 
     private XMLStreamNormalizedNodeStreamWriter(final XMLStreamWriter writer, final SchemaContext context, final SchemaPath path) {
         this.writer = Preconditions.checkNotNull(writer);
@@ -87,7 +86,7 @@ public final class XMLStreamNormalizedNodeStreamWriter implements NormalizedNode
         return new XMLStreamNormalizedNodeStreamWriter(writer, context, path);
     }
 
-    private void writeStartElement( QName qname) throws XMLStreamException {
+    private void writeStartElement(final QName qname) throws XMLStreamException {
         String ns = qname.getNamespace().toString();
         writer.writeStartElement(XMLConstants.DEFAULT_NS_PREFIX, qname.getLocalName(), ns);
         if(writer.getNamespaceContext() != null) {
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataNodeContainerModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataNodeContainerModificationStrategy.java
new file mode 100644 (file)
index 0000000..af3a904
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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.schema.tree;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import java.util.concurrent.ExecutionException;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
+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.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Base strategy for applying changes to a ContainerNode, irrespective of its
+ * actual type.
+ *
+ * @param <T> Type of the container node
+ */
+abstract class AbstractDataNodeContainerModificationStrategy<T extends DataNodeContainer> extends AbstractNodeContainerModificationStrategy {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractDataNodeContainerModificationStrategy.class);
+    private final LoadingCache<PathArgument, ModificationApplyOperation> childCache = CacheBuilder.newBuilder()
+            .build(new CacheLoader<PathArgument, ModificationApplyOperation>() {
+                @Override
+                public ModificationApplyOperation load(final PathArgument key) throws Exception {
+                    if (key instanceof AugmentationIdentifier && schema instanceof AugmentationTarget) {
+                        return SchemaAwareApplyOperation.from(schema, (AugmentationTarget) schema, (AugmentationIdentifier) key);
+                    }
+
+                    final DataSchemaNode child = schema.getDataChildByName(key.getNodeType());
+                    return child == null ? null : SchemaAwareApplyOperation.from(child);
+                }
+            });
+    private final T schema;
+
+    protected AbstractDataNodeContainerModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
+        super(nodeClass);
+        this.schema = Preconditions.checkNotNull(schema);
+    }
+
+    protected final T getSchema() {
+        return schema;
+    }
+
+    @Override
+    public final Optional<ModificationApplyOperation> getChild(final PathArgument identifier) {
+        try {
+            return Optional.<ModificationApplyOperation> fromNullable(childCache.get(identifier));
+        } catch (ExecutionException e) {
+            LOG.trace("Child {} not present in container schema {}", identifier, this);
+            return Optional.absent();
+        }
+    }
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    protected abstract DataContainerNodeBuilder createBuilder(NormalizedNode<?, ?> original);
+
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + " [" + schema + "]";
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractNodeContainerModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractNodeContainerModificationStrategy.java
new file mode 100644 (file)
index 0000000..c0ddf6c
--- /dev/null
@@ -0,0 +1,202 @@
+/*
+ * 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.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import java.util.Collection;
+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.NormalizedNodeContainer;
+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.api.schema.tree.ModifiedNodeDoesNotExistException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.MutableTreeNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+
+abstract class AbstractNodeContainerModificationStrategy extends SchemaAwareApplyOperation {
+
+    private final Class<? extends NormalizedNode<?, ?>> nodeClass;
+
+    protected AbstractNodeContainerModificationStrategy(final Class<? extends NormalizedNode<?, ?>> nodeClass) {
+        this.nodeClass = Preconditions.checkNotNull(nodeClass);
+    }
+
+    @Override
+    void verifyStructure(final ModifiedNode modification) throws IllegalArgumentException {
+        for (ModifiedNode childModification : modification.getChildren()) {
+            resolveChildOperation(childModification.getIdentifier()).verifyStructure(childModification);
+        }
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
+        checkArgument(nodeClass.isInstance(writtenValue), "Node %s is not of type %s", writtenValue, nodeClass);
+        checkArgument(writtenValue instanceof NormalizedNodeContainer);
+
+        NormalizedNodeContainer container = (NormalizedNodeContainer) writtenValue;
+        for (Object child : container.getValue()) {
+            checkArgument(child instanceof NormalizedNode);
+
+            /*
+             * FIXME: fail-fast semantics:
+             *
+             * We can validate the data structure here, aborting the commit
+             * before it ever progresses to being committed.
+             */
+        }
+    }
+
+    @Override
+    protected TreeNode applyWrite(final ModifiedNode modification,
+            final Optional<TreeNode> currentMeta, final Version version) {
+        final NormalizedNode<?, ?> newValue = modification.getWrittenValue();
+        final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, version);
+
+        if (modification.getChildren().isEmpty()) {
+            return newValueMeta;
+        }
+
+        /*
+         * This is where things get interesting. The user has performed a write and
+         * then she applied some more modifications to it. So we need to make sense
+         * of that an apply the operations on top of the written value. We could have
+         * done it during the write, but this operation is potentially expensive, so
+         * we have left it out of the fast path.
+         *
+         * As it turns out, once we materialize the written data, we can share the
+         * code path with the subtree change. So let's create an unsealed TreeNode
+         * and run the common parts on it -- which end with the node being sealed.
+         *
+         * FIXME: this code needs to be moved out from the prepare() path and into
+         *        the read() and seal() paths. Merging of writes needs to be charged
+         *        to the code which originated this, not to the code which is
+         *        attempting to make it visible.
+         */
+        final MutableTreeNode mutable = newValueMeta.mutable();
+        mutable.setSubtreeVersion(version);
+
+        @SuppressWarnings("rawtypes")
+        final NormalizedNodeContainerBuilder dataBuilder = createBuilder(newValue);
+
+        return mutateChildren(mutable, dataBuilder, version, modification.getChildren());
+    }
+
+    /**
+     * Applies write/remove diff operation for each modification child in modification subtree.
+     * Operation also sets the Data tree references for each Tree Node (Index Node) in meta (MutableTreeNode) structure.
+     *
+     * @param meta MutableTreeNode (IndexTreeNode)
+     * @param data DataBuilder
+     * @param nodeVersion Version of TreeNode
+     * @param modifications modification operations to apply
+     * @return Sealed immutable copy of TreeNode structure with all Data Node references set.
+     */
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    private TreeNode mutateChildren(final MutableTreeNode meta, final NormalizedNodeContainerBuilder data,
+            final Version nodeVersion, final Iterable<ModifiedNode> modifications) {
+
+        for (ModifiedNode mod : modifications) {
+            final YangInstanceIdentifier.PathArgument id = mod.getIdentifier();
+            final Optional<TreeNode> cm = meta.getChild(id);
+
+            Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
+            if (result.isPresent()) {
+                final TreeNode tn = result.get();
+                meta.addChild(tn);
+                data.addChild(tn.getData());
+            } else {
+                meta.removeChild(id);
+                data.removeChild(id);
+            }
+        }
+
+        meta.setData(data.build());
+        return meta.seal();
+    }
+
+    @Override
+    protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
+            final Version version) {
+        // For Node Containers - merge is same as subtree change - we only replace children.
+        return applyTouch(modification, currentMeta, version);
+    }
+
+    @Override
+    public TreeNode applyTouch(final ModifiedNode modification,
+            final TreeNode currentMeta, final Version version) {
+        final MutableTreeNode newMeta = currentMeta.mutable();
+        newMeta.setSubtreeVersion(version);
+
+        /*
+         * The user has issued an empty merge operation. In this case we do not perform
+         * a data tree mutation, do not pass GO, and do not collect useless garbage.
+         */
+        final Collection<ModifiedNode> children = modification.getChildren();
+        if (children.isEmpty()) {
+            modification.resolveModificationType(ModificationType.UNMODIFIED);
+            newMeta.setData(currentMeta.getData());
+            return newMeta.seal();
+        }
+
+        @SuppressWarnings("rawtypes")
+        NormalizedNodeContainerBuilder dataBuilder = createBuilder(currentMeta.getData());
+
+        /*
+         * TODO: this is not entirely accurate. If there is only an empty merge operation
+         *       among the children, its effect is ModificationType.UNMODIFIED. That would
+         *       mean this operation can be turned into UNMODIFIED, cascading that further
+         *       up the root -- potentially turning the entire transaction into a no-op
+         *       from the perspective of physical replication.
+         *
+         *       In order to do that, though, we either have to walk the children ourselves
+         *       (looking for a non-UNMODIFIED child), or have mutateChildren() pass that
+         *       information back to us.
+         */
+        modification.resolveModificationType(ModificationType.SUBTREE_MODIFIED);
+        return mutateChildren(newMeta, dataBuilder, version, children);
+    }
+
+    @Override
+    protected void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+            final Optional<TreeNode> current) throws DataValidationFailedException {
+        if (!modification.getOriginal().isPresent() && !current.isPresent()) {
+            throw new ModifiedNodeDoesNotExistException(path, String.format("Node %s does not exist. Cannot apply modification to its children.", path));
+        }
+
+        SchemaAwareApplyOperation.checkConflicting(path, current.isPresent(), "Node was deleted by other transaction.");
+        checkChildPreconditions(path, modification, current);
+    }
+
+    private void checkChildPreconditions(final YangInstanceIdentifier path, final NodeModification modification, final Optional<TreeNode> current) throws DataValidationFailedException {
+        final TreeNode currentMeta = current.get();
+        for (NodeModification childMod : modification.getChildren()) {
+            final YangInstanceIdentifier.PathArgument childId = childMod.getIdentifier();
+            final Optional<TreeNode> childMeta = currentMeta.getChild(childId);
+
+            YangInstanceIdentifier childPath = path.node(childId);
+            resolveChildOperation(childId).checkApplicable(childPath, childMod, childMeta);
+        }
+    }
+
+    @Override
+    protected void checkMergeApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+            final Optional<TreeNode> current) throws DataValidationFailedException {
+        if(current.isPresent()) {
+            checkChildPreconditions(path, modification,current);
+        }
+    }
+
+    @SuppressWarnings("rawtypes")
+    protected abstract NormalizedNodeContainerBuilder createBuilder(NormalizedNode<?, ?> original);
+}
@@ -7,81 +7,68 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 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.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.IncorrectDataStructureException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
 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 static com.google.common.base.Preconditions.checkArgument;
-
-abstract class ValueNodeModificationStrategy<T extends DataSchemaNode> extends SchemaAwareApplyOperation {
 
-    private final T schema;
+abstract class AbstractValueNodeModificationStrategy<T extends DataSchemaNode> extends SchemaAwareApplyOperation {
     private final Class<? extends NormalizedNode<?, ?>> nodeClass;
+    private final T schema;
 
-    protected ValueNodeModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
-        super();
+    protected AbstractValueNodeModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
+        this.nodeClass = Preconditions.checkNotNull(nodeClass);
         this.schema = schema;
-        this.nodeClass = nodeClass;
     }
 
     @Override
-    protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
+    protected final void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
         checkArgument(nodeClass.isInstance(writtenValue), "Node should must be of type %s", nodeClass);
     }
 
     @Override
-    public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
+    public final Optional<ModificationApplyOperation> getChild(final PathArgument child) {
         throw new UnsupportedOperationException("Node " + schema.getPath()
                 + "is leaf type node. Child nodes not allowed");
     }
 
     @Override
-    protected TreeNode applySubtreeChange(final ModifiedNode modification,
+    protected final ChildTrackingPolicy getChildPolicy() {
+        return ChildTrackingPolicy.NONE;
+    }
+
+    @Override
+    protected final TreeNode applyTouch(final ModifiedNode modification,
             final TreeNode currentMeta, final Version version) {
         throw new UnsupportedOperationException("Node " + schema.getPath()
                 + "is leaf type node. Subtree change is not allowed.");
     }
 
     @Override
-    protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
+    protected final TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
             final Version version) {
         // Just overwrite whatever was there
+        modification.resolveModificationType(ModificationType.WRITE);
         return applyWrite(modification, null, version);
     }
 
     @Override
-    protected TreeNode applyWrite(final ModifiedNode modification,
+    protected final TreeNode applyWrite(final ModifiedNode modification,
             final Optional<TreeNode> currentMeta, final Version version) {
-        return TreeNodeFactory.createTreeNodeRecursively(modification.getWrittenValue(), version);
+        return TreeNodeFactory.createTreeNode(modification.getWrittenValue(), version);
     }
 
     @Override
-    protected void checkSubtreeModificationApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+    protected final void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
             final Optional<TreeNode> current) throws IncorrectDataStructureException {
         throw new IncorrectDataStructureException(path, "Subtree modification is not allowed.");
     }
-
-    public static class LeafSetEntryModificationStrategy extends ValueNodeModificationStrategy<LeafListSchemaNode> {
-        @SuppressWarnings({ "unchecked", "rawtypes" })
-        protected LeafSetEntryModificationStrategy(final LeafListSchemaNode schema) {
-            super(schema, (Class) LeafSetEntryNode.class);
-        }
-    }
-
-    public static class LeafModificationStrategy extends ValueNodeModificationStrategy<LeafSchemaNode> {
-        @SuppressWarnings({ "unchecked", "rawtypes" })
-        protected LeafModificationStrategy(final LeafSchemaNode schema) {
-            super(schema, (Class) LeafNode.class);
-        }
-    }
 }
\ No newline at end of file
index bbbd2f12427befe7c70758923a6a4060bc49b812..8ff141f16727a87d7a3974befac89d121aa99a18 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-
 import com.google.common.base.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -20,21 +19,21 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
  * if it does not have a SchemaContext attached and hence cannot
  * perform anything meaningful.
  */
-final class AlwaysFailOperation implements ModificationApplyOperation {
-    public static final ModificationApplyOperation INSTANCE = new AlwaysFailOperation();
+final class AlwaysFailOperation extends ModificationApplyOperation {
+    static final ModificationApplyOperation INSTANCE = new AlwaysFailOperation();
 
     private AlwaysFailOperation() {
 
     }
 
     @Override
-    public Optional<TreeNode> apply(final ModifiedNode modification,
+    Optional<TreeNode> apply(final ModifiedNode modification,
             final Optional<TreeNode> storeMeta, final Version version) {
         throw new IllegalStateException("Schema Context is not available.");
     }
 
     @Override
-    public void checkApplicable(final YangInstanceIdentifier path,final NodeModification modification, final Optional<TreeNode> storeMetadata) {
+    void checkApplicable(final YangInstanceIdentifier path,final NodeModification modification, final Optional<TreeNode> storeMetadata) {
         throw new IllegalStateException("Schema Context is not available.");
     }
 
@@ -44,7 +43,12 @@ final class AlwaysFailOperation implements ModificationApplyOperation {
     }
 
     @Override
-    public void verifyStructure(final ModifiedNode modification) {
+    void verifyStructure(final ModifiedNode modification) {
+        throw new IllegalStateException("Schema Context is not available.");
+    }
+
+    @Override
+    ChildTrackingPolicy getChildPolicy() {
         throw new IllegalStateException("Schema Context is not available.");
     }
 }
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AugmentationModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AugmentationModificationStrategy.java
new file mode 100644 (file)
index 0000000..454254e
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import java.util.HashSet;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
+
+final class AugmentationModificationStrategy extends AbstractDataNodeContainerModificationStrategy<AugmentationSchema> {
+    AugmentationModificationStrategy(final AugmentationSchema schema, final DataNodeContainer resolved) {
+        super(createAugmentProxy(schema,resolved), AugmentationNode.class);
+    }
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+        checkArgument(original instanceof AugmentationNode);
+        return ImmutableAugmentationNodeBuilder.create((AugmentationNode) original);
+    }
+
+    private static AugmentationSchema createAugmentProxy(final AugmentationSchema schema, final DataNodeContainer resolved) {
+        Set<DataSchemaNode> realChildSchemas = new HashSet<>();
+        for(DataSchemaNode augChild : schema.getChildNodes()) {
+            realChildSchemas.add(resolved.getDataChildByName(augChild.getQName()));
+        }
+        return new EffectiveAugmentationSchema(schema, realChildSchemas);
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChildTrackingPolicy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChildTrackingPolicy.java
new file mode 100644 (file)
index 0000000..52bffc7
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+
+/**
+ * Child ordering policy. It defines how a {@link ModifiedNode} tracks its children.
+ */
+enum ChildTrackingPolicy {
+    /**
+     * No child nodes are possible, ever.
+     */
+    NONE,
+    /**
+     * Child nodes are possible and we need to make sure that their iteration order
+     * matches the order in which they are introduced.
+     */
+    ORDERED,
+    /**
+     * Child nodes are possible, but their iteration order can be undefined.
+     */
+    UNORDERED,
+}
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChoiceModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ChoiceModificationStrategy.java
new file mode 100644 (file)
index 0000000..dbc1fe3
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+
+final class ChoiceModificationStrategy extends AbstractNodeContainerModificationStrategy {
+    private final Map<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> childNodes;
+
+    ChoiceModificationStrategy(final ChoiceSchemaNode schemaNode) {
+        super(ChoiceNode.class);
+        ImmutableMap.Builder<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> child = ImmutableMap.builder();
+
+        for (ChoiceCaseNode caze : schemaNode.getCases()) {
+            for (DataSchemaNode cazeChild : caze.getChildNodes()) {
+                SchemaAwareApplyOperation childNode = SchemaAwareApplyOperation.from(cazeChild);
+                child.put(new YangInstanceIdentifier.NodeIdentifier(cazeChild.getQName()), childNode);
+            }
+        }
+        childNodes = child.build();
+    }
+
+    @Override
+    public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument child) {
+        return Optional.fromNullable(childNodes.get(child));
+    }
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+        checkArgument(original instanceof ChoiceNode);
+        return ImmutableChoiceNodeBuilder.create((ChoiceNode) original);
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ContainerModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ContainerModificationStrategy.java
new file mode 100644 (file)
index 0000000..4c81568
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+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.model.api.ContainerSchemaNode;
+
+final class ContainerModificationStrategy extends AbstractDataNodeContainerModificationStrategy<ContainerSchemaNode> {
+    ContainerModificationStrategy(final ContainerSchemaNode schemaNode) {
+        super(schemaNode, ContainerNode.class);
+    }
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+        checkArgument(original instanceof ContainerNode);
+        return ImmutableContainerNodeBuilder.create((ContainerNode) original);
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataNodeContainerModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataNodeContainerModificationStrategy.java
deleted file mode 100644 (file)
index e239c38..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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.schema.tree;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
-import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
-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.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
-
-/**
- * Base strategy for applying changes to a ContainerNode, irrespective of its
- * actual type.
- *
- * @param <T> Type of the container node
- */
-abstract class DataNodeContainerModificationStrategy<T extends DataNodeContainer> extends NormalizedNodeContainerModificationStrategy {
-
-    private final T schema;
-    private final LoadingCache<PathArgument, ModificationApplyOperation> childCache = CacheBuilder.newBuilder()
-            .build(CacheLoader.from(new Function<PathArgument, ModificationApplyOperation>() {
-
-                @Override
-                public ModificationApplyOperation apply(final PathArgument identifier) {
-                    if (identifier instanceof AugmentationIdentifier && schema instanceof AugmentationTarget) {
-                        return SchemaAwareApplyOperation.from(schema, (AugmentationTarget) schema, (AugmentationIdentifier) identifier);
-                    }
-
-                    DataSchemaNode child = schema.getDataChildByName(identifier.getNodeType());
-                    if (child == null) {
-                        return null;
-                    }
-                    return SchemaAwareApplyOperation.from(child);
-                }
-            }));
-
-    protected DataNodeContainerModificationStrategy(final T schema,
-            final Class<? extends NormalizedNode<?, ?>> nodeClass) {
-        super(nodeClass);
-        this.schema = schema;
-    }
-
-    protected T getSchema() {
-        return schema;
-    }
-
-    @Override
-    public Optional<ModificationApplyOperation> getChild(final PathArgument identifier) {
-        try {
-            return Optional.<ModificationApplyOperation> fromNullable(childCache.get(identifier));
-        } catch (ExecutionException e) {
-            return Optional.absent();
-        }
-    }
-
-    @Override
-    @SuppressWarnings("rawtypes")
-    protected abstract DataContainerNodeBuilder createBuilder(NormalizedNode<?, ?> original);
-
-    @Override
-    public String toString() {
-        return getClass().getSimpleName() + " [" + schema + "]";
-    }
-
-    public static class AugmentationModificationStrategy extends DataNodeContainerModificationStrategy<AugmentationSchema> {
-
-        protected AugmentationModificationStrategy(final AugmentationSchema schema, final DataNodeContainer resolved) {
-            super(createAugmentProxy(schema,resolved), AugmentationNode.class);
-        }
-
-        @Override
-        @SuppressWarnings("rawtypes")
-        protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
-            checkArgument(original instanceof AugmentationNode);
-            return ImmutableAugmentationNodeBuilder.create((AugmentationNode) original);
-        }
-
-        private static AugmentationSchema createAugmentProxy(final AugmentationSchema schema, final DataNodeContainer resolved) {
-            Set<DataSchemaNode> realChildSchemas = new HashSet<>();
-            for(DataSchemaNode augChild : schema.getChildNodes()) {
-                realChildSchemas.add(resolved.getDataChildByName(augChild.getQName()));
-            }
-            return new EffectiveAugmentationSchema(schema, realChildSchemas);
-        }
-    }
-
-    public static class ContainerModificationStrategy extends DataNodeContainerModificationStrategy<ContainerSchemaNode> {
-
-        public ContainerModificationStrategy(final ContainerSchemaNode schemaNode) {
-            super(schemaNode, ContainerNode.class);
-        }
-
-        @Override
-        @SuppressWarnings("rawtypes")
-        protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
-            checkArgument(original instanceof ContainerNode);
-            return ImmutableContainerNodeBuilder.create((ContainerNode) original);
-        }
-    }
-
-    public static class ListEntryModificationStrategy extends DataNodeContainerModificationStrategy<ListSchemaNode> {
-
-        protected ListEntryModificationStrategy(final ListSchemaNode schema) {
-            super(schema, MapEntryNode.class);
-        }
-
-        @Override
-        @SuppressWarnings("rawtypes")
-        protected final DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
-            checkArgument(original instanceof MapEntryNode);
-            return ImmutableMapEntryNodeBuilder.create((MapEntryNode) original);
-        }
-    }
-
-    public static class UnkeyedListItemModificationStrategy extends DataNodeContainerModificationStrategy<ListSchemaNode> {
-
-        public UnkeyedListItemModificationStrategy(final ListSchemaNode schemaNode) {
-            super(schemaNode, UnkeyedListEntryNode.class);
-        }
-
-        @Override
-        @SuppressWarnings("rawtypes")
-        protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
-            checkArgument(original instanceof UnkeyedListEntryNode);
-            return ImmutableUnkeyedListEntryNodeBuilder.create((UnkeyedListEntryNode) original);
-        }
-    }
-}
\ No newline at end of file
index f6bb6ba2aac4e8da8c0ba922bd09d0f5621b43cb..1ce5e8b4831044ac27ad80746ba3182ddec35612 100644 (file)
@@ -15,10 +15,6 @@ import java.util.Collection;
 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.NormalizedNodeContainer;
-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.UnkeyedListNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
@@ -73,39 +69,7 @@ final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
 
         @Override
         public ModificationType getModificationType() {
-            switch (mod.getOperation()) {
-            case DELETE:
-                return ModificationType.DELETE;
-            case MERGE:
-                // Merge into non-existing data is a write
-                if (oldMeta == null) {
-                    return ModificationType.WRITE;
-                }
-
-                // Data-based checks to narrow down types
-                final NormalizedNode<?, ?> data = newMeta.getData();
-
-                // leaf or anyxml are always written
-                if (!(data instanceof NormalizedNodeContainer)) {
-                    return ModificationType.WRITE;
-                }
-
-                // Unkeyed collections are always written
-                if (data instanceof UnkeyedListNode || data instanceof OrderedMapNode || data instanceof OrderedLeafSetNode) {
-                    return ModificationType.WRITE;
-                }
-
-                // Everything else is subtree modified
-                return ModificationType.SUBTREE_MODIFIED;
-            case TOUCH:
-                return ModificationType.SUBTREE_MODIFIED;
-            case NONE:
-                return ModificationType.UNMODIFIED;
-            case WRITE:
-                return ModificationType.WRITE;
-            }
-
-            throw new IllegalStateException("Unhandled internal operation " + mod.getOperation());
+            return mod.modificationType();
         }
 
         private Optional<NormalizedNode<?, ?>> optionalData(final TreeNode meta) {
@@ -129,7 +93,7 @@ final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate {
         @Override
         public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
             final Optional<ModifiedNode> childMod = mod.getChild(identifier);
-            if(childMod.isPresent()) {
+            if (childMod.isPresent()) {
                 return childNode(mod);
             }
             return null;
index 7251e9259e698a816db1f1631e7938ef37c091af..62eb30ff0ab54fef9b3519f273b547960989256e 100644 (file)
@@ -30,7 +30,7 @@ public final class InMemoryDataTreeFactory implements DataTreeFactory {
         final NodeIdentifier root = new NodeIdentifier(SchemaContext.NAME);
         final NormalizedNode<?, ?> data = Builders.containerBuilder().withNodeIdentifier(root).build();
 
-        return new InMemoryDataTree(TreeNodeFactory.createTreeNodeRecursively(data, Version.initial()), null);
+        return new InMemoryDataTree(TreeNodeFactory.createTreeNode(data, Version.initial()), null);
     }
 
     /**
index eb6b9726bece91e6d9afa97af1d3037b21187117..4e2d84e13f99dfca366f1a5ae85eb47a0f099bf1 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
 import java.util.Map.Entry;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -37,7 +38,7 @@ final class InMemoryDataTreeModification implements DataTreeModification {
     InMemoryDataTreeModification(final InMemoryDataTreeSnapshot snapshot, final RootModificationApplyOperation resolver) {
         this.snapshot = Preconditions.checkNotNull(snapshot);
         this.strategyTree = Preconditions.checkNotNull(resolver).snapshot();
-        this.rootNode = ModifiedNode.createUnmodified(snapshot.getRootNode(), false);
+        this.rootNode = ModifiedNode.createUnmodified(snapshot.getRootNode(), strategyTree.getChildPolicy());
 
         /*
          * We could allocate version beforehand, since Version contract
@@ -115,30 +116,48 @@ final class InMemoryDataTreeModification implements DataTreeModification {
         }
     }
 
-    private ModificationApplyOperation resolveModificationStrategy(final YangInstanceIdentifier path) {
-        LOG.trace("Resolving modification apply strategy for {}", path);
+    private void upgradeIfPossible() {
         if (rootNode.getOperation() == LogicalOperation.NONE) {
             strategyTree.upgradeIfPossible();
         }
+    }
+
+    private ModificationApplyOperation resolveModificationStrategy(final YangInstanceIdentifier path) {
+        LOG.trace("Resolving modification apply strategy for {}", path);
 
+        upgradeIfPossible();
         return StoreTreeNodes.<ModificationApplyOperation>findNodeChecked(strategyTree, path);
     }
 
     private OperationWithModification resolveModificationFor(final YangInstanceIdentifier path) {
-        // We ensure strategy is present.
-        final ModificationApplyOperation operation = resolveModificationStrategy(path);
-
-        final boolean isOrdered;
-        if (operation instanceof SchemaAwareApplyOperation) {
-            isOrdered = ((SchemaAwareApplyOperation) operation).isOrdered();
-        } else {
-            isOrdered = true;
-        }
+        upgradeIfPossible();
 
+        /*
+         * Walk the strategy and modification trees in-sync, creating modification nodes as needed.
+         *
+         * If the user has provided wrong input, we may end up with a bunch of TOUCH nodes present
+         * ending with an empty one, as we will throw the exception below. This fact could end up
+         * being a problem, as we'd have bunch of phantom operations.
+         *
+         * That is fine, as we will prune any empty TOUCH nodes in the last phase of the ready
+         * process.
+         */
+        ModificationApplyOperation operation = strategyTree;
         ModifiedNode modification = rootNode;
-        for (PathArgument pathArg : path.getPathArguments()) {
-            modification = modification.modifyChild(pathArg, isOrdered);
+
+        int i = 1;
+        for(PathArgument pathArg : path.getPathArguments()) {
+            Optional<ModificationApplyOperation> potential = operation.getChild(pathArg);
+            if (!potential.isPresent()) {
+                throw new IllegalArgumentException(String.format("Child %s is not present in tree.",
+                        Iterables.toString(Iterables.limit(path.getPathArguments(), i))));
+            }
+            operation = potential.get();
+            ++i;
+
+            modification = modification.modifyChild(pathArg, operation.getChildPolicy());
         }
+
         return OperationWithModification.from(operation, modification);
     }
 
index da5af3bdd75d88aa565326cb2fb258e3b39d495b..aed8087641f2cdb63a6fe915a98f4c14ecdf40a3 100644 (file)
@@ -13,7 +13,7 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
  * This class is factory for upgradable root modifications and provides an
  * access to set latest backing implementation.
  */
-class LatestOperationHolder {
+final class LatestOperationHolder {
 
     private ModificationApplyOperation current = AlwaysFailOperation.INSTANCE;
 
@@ -22,7 +22,7 @@ class LatestOperationHolder {
      *
      * @return
      */
-    public ModificationApplyOperation getCurrent() {
+    ModificationApplyOperation getCurrent() {
         return current;
     }
 
@@ -41,7 +41,7 @@ class LatestOperationHolder {
      * @param newApplyOper
      *            New backing implementation
      */
-    public void setCurrent(final ModificationApplyOperation newApplyOper) {
+    void setCurrent(final ModificationApplyOperation newApplyOper) {
         current = newApplyOper;
     }
 
@@ -53,7 +53,7 @@ class LatestOperationHolder {
      * @return New upgradable {@link RootModificationApplyOperation} with
      *         {@link #getCurrent()} used as backing implementation.
      */
-    public RootModificationApplyOperation newSnapshot() {
+    RootModificationApplyOperation newSnapshot() {
         return new UpgradableModificationApplyOperation(this, current);
     }
 
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LeafModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LeafModificationStrategy.java
new file mode 100644 (file)
index 0000000..e5f07c6
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.schema.tree;
+
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+
+final class LeafModificationStrategy extends AbstractValueNodeModificationStrategy<LeafSchemaNode> {
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    LeafModificationStrategy(final LeafSchemaNode schema) {
+        super(schema, (Class) LeafNode.class);
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LeafSetEntryModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LeafSetEntryModificationStrategy.java
new file mode 100644 (file)
index 0000000..e364dde
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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.schema.tree;
+
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+
+final class LeafSetEntryModificationStrategy extends AbstractValueNodeModificationStrategy<LeafListSchemaNode> {
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    LeafSetEntryModificationStrategy(final LeafListSchemaNode schema) {
+        super(schema, (Class) LeafSetEntryNode.class);
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListEntryModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListEntryModificationStrategy.java
new file mode 100644 (file)
index 0000000..a0c5a3b
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+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.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+
+final class ListEntryModificationStrategy extends AbstractDataNodeContainerModificationStrategy<ListSchemaNode> {
+    ListEntryModificationStrategy(final ListSchemaNode schema) {
+        super(schema, MapEntryNode.class);
+    }
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    protected final DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+        checkArgument(original instanceof MapEntryNode);
+        return ImmutableMapEntryNodeBuilder.create((MapEntryNode) original);
+    }
+}
\ No newline at end of file
index fd678e61c0b52ed808cb33fd4ecdb99e9c204e6f..c890a28b09335ce6f520d2f21c2a7f6956f9dbf3 100644 (file)
@@ -10,13 +10,12 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 import com.google.common.base.Optional;
 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.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 
 /**
- *
  * Operation responsible for applying {@link ModifiedNode} on tree.
  *
  * Operation is composite - operation on top level node consists of
@@ -34,11 +33,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailed
  *
  * Hierarchical composite operation which is responsible for applying
  * modification on particular subtree and creating updated subtree
- *
- *
  */
-interface ModificationApplyOperation extends StoreTreeNode<ModificationApplyOperation> {
-
+abstract class ModificationApplyOperation implements StoreTreeNode<ModificationApplyOperation> {
     /**
      *
      * Implementation of this operation must be stateless and must not change
@@ -57,7 +53,19 @@ interface ModificationApplyOperation extends StoreTreeNode<ModificationApplyOper
      *         node, {@link Optional#absent()} if {@link ModifiedNode}
      *         resulted in deletion of this node.
      */
-    Optional<TreeNode> apply(ModifiedNode modification, Optional<TreeNode> storeMeta, Version version);
+    abstract Optional<TreeNode> apply(ModifiedNode modification, Optional<TreeNode> storeMeta, Version version);
+
+    /**
+    *
+    * Checks if provided node modification could be applied to current metadata node.
+    *
+    * @param modification Modification
+    * @param current Metadata Node to which modification should be applied
+    * @return true if modification is applicable
+    *         false if modification is no applicable
+    * @throws DataValidationFailedException
+    */
+   abstract void checkApplicable(YangInstanceIdentifier path, NodeModification modification, Optional<TreeNode> current) throws DataValidationFailedException;
 
     /**
      *
@@ -67,26 +75,21 @@ interface ModificationApplyOperation extends StoreTreeNode<ModificationApplyOper
      * @param modification to be verified.
      * @throws IllegalArgumentException If provided NodeModification does not adhere to the structure.
      */
-    void verifyStructure(ModifiedNode modification) throws IllegalArgumentException;
+    abstract void verifyStructure(ModifiedNode modification) throws IllegalArgumentException;
 
     /**
-     * Returns a suboperation for specified tree node
+     * Return the tracking policy for this node's children.
      *
-     * @return Reference to suboperation for specified tree node, {@link Optional#absent()}
-     *    if suboperation is not supported for specified tree node.
+     * @return Tracking policy, may not be null.
      */
-    @Override
-    Optional<ModificationApplyOperation> getChild(PathArgument child);
+    abstract ChildTrackingPolicy getChildPolicy();
 
     /**
+     * Returns a suboperation for specified tree node
      *
-     * Checks if provided node modification could be applied to current metadata node.
-     *
-     * @param modification Modification
-     * @param current Metadata Node to which modification should be applied
-     * @return true if modification is applicable
-     *         false if modification is no applicable
-     * @throws DataValidationFailedException
+     * @return Reference to suboperation for specified tree node, {@link Optional#absent()}
+     *    if suboperation is not supported for specified tree node.
      */
-    void checkApplicable(YangInstanceIdentifier path, NodeModification modification, Optional<TreeNode> current) throws DataValidationFailedException;
+    @Override
+    public abstract Optional<ModificationApplyOperation> getChild(PathArgument child);
 }
index 053e21ff2642b5fc5dfeca79fbbfaf514e8a4d44..dd06b890cb367569d8dcefaa10b9452c04fb9513 100644 (file)
@@ -10,7 +10,9 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
+import com.google.common.base.Verify;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -58,15 +60,24 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
     private LogicalOperation operation = LogicalOperation.NONE;
     private Optional<TreeNode> snapshotCache;
     private NormalizedNode<?, ?> value;
+    private ModificationType modType;
 
-    private ModifiedNode(final PathArgument identifier, final Optional<TreeNode> original, final boolean isOrdered) {
+    private ModifiedNode(final PathArgument identifier, final Optional<TreeNode> original, final ChildTrackingPolicy childPolicy) {
         this.identifier = identifier;
         this.original = original;
 
-        if (isOrdered) {
+        switch (childPolicy) {
+        case NONE:
+            children = Collections.emptyMap();
+            break;
+        case ORDERED:
             children = new LinkedHashMap<>();
-        } else {
+            break;
+        case UNORDERED:
             children = new HashMap<>();
+            break;
+        default:
+            throw new IllegalArgumentException("Unsupported child tracking policy " + childPolicy);
         }
     }
 
@@ -89,7 +100,6 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
         return original;
     }
 
-
     @Override
     LogicalOperation getOperation() {
         return operation;
@@ -116,14 +126,15 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
      * If this node's {@link ModificationType} is {@link ModificationType#UNMODIFIED}
      * changes modification type to {@link ModificationType#SUBTREE_MODIFIED}
      *
-     * @param child
+     * @param child child identifier, may not be null
+     * @param childPolicy child tracking policy for the node we are looking for
      * @return {@link ModifiedNode} for specified child, with {@link #getOriginal()}
      *         containing child metadata if child was present in original data.
      */
-    ModifiedNode modifyChild(final PathArgument child, final boolean isOrdered) {
+    ModifiedNode modifyChild(@Nonnull final PathArgument child, @Nonnull final ChildTrackingPolicy childPolicy) {
         clearSnapshot();
         if (operation == LogicalOperation.NONE) {
-            updateModificationType(LogicalOperation.TOUCH);
+            updateOperationType(LogicalOperation.TOUCH);
         }
         final ModifiedNode potential = children.get(child);
         if (potential != null) {
@@ -138,7 +149,7 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
             currentMetadata = Optional.absent();
         }
 
-        final ModifiedNode newlyCreated = new ModifiedNode(child, currentMetadata, isOrdered);
+        final ModifiedNode newlyCreated = new ModifiedNode(child, currentMetadata, childPolicy);
         children.put(child, newlyCreated);
         return newlyCreated;
     }
@@ -185,7 +196,7 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
         clearSnapshot();
         children.clear();
         this.value = null;
-        updateModificationType(newType);
+        updateOperationType(newType);
     }
 
     /**
@@ -195,14 +206,14 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
      */
     void write(final NormalizedNode<?, ?> value) {
         clearSnapshot();
-        updateModificationType(LogicalOperation.WRITE);
+        updateOperationType(LogicalOperation.WRITE);
         children.clear();
         this.value = value;
     }
 
     void merge(final NormalizedNode<?, ?> value) {
         clearSnapshot();
-        updateModificationType(LogicalOperation.MERGE);
+        updateOperationType(LogicalOperation.MERGE);
 
         /*
          * Blind overwrite of any previous data is okay, no matter whether the node
@@ -243,7 +254,7 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
 
         // A TOUCH node without any children is a no-op
         if (operation == LogicalOperation.TOUCH && children.isEmpty()) {
-            updateModificationType(LogicalOperation.NONE);
+            updateOperationType(LogicalOperation.NONE);
         }
     }
 
@@ -260,8 +271,9 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
         return snapshot;
     }
 
-    private void updateModificationType(final LogicalOperation type) {
+    private void updateOperationType(final LogicalOperation type) {
         operation = type;
+        modType = null;
         clearSnapshot();
     }
 
@@ -271,6 +283,14 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
                 + operation + ", childModification=" + children + "]";
     }
 
+    void resolveModificationType(@Nonnull final ModificationType type) {
+        modType = type;
+    }
+
+    @Nonnull ModificationType modificationType() {
+        return Verify.verifyNotNull(modType, "Node %s does not have resolved modification type", this);
+    }
+
     /**
      * Create a node which will reflect the state of this node, except it will behave as newly-written
      * value. This is useful only for merge validation.
@@ -279,12 +299,23 @@ final class ModifiedNode extends NodeModification implements StoreTreeNode<Modif
      * @return An isolated node. This node should never reach a datatree.
      */
     ModifiedNode asNewlyWritten(final NormalizedNode<?, ?> value) {
-        final ModifiedNode ret = new ModifiedNode(getIdentifier(), Optional.<TreeNode>absent(), false);
+        /*
+         * We are instantiating an "equivalent" of this node. Currently the only callsite does not care
+         * about the actual iteration order, so we do not have to specify the same tracking policy as
+         * we were instantiated with. Since this is the only time we need to know that policy (it affects
+         * only things in constructor), we do not want to retain it (saves some memory on per-instance
+         * basis).
+         *
+         * We could reconstruct it using two instanceof checks (to undo what the constructor has done),
+         * which would give perfect results. The memory saving would be at most 32 bytes of a short-lived
+         * object, so let's not bother with that.
+         */
+        final ModifiedNode ret = new ModifiedNode(getIdentifier(), Optional.<TreeNode>absent(), ChildTrackingPolicy.UNORDERED);
         ret.write(value);
         return ret;
     }
 
-    public static ModifiedNode createUnmodified(final TreeNode metadataTree, final boolean isOrdered) {
-        return new ModifiedNode(metadataTree.getIdentifier(), Optional.of(metadataTree), isOrdered);
+    public static ModifiedNode createUnmodified(final TreeNode metadataTree, final ChildTrackingPolicy childPolicy) {
+        return new ModifiedNode(metadataTree.getIdentifier(), Optional.of(metadataTree), childPolicy);
     }
 }
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NormalizedNodeContainerModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NormalizedNodeContainerModificationStrategy.java
deleted file mode 100644 (file)
index 053d0b0..0000000
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * 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.schema.tree;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
-import java.util.Collection;
-import java.util.Map;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
-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.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
-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.api.schema.tree.ModifiedNodeDoesNotExistException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.MutableTreeNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-
-abstract class NormalizedNodeContainerModificationStrategy extends SchemaAwareApplyOperation {
-
-    private final Class<? extends NormalizedNode<?, ?>> nodeClass;
-
-    protected NormalizedNodeContainerModificationStrategy(final Class<? extends NormalizedNode<?, ?>> nodeClass) {
-        this.nodeClass = nodeClass;
-    }
-
-    @Override
-    public void verifyStructure(final ModifiedNode modification) throws IllegalArgumentException {
-        for (ModifiedNode childModification : modification.getChildren()) {
-            resolveChildOperation(childModification.getIdentifier()).verifyStructure(childModification);
-        }
-    }
-
-    @SuppressWarnings("rawtypes")
-    @Override
-    protected void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
-        checkArgument(nodeClass.isInstance(writtenValue), "Node %s is not of type %s", writtenValue, nodeClass);
-        checkArgument(writtenValue instanceof NormalizedNodeContainer);
-
-        NormalizedNodeContainer container = (NormalizedNodeContainer) writtenValue;
-        for (Object child : container.getValue()) {
-            checkArgument(child instanceof NormalizedNode);
-
-            /*
-             * FIXME: fail-fast semantics:
-             *
-             * We can validate the data structure here, aborting the commit
-             * before it ever progresses to being committed.
-             */
-        }
-    }
-
-    @Override
-    protected TreeNode applyWrite(final ModifiedNode modification,
-            final Optional<TreeNode> currentMeta, final Version version) {
-        final NormalizedNode<?, ?> newValue = modification.getWrittenValue();
-        final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, version);
-
-        if (modification.getChildren().isEmpty()) {
-            return newValueMeta;
-        }
-
-        /*
-         * This is where things get interesting. The user has performed a write and
-         * then she applied some more modifications to it. So we need to make sense
-         * of that an apply the operations on top of the written value. We could have
-         * done it during the write, but this operation is potentially expensive, so
-         * we have left it out of the fast path.
-         *
-         * As it turns out, once we materialize the written data, we can share the
-         * code path with the subtree change. So let's create an unsealed TreeNode
-         * and run the common parts on it -- which end with the node being sealed.
-         *
-         * FIXME: this code needs to be moved out from the prepare() path and into
-         *        the read() and seal() paths. Merging of writes needs to be charged
-         *        to the code which originated this, not to the code which is
-         *        attempting to make it visible.
-         */
-        final MutableTreeNode mutable = newValueMeta.mutable();
-        mutable.setSubtreeVersion(version);
-
-        @SuppressWarnings("rawtypes")
-        final NormalizedNodeContainerBuilder dataBuilder = createBuilder(newValue);
-
-        return mutateChildren(mutable, dataBuilder, version, modification.getChildren());
-    }
-
-    /**
-     * Applies write/remove diff operation for each modification child in modification subtree.
-     * Operation also sets the Data tree references for each Tree Node (Index Node) in meta (MutableTreeNode) structure.
-     *
-     * @param meta MutableTreeNode (IndexTreeNode)
-     * @param data DataBuilder
-     * @param nodeVersion Version of TreeNode
-     * @param modifications modification operations to apply
-     * @return Sealed immutable copy of TreeNode structure with all Data Node references set.
-     */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    private TreeNode mutateChildren(final MutableTreeNode meta, final NormalizedNodeContainerBuilder data,
-            final Version nodeVersion, final Iterable<ModifiedNode> modifications) {
-
-        for (ModifiedNode mod : modifications) {
-            final YangInstanceIdentifier.PathArgument id = mod.getIdentifier();
-            final Optional<TreeNode> cm = meta.getChild(id);
-
-            Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
-            if (result.isPresent()) {
-                final TreeNode tn = result.get();
-                meta.addChild(tn);
-                data.addChild(tn.getData());
-            } else {
-                meta.removeChild(id);
-                data.removeChild(id);
-            }
-        }
-
-        meta.setData(data.build());
-        return meta.seal();
-    }
-
-    @Override
-    protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
-            final Version version) {
-        // For Node Containers - merge is same as subtree change - we only replace children.
-        return applySubtreeChange(modification, currentMeta, version);
-    }
-
-    @Override
-    public TreeNode applySubtreeChange(final ModifiedNode modification,
-            final TreeNode currentMeta, final Version version) {
-        final MutableTreeNode newMeta = currentMeta.mutable();
-        newMeta.setSubtreeVersion(version);
-
-        /*
-         * The user has issued an empty merge operation. In this case we do not perform
-         * a data tree mutation, do not pass GO, and do not collect useless garbage.
-         */
-        final Collection<ModifiedNode> children = modification.getChildren();
-        if (children.isEmpty()) {
-            newMeta.setData(currentMeta.getData());
-            return newMeta.seal();
-        }
-
-        @SuppressWarnings("rawtypes")
-        NormalizedNodeContainerBuilder dataBuilder = createBuilder(currentMeta.getData());
-
-        return mutateChildren(newMeta, dataBuilder, version, children);
-    }
-
-    @Override
-    protected void checkSubtreeModificationApplicable(final YangInstanceIdentifier path, final NodeModification modification,
-            final Optional<TreeNode> current) throws DataValidationFailedException {
-        if (!modification.getOriginal().isPresent() && !current.isPresent()) {
-            throw new ModifiedNodeDoesNotExistException(path, String.format("Node %s does not exist. Cannot apply modification to its children.", path));
-        }
-
-        SchemaAwareApplyOperation.checkConflicting(path, current.isPresent(), "Node was deleted by other transaction.");
-        checkChildPreconditions(path, modification, current);
-    }
-
-    private void checkChildPreconditions(final YangInstanceIdentifier path, final NodeModification modification, final Optional<TreeNode> current) throws DataValidationFailedException {
-        final TreeNode currentMeta = current.get();
-        for (NodeModification childMod : modification.getChildren()) {
-            final YangInstanceIdentifier.PathArgument childId = childMod.getIdentifier();
-            final Optional<TreeNode> childMeta = currentMeta.getChild(childId);
-
-            YangInstanceIdentifier childPath = path.node(childId);
-            resolveChildOperation(childId).checkApplicable(childPath, childMod, childMeta);
-        }
-    }
-
-    @Override
-    protected void checkMergeApplicable(final YangInstanceIdentifier path, final NodeModification modification,
-            final Optional<TreeNode> current) throws DataValidationFailedException {
-        if(current.isPresent()) {
-            checkChildPreconditions(path, modification,current);
-        }
-    }
-
-    @SuppressWarnings("rawtypes")
-    protected abstract NormalizedNodeContainerBuilder createBuilder(NormalizedNode<?, ?> original);
-
-    public static class ChoiceModificationStrategy extends NormalizedNodeContainerModificationStrategy {
-
-        private final Map<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> childNodes;
-
-        public ChoiceModificationStrategy(final ChoiceSchemaNode schemaNode) {
-            super(ChoiceNode.class);
-            ImmutableMap.Builder<YangInstanceIdentifier.PathArgument, ModificationApplyOperation> child = ImmutableMap.builder();
-
-            for (ChoiceCaseNode caze : schemaNode.getCases()) {
-                for (DataSchemaNode cazeChild : caze.getChildNodes()) {
-                    SchemaAwareApplyOperation childNode = SchemaAwareApplyOperation.from(cazeChild);
-                    child.put(new YangInstanceIdentifier.NodeIdentifier(cazeChild.getQName()), childNode);
-                }
-            }
-            childNodes = child.build();
-        }
-
-        @Override
-        public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument child) {
-            return Optional.fromNullable(childNodes.get(child));
-        }
-
-        @Override
-        @SuppressWarnings("rawtypes")
-        protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
-            checkArgument(original instanceof ChoiceNode);
-            return ImmutableChoiceNodeBuilder.create((ChoiceNode) original);
-        }
-    }
-
-    public static class OrderedLeafSetModificationStrategy extends NormalizedNodeContainerModificationStrategy {
-
-        private final Optional<ModificationApplyOperation> entryStrategy;
-
-        @SuppressWarnings({ "unchecked", "rawtypes" })
-        protected OrderedLeafSetModificationStrategy(final LeafListSchemaNode schema) {
-            super((Class) LeafSetNode.class);
-            entryStrategy = Optional.<ModificationApplyOperation> of(new ValueNodeModificationStrategy.LeafSetEntryModificationStrategy(schema));
-        }
-
-        @Override
-        boolean isOrdered() {
-            return true;
-        }
-
-        @SuppressWarnings("rawtypes")
-        @Override
-        protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
-            checkArgument(original instanceof OrderedLeafSetNode<?>);
-            return ImmutableOrderedLeafSetNodeBuilder.create((OrderedLeafSetNode<?>) original);
-        }
-
-        @Override
-        public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument identifier) {
-            if (identifier instanceof YangInstanceIdentifier.NodeWithValue) {
-                return entryStrategy;
-            }
-            return Optional.absent();
-        }
-    }
-
-    public static class OrderedMapModificationStrategy extends NormalizedNodeContainerModificationStrategy {
-
-        private final Optional<ModificationApplyOperation> entryStrategy;
-
-        protected OrderedMapModificationStrategy(final ListSchemaNode schema) {
-            super(OrderedMapNode.class);
-            entryStrategy = Optional.<ModificationApplyOperation> of(new DataNodeContainerModificationStrategy.ListEntryModificationStrategy(schema));
-        }
-
-        @Override
-        boolean isOrdered() {
-            return true;
-        }
-
-        @SuppressWarnings("rawtypes")
-        @Override
-        protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
-            checkArgument(original instanceof OrderedMapNode);
-            return ImmutableOrderedMapNodeBuilder.create((OrderedMapNode) original);
-        }
-
-        @Override
-        public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument identifier) {
-            if (identifier instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) {
-                return entryStrategy;
-            }
-            return Optional.absent();
-        }
-
-        @Override
-        public String toString() {
-            return "OrderedMapModificationStrategy [entry=" + entryStrategy + "]";
-        }
-    }
-
-    public static class UnorderedLeafSetModificationStrategy extends NormalizedNodeContainerModificationStrategy {
-
-        private final Optional<ModificationApplyOperation> entryStrategy;
-
-        @SuppressWarnings({ "unchecked", "rawtypes" })
-        protected UnorderedLeafSetModificationStrategy(final LeafListSchemaNode schema) {
-            super((Class) LeafSetNode.class);
-            entryStrategy = Optional.<ModificationApplyOperation> of(new ValueNodeModificationStrategy.LeafSetEntryModificationStrategy(schema));
-        }
-
-        @SuppressWarnings("rawtypes")
-        @Override
-        protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
-            checkArgument(original instanceof LeafSetNode<?>);
-            return ImmutableLeafSetNodeBuilder.create((LeafSetNode<?>) original);
-        }
-
-        @Override
-        public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument identifier) {
-            if (identifier instanceof YangInstanceIdentifier.NodeWithValue) {
-                return entryStrategy;
-            }
-            return Optional.absent();
-        }
-    }
-
-    public static class UnorderedMapModificationStrategy extends NormalizedNodeContainerModificationStrategy {
-
-        private final Optional<ModificationApplyOperation> entryStrategy;
-
-        protected UnorderedMapModificationStrategy(final ListSchemaNode schema) {
-            super(MapNode.class);
-            entryStrategy = Optional.<ModificationApplyOperation> of(new DataNodeContainerModificationStrategy.ListEntryModificationStrategy(schema));
-        }
-
-        @SuppressWarnings("rawtypes")
-        @Override
-        protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
-            checkArgument(original instanceof MapNode);
-            return ImmutableMapNodeBuilder.create((MapNode) original);
-        }
-
-        @Override
-        public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument identifier) {
-            if (identifier instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) {
-                return entryStrategy;
-            }
-            return Optional.absent();
-        }
-
-        @Override
-        public String toString() {
-            return "UnorderedMapModificationStrategy [entry=" + entryStrategy + "]";
-        }
-    }
-}
index 3293a05b066edea7cc77a9e51796794063fd4c4c..6d20d385ee194b908f6aa015679324fb5cbd3e39 100644 (file)
@@ -80,15 +80,7 @@ final class OperationWithModification {
 
     private OperationWithModification forChild(final PathArgument childId) {
         ModificationApplyOperation childOp = applyOperation.getChild(childId).get();
-
-        final boolean isOrdered;
-        if (childOp instanceof SchemaAwareApplyOperation) {
-            isOrdered = ((SchemaAwareApplyOperation) childOp).isOrdered();
-        } else {
-            isOrdered = true;
-        }
-
-        ModifiedNode childMod = modification.modifyChild(childId, isOrdered);
+        ModifiedNode childMod = modification.modifyChild(childId, childOp.getChildPolicy());
 
         return from(childOp,childMod);
     }
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedLeafSetModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedLeafSetModificationStrategy.java
new file mode 100644 (file)
index 0000000..4d0b62f
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import com.google.common.base.Optional;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+
+final class OrderedLeafSetModificationStrategy extends AbstractNodeContainerModificationStrategy {
+    private final Optional<ModificationApplyOperation> entryStrategy;
+
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    OrderedLeafSetModificationStrategy(final LeafListSchemaNode schema) {
+        super((Class) LeafSetNode.class);
+        entryStrategy = Optional.<ModificationApplyOperation> of(new LeafSetEntryModificationStrategy(schema));
+    }
+
+    @Override
+    protected ChildTrackingPolicy getChildPolicy() {
+        return ChildTrackingPolicy.ORDERED;
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
+        checkArgument(original instanceof OrderedLeafSetNode<?>);
+        return ImmutableOrderedLeafSetNodeBuilder.create((OrderedLeafSetNode<?>) original);
+    }
+
+    @Override
+    public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument identifier) {
+        if (identifier instanceof YangInstanceIdentifier.NodeWithValue) {
+            return entryStrategy;
+        }
+        return Optional.absent();
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedMapModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedMapModificationStrategy.java
new file mode 100644 (file)
index 0000000..0949be4
--- /dev/null
@@ -0,0 +1,44 @@
+package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import com.google.common.base.Optional;
+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.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+
+final class OrderedMapModificationStrategy extends AbstractNodeContainerModificationStrategy {
+    private final Optional<ModificationApplyOperation> entryStrategy;
+
+    OrderedMapModificationStrategy(final ListSchemaNode schema) {
+        super(OrderedMapNode.class);
+        entryStrategy = Optional.<ModificationApplyOperation> of(new ListEntryModificationStrategy(schema));
+    }
+
+    @Override
+    protected ChildTrackingPolicy getChildPolicy() {
+        return ChildTrackingPolicy.ORDERED;
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
+        checkArgument(original instanceof OrderedMapNode);
+        return ImmutableOrderedMapNodeBuilder.create((OrderedMapNode) original);
+    }
+
+    @Override
+    public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument identifier) {
+        if (identifier instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) {
+            return entryStrategy;
+        }
+        return Optional.absent();
+    }
+
+    @Override
+    public String toString() {
+        return "OrderedMapModificationStrategy [entry=" + entryStrategy + "]";
+    }
+}
\ No newline at end of file
index 18425dc243f7923d9e79ed81fed8776b45f1526a..868dfd1d520a011d59e60bfccd8d951390f3d94a 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import com.google.common.base.Optional;
-
 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.tree.DataValidationFailedException;
@@ -59,45 +58,50 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
  * update user did not invoked any operation.
  *
  */
-abstract class RootModificationApplyOperation implements ModificationApplyOperation {
+abstract class RootModificationApplyOperation extends ModificationApplyOperation {
 
     @Override
-    public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
+    public final Optional<ModificationApplyOperation> getChild(final PathArgument child) {
         return getDelegate().getChild(child);
     }
 
     @Override
-    public final void checkApplicable(final YangInstanceIdentifier path, final NodeModification modification, final Optional<TreeNode> current)
+    final void checkApplicable(final YangInstanceIdentifier path, final NodeModification modification, final Optional<TreeNode> current)
             throws DataValidationFailedException {
         getDelegate().checkApplicable(path, modification, current);
     }
 
     @Override
-    public final Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
+    final Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
             final Version version) {
         return getDelegate().apply(modification, currentMeta, version);
     }
 
     @Override
-    public boolean equals(final Object obj) {
+    public final boolean equals(final Object obj) {
         return getDelegate().equals(obj);
     }
 
     @Override
-    public int hashCode() {
+    public final int hashCode() {
         return getDelegate().hashCode();
     }
 
     @Override
-    public String toString() {
+    public final String toString() {
         return getDelegate().toString();
     }
 
     @Override
-    public void verifyStructure(final ModifiedNode modification) throws IllegalArgumentException {
+    final void verifyStructure(final ModifiedNode modification) throws IllegalArgumentException {
         getDelegate().verifyStructure(modification);
     }
 
+    @Override
+    final ChildTrackingPolicy getChildPolicy() {
+        return getDelegate().getChildPolicy();
+    }
+
     /**
      * Return the underlying delegate.
      *
@@ -114,7 +118,7 @@ abstract class RootModificationApplyOperation implements ModificationApplyOperat
      * @return Derived {@link RootModificationApplyOperation} with separate
      *         upgrade lifecycle.
      */
-    public abstract RootModificationApplyOperation snapshot();
+    abstract RootModificationApplyOperation snapshot();
 
     /**
      * Upgrades backing implementation to latest available, if possible.
@@ -124,9 +128,9 @@ abstract class RootModificationApplyOperation implements ModificationApplyOperat
      * operation and latest operation is updated by
      * {@link LatestOperationHolder#setCurrent(ModificationApplyOperation)}.
      */
-    public abstract void upgradeIfPossible();
+    abstract void upgradeIfPossible();
 
-    public static RootModificationApplyOperation from(final ModificationApplyOperation resolver) {
+    static RootModificationApplyOperation from(final ModificationApplyOperation resolver) {
         if (resolver instanceof RootModificationApplyOperation) {
             return ((RootModificationApplyOperation) resolver).snapshot();
         }
index f024a9d830f677c048e610e32e233b8c121cdc15..80ef74cf9a3a8b9bcc44e0fdbec3b514237882db 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.IncorrectDataStructureException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
@@ -32,20 +33,20 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
+abstract class SchemaAwareApplyOperation extends ModificationApplyOperation {
     private static final Logger LOG = LoggerFactory.getLogger(SchemaAwareApplyOperation.class);
 
     public static SchemaAwareApplyOperation from(final DataSchemaNode schemaNode) {
         if (schemaNode instanceof ContainerSchemaNode) {
-            return new DataNodeContainerModificationStrategy.ContainerModificationStrategy((ContainerSchemaNode) schemaNode);
+            return new ContainerModificationStrategy((ContainerSchemaNode) schemaNode);
         } else if (schemaNode instanceof ListSchemaNode) {
             return fromListSchemaNode((ListSchemaNode) schemaNode);
         } else if (schemaNode instanceof ChoiceSchemaNode) {
-            return new NormalizedNodeContainerModificationStrategy.ChoiceModificationStrategy((ChoiceSchemaNode) schemaNode);
+            return new ChoiceModificationStrategy((ChoiceSchemaNode) schemaNode);
         } else if (schemaNode instanceof LeafListSchemaNode) {
             return fromLeafListSchemaNode((LeafListSchemaNode) schemaNode);
         } else if (schemaNode instanceof LeafSchemaNode) {
-            return new ValueNodeModificationStrategy.LeafModificationStrategy((LeafSchemaNode) schemaNode);
+            return new LeafModificationStrategy((LeafSchemaNode) schemaNode);
         }
         throw new IllegalArgumentException("Not supported schema node type for " + schemaNode.getClass());
     }
@@ -55,7 +56,7 @@ abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
         for (AugmentationSchema potential : augSchemas.getAvailableAugmentations()) {
             for (DataSchemaNode child : potential.getChildNodes()) {
                 if (identifier.getPossibleChildNames().contains(child.getQName())) {
-                    return new DataNodeContainerModificationStrategy.AugmentationModificationStrategy(potential, resolvedTree);
+                    return new AugmentationModificationStrategy(potential, resolvedTree);
                 }
             }
         }
@@ -76,17 +77,17 @@ abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
             return new UnkeyedListModificationStrategy(schemaNode);
         }
         if (schemaNode.isUserOrdered()) {
-            return new NormalizedNodeContainerModificationStrategy.OrderedMapModificationStrategy(schemaNode);
+            return new OrderedMapModificationStrategy(schemaNode);
         }
 
-        return new NormalizedNodeContainerModificationStrategy.UnorderedMapModificationStrategy(schemaNode);
+        return new UnorderedMapModificationStrategy(schemaNode);
     }
 
     private static SchemaAwareApplyOperation fromLeafListSchemaNode(final LeafListSchemaNode schemaNode) {
         if(schemaNode.isUserOrdered()) {
-            return new NormalizedNodeContainerModificationStrategy.OrderedLeafSetModificationStrategy(schemaNode);
+            return new OrderedLeafSetModificationStrategy(schemaNode);
         } else {
-            return new NormalizedNodeContainerModificationStrategy.UnorderedLeafSetModificationStrategy(schemaNode);
+            return new UnorderedLeafSetModificationStrategy(schemaNode);
         }
     }
 
@@ -104,32 +105,32 @@ abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
     }
 
     @Override
-    public void verifyStructure(final ModifiedNode modification) throws IllegalArgumentException {
+    void verifyStructure(final ModifiedNode modification) throws IllegalArgumentException {
         if (modification.getOperation() == LogicalOperation.WRITE) {
             verifyWrittenStructure(modification.getWrittenValue());
         }
     }
 
     @Override
-    public final void checkApplicable(final YangInstanceIdentifier path,final NodeModification modification, final Optional<TreeNode> current) throws DataValidationFailedException {
+    final void checkApplicable(final YangInstanceIdentifier path,final NodeModification modification, final Optional<TreeNode> current) throws DataValidationFailedException {
         switch (modification.getOperation()) {
         case DELETE:
             checkDeleteApplicable(modification, current);
+            break;
         case TOUCH:
-            checkSubtreeModificationApplicable(path, modification, current);
-            return;
+            checkTouchApplicable(path, modification, current);
+            break;
         case WRITE:
             checkWriteApplicable(path, modification, current);
-            return;
+            break;
         case MERGE:
             checkMergeApplicable(path, modification, current);
-            return;
+            break;
         case NONE:
-            return;
+            break;
         default:
-            throw new UnsupportedOperationException("Suplied modification type "+ modification.getOperation()+ "is not supported.");
+            throw new UnsupportedOperationException("Suplied modification type "+ modification.getOperation()+ " is not supported.");
         }
-
     }
 
     protected void checkMergeApplicable(final YangInstanceIdentifier path, final NodeModification modification, final Optional<TreeNode> current) throws DataValidationFailedException {
@@ -176,21 +177,21 @@ abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
         }
     }
 
-    boolean isOrdered() {
-        return false;
+    @Override
+    protected ChildTrackingPolicy getChildPolicy() {
+        return ChildTrackingPolicy.UNORDERED;
     }
 
     @Override
-    public final Optional<TreeNode> apply(final ModifiedNode modification,
-            final Optional<TreeNode> currentMeta, final Version version) {
-
+    final Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta, final Version version) {
         switch (modification.getOperation()) {
         case DELETE:
+            modification.resolveModificationType(ModificationType.DELETE);
             return modification.setSnapshot(Optional.<TreeNode> absent());
         case TOUCH:
             Preconditions.checkArgument(currentMeta.isPresent(), "Metadata not available for modification",
                     modification);
-            return modification.setSnapshot(Optional.of(applySubtreeChange(modification, currentMeta.get(),
+            return modification.setSnapshot(Optional.of(applyTouch(modification, currentMeta.get(),
                     version)));
         case MERGE:
             final TreeNode result;
@@ -199,27 +200,47 @@ abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
             if (currentMeta.isPresent()) {
                 result = applyMerge(modification,currentMeta.get(), version);
             } else {
+                modification.resolveModificationType(ModificationType.WRITE);
                 result = applyWrite(modification, currentMeta, version);
             }
 
             return modification.setSnapshot(Optional.of(result));
         case WRITE:
+            modification.resolveModificationType(ModificationType.WRITE);
             return modification.setSnapshot(Optional.of(applyWrite(modification, currentMeta, version)));
         case NONE:
+            modification.resolveModificationType(ModificationType.UNMODIFIED);
             return currentMeta;
         default:
             throw new IllegalArgumentException("Provided modification type is not supported.");
         }
     }
 
-    protected abstract TreeNode applyMerge(ModifiedNode modification,
-            TreeNode currentMeta, Version version);
+    /**
+     * Apply a merge operation. Since the result of merge differs based on the data type
+     * being modified, implementations of this method are responsible for calling
+     * {@link ModifiedNode#resolveModificationType(ModificationType)} as appropriate.
+     *
+     * @param modification Modified node
+     * @param currentMeta Store Metadata Node on which NodeModification should be applied
+     * @param version New subtree version of parent node
+     * @return A sealed TreeNode representing applied operation.
+     */
+    protected abstract TreeNode applyMerge(ModifiedNode modification, TreeNode currentMeta, Version version);
 
-    protected abstract TreeNode applyWrite(ModifiedNode modification,
-            Optional<TreeNode> currentMeta, Version version);
+    protected abstract TreeNode applyWrite(ModifiedNode modification, Optional<TreeNode> currentMeta, Version version);
 
-    protected abstract TreeNode applySubtreeChange(ModifiedNode modification,
-            TreeNode currentMeta, Version version);
+    /**
+     * Apply a nested operation. Since there may not actually be a nested operation
+     * to be applied, implementations of this method are responsible for calling
+     * {@link ModifiedNode#resolveModificationType(ModificationType)} as appropriate.
+     *
+     * @param modification Modified node
+     * @param currentMeta Store Metadata Node on which NodeModification should be applied
+     * @param version New subtree version of parent node
+     * @return A sealed TreeNode representing applied operation.
+     */
+    protected abstract TreeNode applyTouch(ModifiedNode modification, TreeNode currentMeta, Version version);
 
     /**
      *
@@ -231,7 +252,7 @@ abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
      * @throws ConflictingModificationAppliedException If subtree was changed in conflicting way
      * @throws IncorrectDataStructureException If subtree modification is not applicable (e.g. leaf node).
      */
-    protected abstract void checkSubtreeModificationApplicable(YangInstanceIdentifier path, final NodeModification modification,
+    protected abstract void checkTouchApplicable(YangInstanceIdentifier path, final NodeModification modification,
             final Optional<TreeNode> current) throws DataValidationFailedException;
 
     protected abstract void verifyWrittenStructure(NormalizedNode<?, ?> writtenValue);
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnkeyedListItemModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnkeyedListItemModificationStrategy.java
new file mode 100644 (file)
index 0000000..9367b4c
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+
+final class UnkeyedListItemModificationStrategy extends AbstractDataNodeContainerModificationStrategy<ListSchemaNode> {
+    UnkeyedListItemModificationStrategy(final ListSchemaNode schemaNode) {
+        super(schemaNode, UnkeyedListEntryNode.class);
+    }
+
+    @Override
+    @SuppressWarnings("rawtypes")
+    protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+        checkArgument(original instanceof UnkeyedListEntryNode);
+        return ImmutableUnkeyedListEntryNodeBuilder.create((UnkeyedListEntryNode) original);
+    }
+}
\ No newline at end of file
index 23140b86a68cb86b597dabf44ce985fdb78b2e58..d786cc67b5fe61c21ba19df0e6ecd04c1baaca89 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum
 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.tree.IncorrectDataStructureException;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.MutableTreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
@@ -26,23 +27,24 @@ final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation {
 
     private final Optional<ModificationApplyOperation> entryStrategy;
 
-    protected UnkeyedListModificationStrategy(final ListSchemaNode schema) {
-        entryStrategy = Optional.<ModificationApplyOperation> of(new DataNodeContainerModificationStrategy.UnkeyedListItemModificationStrategy(schema));
+    UnkeyedListModificationStrategy(final ListSchemaNode schema) {
+        entryStrategy = Optional.<ModificationApplyOperation> of(new UnkeyedListItemModificationStrategy(schema));
     }
 
     @Override
-    boolean isOrdered() {
-        return true;
+    protected ChildTrackingPolicy getChildPolicy() {
+        return ChildTrackingPolicy.ORDERED;
     }
 
     @Override
     protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
             final Version version) {
+        modification.resolveModificationType(ModificationType.WRITE);
         return applyWrite(modification, Optional.of(currentMeta), version);
     }
 
     @Override
-    protected TreeNode applySubtreeChange(final ModifiedNode modification,
+    protected TreeNode applyTouch(final ModifiedNode modification,
             final TreeNode currentMeta, final Version version) {
         throw new UnsupportedOperationException("UnkeyedList does not support subtree change.");
     }
@@ -125,7 +127,7 @@ final class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation {
     }
 
     @Override
-    protected void checkSubtreeModificationApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+    protected void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
             final Optional<TreeNode> current) throws IncorrectDataStructureException {
         throw new IncorrectDataStructureException(path, "Subtree modification is not allowed.");
     }
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnorderedLeafSetModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnorderedLeafSetModificationStrategy.java
new file mode 100644 (file)
index 0000000..b88b28b
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import com.google.common.base.Optional;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+
+final class UnorderedLeafSetModificationStrategy extends AbstractNodeContainerModificationStrategy {
+    private final Optional<ModificationApplyOperation> entryStrategy;
+
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    UnorderedLeafSetModificationStrategy(final LeafListSchemaNode schema) {
+        super((Class) LeafSetNode.class);
+        entryStrategy = Optional.<ModificationApplyOperation> of(new LeafSetEntryModificationStrategy(schema));
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
+        checkArgument(original instanceof LeafSetNode<?>);
+        return ImmutableLeafSetNodeBuilder.create((LeafSetNode<?>) original);
+    }
+
+    @Override
+    public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument identifier) {
+        if (identifier instanceof YangInstanceIdentifier.NodeWithValue) {
+            return entryStrategy;
+        }
+        return Optional.absent();
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnorderedMapModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UnorderedMapModificationStrategy.java
new file mode 100644 (file)
index 0000000..9f13a9f
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.schema.tree;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import com.google.common.base.Optional;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+
+final class UnorderedMapModificationStrategy extends AbstractNodeContainerModificationStrategy {
+    private final Optional<ModificationApplyOperation> entryStrategy;
+
+    UnorderedMapModificationStrategy(final ListSchemaNode schema) {
+        super(MapNode.class);
+        entryStrategy = Optional.<ModificationApplyOperation> of(new ListEntryModificationStrategy(schema));
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
+        checkArgument(original instanceof MapNode);
+        return ImmutableMapNodeBuilder.create((MapNode) original);
+    }
+
+    @Override
+    public Optional<ModificationApplyOperation> getChild(final YangInstanceIdentifier.PathArgument identifier) {
+        if (identifier instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) {
+            return entryStrategy;
+        }
+        return Optional.absent();
+    }
+
+    @Override
+    public String toString() {
+        return "UnorderedMapModificationStrategy [entry=" + entryStrategy + "]";
+    }
+}
\ No newline at end of file
index 0727e449b9ee6a4b50a9314acba91b2c27c96bfc..6762cbbf1aab6239e4fd55e4e95b508fd339db8a 100644 (file)
@@ -20,18 +20,16 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
  *
  */
 final class UpgradableModificationApplyOperation extends RootModificationApplyOperation {
-
     private final LatestOperationHolder holder;
     private ModificationApplyOperation delegate;
 
-    public UpgradableModificationApplyOperation(final LatestOperationHolder holder, final ModificationApplyOperation delegate) {
+    UpgradableModificationApplyOperation(final LatestOperationHolder holder, final ModificationApplyOperation delegate) {
         this.holder = holder;
         this.delegate = delegate;
-
     }
 
     @Override
-    public void upgradeIfPossible() {
+    void upgradeIfPossible() {
         ModificationApplyOperation holderCurrent = holder.getCurrent();
         if (holderCurrent != delegate) {
             // FIXME: Allow update only if there is addition of models, not
@@ -46,7 +44,7 @@ final class UpgradableModificationApplyOperation extends RootModificationApplyOp
     }
 
     @Override
-    public RootModificationApplyOperation snapshot() {
+    RootModificationApplyOperation snapshot() {
         return new UpgradableModificationApplyOperation(holder, getDelegate());
     }
 
index bf3ece3d7e0a9cb4bd69fac4eff6232a807d6988..f27beec60beaf4e706fde3a8b56ca2b465536bd4 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableCo
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class SchemaAwareApplyOperationRoot extends DataNodeContainerModificationStrategy<ContainerSchemaNode> {
+public class SchemaAwareApplyOperationRoot extends AbstractDataNodeContainerModificationStrategy<ContainerSchemaNode> {
     private final SchemaContext context;
 
     public SchemaAwareApplyOperationRoot(final SchemaContext context) {
index f0854b30ae8ec2e1ab0873e4f2a36fcc72c26d8a..d3abae3465c4de36a5e21e20d3b9c435fa4ded21 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * 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
@@ -7,7 +8,6 @@
 package org.opendaylight.yangtools.yang.model.api;
 
 import com.google.common.base.Optional;
-
 import java.util.List;
 
 /**
index 7dd248cf379e8adc48c78bb580c52e56a4b8b19e..db707c56ed3cc3183353b9aed084c4e4f06492a6 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.model.api;
 
 import com.google.common.base.Optional;
index bb923b6f3f798e12629f6156d73b5feb7370dee6..36acbe9b5168c770bbff5558bf1d736b065bafea 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * 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.model.api;
 
 /**
index 99a30a465a9f94d3b6925b181af55d9ffae9f07a..8d0dd54d9fdd71ae54ee9fe7f966ad2a7462e072 100644 (file)
@@ -1,8 +1,3 @@
-package org.opendaylight.yangtools.yang.model.api;
-
-import java.net.URI;
-import java.util.Date;
-
 /*
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
@@ -10,6 +5,11 @@ import java.util.Date;
  * 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.model.api;
+
+import java.net.URI;
+import java.util.Date;
+
 public interface NamespaceRevisionAware {
 
     URI getNamespace();
index 4036658575d163dfb94417fc279d122a7a8cbd3c..7d17b042e6108dd76c1de2a831667775360639fa 100644 (file)
@@ -1,4 +1,3 @@
-
 /* Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
index b4264dff133cd341ef3ef0eccb28459db0a89e3b..c5fb34faaff7b8c658bc5313ff18d15a29cc4eb2 100644 (file)
@@ -11,9 +11,7 @@ import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 
 public interface ModuleStatement extends DeclaredStatement<String>, ModuleHeaderGroup, LinkageGroup, MetaGroup,
-        RevisionGroup, BodyGroup
-
-    {
+        RevisionGroup, BodyGroup {
 
     @Nonnull String getName();
 
index 89138d6a57e7fdbf3772fa3a2d5c1524c7f2d539..2062a635516496682397f5bb1ce32d30bed329a7 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
index 2597e9c185481d8886d4ee65155e74d9264cdc37..11782fe2acbc58820883fb70f900c624acc41cf5 100644 (file)
@@ -3,17 +3,14 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
 import com.google.common.util.concurrent.CheckedFuture;
-
 import java.util.Collection;
-
 import javax.annotation.Nonnull;
-
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
index 73569d384d3cd76091466ebe5474c70a96b57e6c..c86c25eb81a8febff2020e814b485e34e2487c19 100644 (file)
@@ -3,15 +3,13 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
 import com.google.common.util.concurrent.CheckedFuture;
-
 import javax.annotation.Nonnull;
-
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
index 42c92d58baaaee64c4122badfe4e329c3f0a24eb..0070cab71fe3d7bcf734060e9bfc4d6e63351d50 100644 (file)
@@ -27,20 +27,20 @@ public class SchemaResolutionException extends SchemaSourceException {
     private final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports;
     private final Collection<SourceIdentifier> resolvedSources;
 
-    public SchemaResolutionException(final @Nonnull String message) {
+    public SchemaResolutionException(@Nonnull final String message) {
         this(message, (Throwable)null);
     }
 
-    public SchemaResolutionException(final @Nonnull String message, final Throwable cause) {
+    public SchemaResolutionException(@Nonnull final String message, final Throwable cause) {
         this(message, cause, Collections.<SourceIdentifier>emptySet(), ImmutableMultimap.<SourceIdentifier, ModuleImport>of());
     }
 
-    public SchemaResolutionException(final @Nonnull String message, final Collection<SourceIdentifier> resolvedSources,
+    public SchemaResolutionException(@Nonnull final String message, final Collection<SourceIdentifier> resolvedSources,
             final @Nonnull Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
         this(message, null, resolvedSources, unsatisfiedImports);
     }
 
-    public SchemaResolutionException(final @Nonnull String message, final Throwable cause,
+    public SchemaResolutionException(@Nonnull final String message, final Throwable cause,
             @Nonnull final Collection<SourceIdentifier> resolvedSources,
             @Nonnull final Multimap<SourceIdentifier, ModuleImport> unsatisfiedImports) {
         super(formatMessage(message, resolvedSources, unsatisfiedImports), cause);
index d31da32ac491719f3959f2a14897bd8d79a807cb..d307213fd207aa180fd3a93ee77d9ca0340a8c12 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
index afeae46e5e3108d38cd6ea758eae775615e0a162..6da4ee301263ffbcb72c5200fdea0b54ee87c3da 100644 (file)
@@ -3,14 +3,13 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-
 import java.util.Collections;
 
 /**
index 4bffdd505fd01caf6b4910b87120b46b390effc1..053fe79b345eb8b12d2dc2d3d64c8b1b984d2048 100644 (file)
@@ -3,12 +3,11 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
-
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.concepts.Immutable;
 
index 2a688b3ff8347ede6894e73093dcd51e65f28010..f46ed3f426553be6f37a5a94e72b7d96b965c24c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
index 8ae9c287fb1c1c486f5c0a956603e8047e7e329b..e3083456ef16302008384266cdbc56cdfa9dbb1b 100644 (file)
@@ -3,22 +3,19 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import static com.google.common.base.Preconditions.checkArgument;
-
 import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.io.ByteSource;
-
 import java.io.IOException;
 import java.io.InputStream;
-
 import org.opendaylight.yangtools.concepts.Delegator;
 
 /**
index f09f525533e62982f6610c96344501414bcfa8b4..1fbe208536b4d8217ba5145d7791bf6d76dcda1e 100644 (file)
@@ -3,12 +3,11 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
-
 import org.w3c.dom.Document;
 
 /**
index 3e970949f50ac894e2248200301e39ec946ddd8c..7e480b9a692679d429b0c7cbe757d03724139269 100644 (file)
@@ -3,12 +3,11 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.spi;
 
 import com.google.common.annotations.Beta;
-
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
 /**
index b4f55a812e3b9cbbe43f316046a3c584f6bf22dd..71ca20307ffe3f0f18a5ecd61ec14045f249d203 100644 (file)
@@ -3,14 +3,12 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.spi;
 
 import com.google.common.annotations.Beta;
-
 import java.util.EventListener;
-
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 
 /**
index 90fc9dbe32c85303688651b67883729853b68eac..cdf6701805d94c700d856a49a0c32ea1ad3a3217 100644 (file)
@@ -3,13 +3,12 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.spi;
 
 import com.google.common.annotations.Beta;
 import com.google.common.util.concurrent.CheckedFuture;
-
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
index 6937c53e98ecbc42544cf61fa7f00b0ee792e880..d59c78d0f7483433ad390374e036ef2e732bb70d 100644 (file)
@@ -3,12 +3,11 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.spi;
 
 import com.google.common.annotations.Beta;
-
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 
index 075fcb5382d44ffb34532d20685c92de4cf86c7a..1b35c51d1c192ebec26f68a024355f5d3dd84257 100644 (file)
@@ -3,12 +3,11 @@
  *
  * 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/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 package org.opendaylight.yangtools.yang.model.repo.spi;
 
 import com.google.common.annotations.Beta;
-
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 
index 10abb048d51eb9916ad666a72eb4dc75f92f4ff7..20fe4ceb3a5401687394ef46377510441eaa9862 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -221,7 +222,7 @@ public final class SchemaContextUtil {
         final QName qname = Iterables.getFirst(schemaNode.getPath().getPathTowardsRoot(), null);
         Preconditions.checkState(qname != null,
                 "Schema Path contains invalid state of path parts. " +
-                "The Schema Path MUST contain at least ONE QName which defines namespace and Local name of path.");
+                        "The Schema Path MUST contain at least ONE QName which defines namespace and Local name of path.");
         return context.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision());
     }
 
@@ -626,7 +627,7 @@ public final class SchemaContextUtil {
         RevisionAwareXPath pathStatement = typeDefinition.getPathStatement();
         pathStatement = new RevisionAwareXPathImpl(stripConditionsFromXPathString(pathStatement), pathStatement.isAbsolute());
 
-        final Module parentModule = SchemaContextUtil.findParentModule(schemaContext, schema);
+        Module parentModule = findParentModuleByType(schemaContext, schema);
 
         final DataSchemaNode dataSchemaNode;
         if(pathStatement.isAbsolute()) {
@@ -651,6 +652,50 @@ public final class SchemaContextUtil {
         }
     }
 
+    /**
+     * Returns parent Yang Module for specified Schema Context in which Schema
+     * Node is declared. If Schema Node is of type 'ExtendedType' it tries to find parent module
+     * in which the type was originally declared (needed for correct leafref path resolution). <br>
+     * If the Schema Node is not present in Schema Context the
+     * operation will return <code>null</code>. <br>
+     * If Schema Context or Schema Node contains <code>null</code> references
+     * the method will throw IllegalArgumentException
+     *
+     * @throws IllegalArgumentException
+     *
+     * @param schemaContext
+     *            Schema Context
+     * @param schemaNode
+     *            Schema Node
+     * @return Yang Module for specified Schema Context and Schema Node, if
+     *         Schema Node is NOT present, the method will returns
+     *         <code>null</code>
+     */
+    public static Module findParentModuleByType(final SchemaContext schemaContext, final SchemaNode schemaNode) {
+        Preconditions.checkArgument(schemaContext != null, "Schema Context reference cannot be NULL!");
+        Preconditions.checkArgument(schemaNode != null, "Schema Node cannot be NULL!");
+        TypeDefinition<?> nodeType = null;
+
+        if (schemaNode instanceof LeafSchemaNode) {
+            nodeType = ((LeafSchemaNode) schemaNode).getType();
+        } else if (schemaNode instanceof LeafListSchemaNode) {
+            nodeType = ((LeafListSchemaNode) schemaNode).getType();
+        }
+
+        if (nodeType != null && nodeType instanceof ExtendedType) {
+            while (nodeType.getBaseType() instanceof ExtendedType) {
+                nodeType = nodeType.getBaseType();
+            }
+
+            QNameModule typeDefModuleQname = nodeType.getQName().getModule();
+
+            return schemaContext.findModuleByNamespaceAndRevision(typeDefModuleQname.getNamespace(),
+                    typeDefModuleQname.getRevision());
+        }
+
+        return SchemaContextUtil.findParentModule(schemaContext, schemaNode);
+    }
+
     /**
      * Returns base type for {@code typeDefinition} which belongs to module specified via {@code qName}. This handle case
      * when leafref type isn't specified as type substatement of leaf or leaf-list but is defined in other module as typedef