*/
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;
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;
* create representation.
*
* <p>
- * 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<InstanceIdentifier<? extends TreeNode>> 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();
}
}
try {
final Entry<InstanceIdentifier<? extends TreeNode>, 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();
}
}
* - RPC as binding object
* @return map of method with path of specific RPC
*/
+ @Deprecated
public ImmutableBiMap<Method, SchemaPath> getRPCMethodToSchemaPath(final Class<?> key) {
final Module module = getModuleBlocking(key);
final ImmutableBiMap.Builder<Method, SchemaPath> ret = ImmutableBiMap.builder();
}
/**
- * 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<Method, SchemaPath> getActionMethodToSchemaPath(final Class<?> key) {
- final Module module = getModuleBlocking(key);
+ public SchemaPath getActionPath(final Class<? extends Action<?, ?, ?, ?>> type) {
+ final ActionDefinition schema = runtimeContext.getActionDefinition(type);
+ checkArgument(schema != null, "Failed to find schema for %s", type);
+ return schema.getPath();
+ }
- final ImmutableBiMap.Builder<Method, SchemaPath> 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<? extends Rpc<?, ?>> 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<? extends Rpc<?, ?>> 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.
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;
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.
*/
return ret;
}
+ //FIXME: avoid the duplication of the function above.
+ public <P extends TreeNode> Set<DOMDataTreeIdentifier>
+ toDOMDataTreeIdentifiers(final Set<DataTreeIdentifier<P>> subtrees) {
+ final Set<DOMDataTreeIdentifier> 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.
*