import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
-import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.RegEx;
import org.opendaylight.yangtools.util.ClassLoaderUtils;
+import org.opendaylight.yangtools.yang.binding.Action;
import org.opendaylight.yangtools.yang.binding.Augmentable;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.BaseIdentity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@Deprecated
public final class BindingReflections {
private static final long EXPIRATION_TIME = 60;
@SuppressWarnings("checkstyle:illegalCatch")
public static QNameModule getQNameModule(final Class<?> clz) {
- if (DataContainer.class.isAssignableFrom(clz) || BaseIdentity.class.isAssignableFrom(clz)) {
+ if (DataContainer.class.isAssignableFrom(clz) || BaseIdentity.class.isAssignableFrom(clz)
+ || Action.class.isAssignableFrom(clz)) {
return findQName(clz).getModule();
}
try {
checkArgument(cls != null);
String packageName = getModelRootPackageName(cls.getPackage());
final String potentialClassName = getModuleInfoClassName(packageName);
- return ClassLoaderUtils.withClassLoader(cls.getClassLoader(), (Callable<YangModuleInfo>) () -> {
+ return ClassLoaderUtils.callWithClassLoader(cls.getClassLoader(), () -> {
Class<?> moduleInfoClass = Thread.currentThread().getContextClassLoader().loadClass(potentialClassName);
return (YangModuleInfo) moduleInfoClass.getMethod("getInstance").invoke(null);
});
*/
public static Map<Class<?>, Method> getChildrenClassToMethod(final Class<?> type) {
checkArgument(type != null, "Target type must not be null");
- checkArgument(DataContainer.class.isAssignableFrom(type), "Supplied type must be derived from DataContainer");
+ checkArgument(DataContainer.class.isAssignableFrom(type), "Supplied type %s must be derived from DataContainer",
+ type);
Map<Class<?>, Method> ret = new HashMap<>();
for (Method method : type.getMethods()) {
Optional<Class<? extends DataContainer>> entity = getYangModeledReturnType(method);
return Optional.of(returnType);
} else if (List.class.isAssignableFrom(returnType)) {
try {
- return ClassLoaderUtils.withClassLoader(method.getDeclaringClass().getClassLoader(),
- (Callable<Optional<Class<? extends DataContainer>>>) () -> {
- Type listResult = ClassLoaderUtils.getFirstGenericParameter(method.getGenericReturnType());
- if (listResult instanceof Class
- && DataContainer.class.isAssignableFrom((Class) listResult)) {
- return Optional.of((Class) listResult);
- }
- return Optional.absent();
- });
+ return ClassLoaderUtils.callWithClassLoader(method.getDeclaringClass().getClassLoader(), () -> {
+ Type listResult = ClassLoaderUtils.getFirstGenericParameter(method.getGenericReturnType());
+ if (listResult instanceof Class
+ && DataContainer.class.isAssignableFrom((Class) listResult)) {
+ return Optional.of((Class) listResult);
+ }
+ return Optional.absent();
+ });
} catch (Exception e) {
/*
* It is safe to log this this exception on debug, since this
*/
private static Optional<QName> resolveQNameNoCache(final Class<?> key) {
try {
- Field field = key.getField(BindingMapping.QNAME_STATIC_FIELD_NAME);
- Object obj = field.get(null);
+ final Field field;
+ try {
+ field = key.getField(BindingMapping.QNAME_STATIC_FIELD_NAME);
+ } catch (NoSuchFieldException e) {
+ LOG.debug("{} does not have a {} field, falling back to computation", key,
+ BindingMapping.QNAME_STATIC_FIELD_NAME, e);
+ return Optional.of(computeQName(key));
+ }
+
+ final Object obj = field.get(null);
if (obj instanceof QName) {
return Optional.of((QName) obj);
}
-
- } catch (NoSuchFieldException e) {
- return Optional.of(computeQName(key));
-
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
/*
- *
- * It is safe to log this this exception on debug, since this method
- * should not fail. Only failures are possible if the runtime /
- * backing.
+ * It is safe to log this this exception on debug, since this method should not fail. Only failures are
+ * possible if the runtime / backing is inconsistent.
*/
LOG.debug("Unexpected exception during extracting QName for {}", key, e);
}
* constructors, etc).
*
* @param potential
- * Class which is potential substition
+ * Class which is potential substitution
* @param target
* Class which should be used at particular subtree
* @return true if and only if classes represents same data.
return false;
}
} catch (NoSuchMethodException e) {
- // Counterpart method is missing, so classes could not be
- // substituted.
+ // Counterpart method is missing, so classes could not be substituted.
return false;
} catch (SecurityException e) {
throw new IllegalStateException("Could not compare methods", e);