2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.javav2.dom.adapter.impl.operation.invoker;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import com.google.common.cache.CacheBuilder;
13 import com.google.common.cache.CacheLoader;
14 import com.google.common.cache.LoadingCache;
15 import java.lang.reflect.Method;
16 import java.util.HashMap;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier;
20 import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifierNormalizer;
21 import org.opendaylight.mdsal.binding.javav2.runtime.reflection.BindingReflections;
22 import org.opendaylight.mdsal.binding.javav2.spec.base.Operation;
23 import org.opendaylight.yangtools.yang.common.QName;
26 final class ClassBasedOperationServiceInvoker extends AbstractMappedOperationInvoker<String> {
28 private static final LoadingCache<Class<? extends Operation>, OperationServiceInvoker> INVOKERS = CacheBuilder
29 .newBuilder().weakKeys().build(new CacheLoader<Class<? extends Operation>, OperationServiceInvoker>() {
32 public OperationServiceInvoker load(@Nonnull final Class<? extends Operation> key) {
33 final Map<String, Method> ret = new HashMap<>();
34 for (final Method m : key.getMethods()) {
35 ret.put(m.getName(), m);
38 return new ClassBasedOperationServiceInvoker(ret);
42 ClassBasedOperationServiceInvoker(final Map<String, Method> ret) {
47 protected String qnameToKey(final QName qname) {
48 return JavaIdentifierNormalizer.normalizeSpecificIdentifier(qname.getLocalName(), JavaIdentifier.METHOD);
51 static OperationServiceInvoker instanceFor(final Class<? extends Operation> type) {
52 Preconditions.checkArgument(type.isInterface());
53 Preconditions.checkArgument(BindingReflections.isBindingClass(type));
54 return INVOKERS.getUnchecked(type);