X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding2%2Fmdsal-binding2-dom-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fjavav2%2Fdom%2Fcodec%2Fimpl%2FBindingToNormalizedNodeCodec.java;h=9268cc9d0b1599e3e79a131e672936b95f05da7b;hb=21a7a7dcf9cee6f66cae97753d431e97866cd00d;hp=b051f871d21b1bb32ae0e1d5b2946e7bddecf65b;hpb=f81f2bd40c093fabd8f96fe8bd42dec4ad7fc3bf;p=mdsal.git diff --git a/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/impl/BindingToNormalizedNodeCodec.java b/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/impl/BindingToNormalizedNodeCodec.java index b051f871d2..9268cc9d0b 100644 --- a/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/impl/BindingToNormalizedNodeCodec.java +++ b/binding2/mdsal-binding2-dom-codec/src/main/java/org/opendaylight/mdsal/binding/javav2/dom/codec/impl/BindingToNormalizedNodeCodec.java @@ -7,24 +7,24 @@ */ package org.opendaylight.mdsal.binding.javav2.dom.codec.impl; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.annotations.Beta; -import com.google.common.base.Function; -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 com.google.common.collect.ImmutableBiMap; import java.lang.reflect.Method; -import java.net.URI; import java.util.AbstractMap.SimpleEntry; import java.util.Collection; -import java.util.Date; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.function.Function; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opendaylight.mdsal.binding.javav2.api.DataTreeIdentifier; @@ -35,8 +35,10 @@ import org.opendaylight.mdsal.binding.javav2.dom.codec.api.serializer.BindingNor import org.opendaylight.mdsal.binding.javav2.generator.impl.GeneratedClassLoadingStrategy; import org.opendaylight.mdsal.binding.javav2.runtime.context.BindingRuntimeContext; import org.opendaylight.mdsal.binding.javav2.runtime.reflection.BindingReflections; +import org.opendaylight.mdsal.binding.javav2.spec.base.Action; import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier; import org.opendaylight.mdsal.binding.javav2.spec.base.Notification; +import org.opendaylight.mdsal.binding.javav2.spec.base.Rpc; import org.opendaylight.mdsal.binding.javav2.spec.base.TreeArgument; import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; @@ -237,15 +239,15 @@ public final class BindingToNormalizedNodeCodec * create representation. * *

- * Returns Optional.absent for cases where target is mixin node except augmentation. + * Returns Optional.empty for cases where target is mixin node except augmentation. * */ public Optional> toBinding(final YangInstanceIdentifier normalized) throws DeserializationException { try { - return Optional.fromNullable(codecRegistry.fromYangInstanceIdentifier(normalized)); + return Optional.ofNullable(codecRegistry.fromYangInstanceIdentifier(normalized)); } catch (final IllegalArgumentException e) { - return Optional.absent(); + return Optional.empty(); } } @@ -265,9 +267,9 @@ public final class BindingToNormalizedNodeCodec try { final Entry, TreeNode> binding = Entry.class.cast(codecRegistry.fromNormalizedNode(normalized.getKey(), normalized.getValue())); - return Optional.fromNullable(binding); + return Optional.ofNullable(binding); } catch (final IllegalArgumentException e) { - return Optional.absent(); + return Optional.empty(); } } @@ -322,6 +324,7 @@ public final class BindingToNormalizedNodeCodec * - RPC as binding object * @return map of method with path of specific RPC */ + @Deprecated public ImmutableBiMap getRPCMethodToSchemaPath(final Class key) { final Module module = getModuleBlocking(key); final ImmutableBiMap.Builder ret = ImmutableBiMap.builder(); @@ -337,31 +340,36 @@ public final class BindingToNormalizedNodeCodec } /** - * Resolve method with path of specific Action as binding object. + * Get Action schema path. * - * @param key - * - action as binding object - * @return map of method with path of specific action + * @param type + * - Action implementation class type + * @return schema path of Action */ - public ImmutableBiMap getActionMethodToSchemaPath(final Class key) { - final Module module = getModuleBlocking(key); + public SchemaPath getActionPath(final Class> type) { + final ActionDefinition schema = runtimeContext.getActionDefinition(type); + checkArgument(schema != null, "Failed to find schema for %s", type); + return schema.getPath(); + } - final ImmutableBiMap.Builder ret = ImmutableBiMap.builder(); - try { - for (final ActionDefinition actionDefinition : runtimeContext.getSchemaContext().getActions()) { - final QName qName = actionDefinition.getQName(); - if (qName.getModule().equals(module.getQNameModule())) { - final Method method = runtimeContext.findOperationMethod(key, actionDefinition); - ret.put(method, actionDefinition.getPath()); - } - } - } catch (final NoSuchMethodException e) { - throw new IllegalStateException("Action defined in model does not have representation in generated class.", - e); - } - return ret.build(); + /** + * Get RPC schema path. + * + * @param type + * - RPC implementation class type + * @return schema path of RPC + */ + public SchemaPath getRpcPath(final Class> type) { + final RpcDefinition schema = runtimeContext.getRpcDefinition(type); + checkArgument(schema != null, "Failed to find schema for %s", type); + return schema.getPath(); } + public RpcDefinition getRpcDefinition(final Class> type) { + final RpcDefinition schema = runtimeContext.getRpcDefinition(type); + checkArgument(schema != null, "Failed to find schema for %s", type); + return schema; + } /** * Resolve method with definition of specific RPC as binding object. @@ -411,15 +419,13 @@ public final class BindingToNormalizedNodeCodec private Module getModuleBlocking(final Class modeledClass) { final QNameModule moduleName = BindingReflections.getQNameModule(modeledClass); - final URI namespace = moduleName.getNamespace(); - final Date revision = moduleName.getRevision(); BindingRuntimeContext localRuntimeContext = runtimeContext; Module module = localRuntimeContext == null ? null - : localRuntimeContext.getSchemaContext().findModuleByNamespaceAndRevision(namespace, revision); - if (module == null && futureSchema != null && futureSchema.waitForSchema(namespace, revision)) { + : localRuntimeContext.getSchemaContext().findModule(moduleName).get(); + if (module == null && futureSchema != null && futureSchema.waitForSchema(moduleName)) { localRuntimeContext = runtimeContext; Preconditions.checkState(localRuntimeContext != null, "BindingRuntimeContext is not available."); - module = localRuntimeContext.getSchemaContext().findModuleByNamespaceAndRevision(namespace, revision); + module = localRuntimeContext.getSchemaContext().findModule(moduleName).get(); } Preconditions.checkState(module != null, "Schema for %s is not available.", modeledClass); return module; @@ -459,7 +465,7 @@ public final class BindingToNormalizedNodeCodec final BindingTreeCodec currentCodecTree = codecRegistry.getCodecContext(); final InstanceIdentifier bindingPath = codecRegistry.fromYangInstanceIdentifier(domIdentifier); - Preconditions.checkArgument(bindingPath != null); + checkArgument(bindingPath != null); /** * If we are able to deserialize YANG instance identifier, getSubtreeCodec must return non-null value. */ @@ -548,6 +554,17 @@ public final class BindingToNormalizedNodeCodec return ret; } + //FIXME: avoid the duplication of the function above. + public

Set + toDOMDataTreeIdentifiers(final Set> subtrees) { + final Set ret = new HashSet<>(subtrees.size()); + + for (final DataTreeIdentifier subtree : subtrees) { + ret.add(toDOMDataTreeIdentifier(subtree)); + } + return ret; + } + /** * Create new DOM data tree identifier from Binding data tree identifier. *