Degrade DataNodeContainer.getChildNodes() from Set to Collection
[yangtools.git] / code-generator / binding-generator-impl / src / main / java / org / opendaylight / yangtools / sal / binding / generator / impl / RuntimeGeneratedMappingServiceImpl.java
index e6dc334e3ea566f48979d4a696b23a2ef403bb22..a8e631c46c052cd68a5e63f7dc2b0bd5906c2cfd 100644 (file)
@@ -7,6 +7,14 @@
  */
 package org.opendaylight.yangtools.sal.binding.generator.impl;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+
+import java.net.URI;
 import java.util.AbstractMap.SimpleEntry;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -67,15 +75,8 @@ import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
-
 public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMappingService, SchemaContextListener,
-        SchemaLock, AutoCloseable, SchemaContextHolder, TypeResolver {
+SchemaLock, AutoCloseable, SchemaContextHolder, TypeResolver {
 
     private static final Logger LOG = LoggerFactory.getLogger(RuntimeGeneratedMappingServiceImpl.class);
 
@@ -89,10 +90,9 @@ public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMap
 
     private final ClassLoadingStrategy classLoadingStrategy;
 
-    // FIXME: will become final
-    private ClassPool pool;
-    private AbstractTransformerGenerator binding;
-    private LazyGeneratedCodecRegistry registry;
+    private final AbstractTransformerGenerator binding;
+    private final LazyGeneratedCodecRegistry registry;
+    private final ClassPool pool;
 
     /*
      * FIXME: updated here, access from AbstractTransformer
@@ -106,16 +106,6 @@ public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMap
     private final ConcurrentMap<Type, Type> typeDefinitions = new ConcurrentHashMap<>();
     private SchemaContext schemaContext;
 
-    @Deprecated
-    public RuntimeGeneratedMappingServiceImpl() {
-        this(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
-    }
-
-    @Deprecated
-    public RuntimeGeneratedMappingServiceImpl(final ClassLoadingStrategy strat) {
-        classLoadingStrategy = strat;
-    }
-
     public RuntimeGeneratedMappingServiceImpl(final ClassPool pool) {
         this(pool, GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
     }
@@ -123,12 +113,7 @@ public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMap
     public RuntimeGeneratedMappingServiceImpl(final ClassPool pool, final ClassLoadingStrategy strat) {
         this.pool = Preconditions.checkNotNull(pool);
         this.classLoadingStrategy = Preconditions.checkNotNull(strat);
-
-        // FIXME: merge into constructor once legacy init() is removed
-        doInit();
-    }
-
-    private void doInit() {
+        // FIXME: this escapes constructor
         binding = new TransformerGenerator(this, pool);
         registry = new LazyGeneratedCodecRegistry(this, binding, classLoadingStrategy);
         binding.setListener(registry);
@@ -139,11 +124,6 @@ public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMap
         // }
     }
 
-    @Deprecated
-    public void setPool(final ClassPool pool) {
-        this.pool = pool;
-    }
-
     @Override
     public synchronized SchemaContext getSchemaContext() {
         return schemaContext;
@@ -239,7 +219,7 @@ public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMap
 
     private CompositeNode toCompositeNodeImpl(final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier identifier,
             final DataObject object) {
-        PathArgument last = identifier.getPath().get(identifier.getPath().size() - 1);
+        PathArgument last = identifier.getLastPathArgument();
         Class<? extends DataContainer> cls = object.getImplementedInterface();
         waitForSchema(cls);
         DataContainerCodec<DataObject> codec = (DataContainerCodec<DataObject>) registry.getCodecForDataObject(cls);
@@ -251,8 +231,7 @@ public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMap
 
         // val cls = object.implementedInterface;
         // waitForSchema(cls);
-        org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument last = identifier.getPath().get(
-                identifier.getPath().size() - 1);
+        org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument last = identifier.getLastPathArgument();
         AugmentationCodec codec = registry.getCodecForAugmentation((Class) object.getImplementedInterface());
         CompositeNode ret = codec.serialize(new ValueWithQName<DataObject>(last.getNodeType(), object));
         if (last instanceof NodeIdentifierWithPredicates) {
@@ -261,7 +240,7 @@ public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMap
             for (Map.Entry<QName, Object> predicate : predicates.getKeyValues().entrySet()) {
                 newNodes.add(new SimpleNodeTOImpl<Object>(predicate.getKey(), null, predicate.getValue()));
             }
-            newNodes.addAll(ret.getChildren());
+            newNodes.addAll(ret.getValue());
             return new CompositeNodeTOImpl(last.getNodeType(), null, newNodes);
         }
         return ret;
@@ -352,10 +331,6 @@ public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMap
         }
     }
 
-    @Deprecated
-    public void init() {
-        doInit();
-    }
 
     @Override
     public Set<QName> getRpcQNamesFor(final Class<? extends RpcService> service) {
@@ -421,7 +396,7 @@ public class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMap
     public synchronized Optional<Class<? extends RpcService>> getRpcServiceClassFor(final String namespace, final String revision) {
         Module module = null;
         if (schemaContext != null) {
-            module = schemaContext.findModuleByName(namespace, QName.parseRevision(revision));
+            module = schemaContext.findModuleByNamespaceAndRevision(URI.create(namespace), QName.parseRevision(revision));
         }
         if (module == null) {
             return Optional.absent();