Address trivial eclipse warnings
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / AbstractDataNodeContainerModificationStrategy.java
index af3a9045153e64babfe1750d87d078259e6cbb7a..53d6d2fae1511e19bb634eacce5dc90c4afed756 100644 (file)
@@ -12,10 +12,13 @@ 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 com.google.common.util.concurrent.UncheckedExecutionException;
 import java.util.concurrent.ExecutionException;
+import javax.annotation.Nonnull;
 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.api.schema.tree.DataTreeConfiguration;
 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;
@@ -34,20 +37,23 @@ abstract class AbstractDataNodeContainerModificationStrategy<T extends DataNodeC
     private final LoadingCache<PathArgument, ModificationApplyOperation> childCache = CacheBuilder.newBuilder()
             .build(new CacheLoader<PathArgument, ModificationApplyOperation>() {
                 @Override
-                public ModificationApplyOperation load(final PathArgument key) throws Exception {
+                public ModificationApplyOperation load(@Nonnull final PathArgument key) {
                     if (key instanceof AugmentationIdentifier && schema instanceof AugmentationTarget) {
-                        return SchemaAwareApplyOperation.from(schema, (AugmentationTarget) schema, (AugmentationIdentifier) key);
+                        return SchemaAwareApplyOperation.from(schema, (AugmentationTarget) schema, (AugmentationIdentifier) key, treeConfig);
                     }
 
                     final DataSchemaNode child = schema.getDataChildByName(key.getNodeType());
-                    return child == null ? null : SchemaAwareApplyOperation.from(child);
+                    Preconditions.checkArgument(child != null, "Schema %s does not have a node for child %s", schema, key.getNodeType());
+                    return SchemaAwareApplyOperation.from(child, treeConfig);
                 }
             });
     private final T schema;
+    private final DataTreeConfiguration treeConfig;
 
-    protected AbstractDataNodeContainerModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
-        super(nodeClass);
-        this.schema = Preconditions.checkNotNull(schema);
+    protected AbstractDataNodeContainerModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass, final DataTreeConfiguration treeConfig) {
+        super(nodeClass, treeConfig);
+        this.schema = Preconditions.checkNotNull(schema,"schema");
+        this.treeConfig = Preconditions.checkNotNull(treeConfig,"treeConfig");
     }
 
     protected final T getSchema() {
@@ -57,9 +63,9 @@ abstract class AbstractDataNodeContainerModificationStrategy<T extends DataNodeC
     @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.fromNullable(childCache.get(identifier));
+        } catch (ExecutionException | UncheckedExecutionException e) {
+            LOG.trace("Child {} not present in container schema {} children {}", identifier, this, schema.getChildNodes(), e.getCause());
             return Optional.absent();
         }
     }
@@ -72,4 +78,4 @@ abstract class AbstractDataNodeContainerModificationStrategy<T extends DataNodeC
     public String toString() {
         return getClass().getSimpleName() + " [" + schema + "]";
     }
-}
\ No newline at end of file
+}