Example usage for java.lang Class isAssignableFrom

List of usage examples for java.lang Class isAssignableFrom

Introduction

In this page you can find the example usage for java.lang Class isAssignableFrom.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isAssignableFrom(Class<?> cls);

Source Link

Document

Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter.

Usage

From source file:org.taverna.server.master.rest.handler.FileConcatenationHandler.java

@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    return type.isAssignableFrom(FileConcatenation.class);
}

From source file:com.ibm.jaql.lang.expr.core.ExpectExceptionFn.java

@Override
public JsonValue eval(final Context context) throws Exception {
    try {//from ww  w .  j av a2 s . c  o  m
        JsonValue value = exprs[0].eval(context);
        throw new RuntimeException("Expected exception but found " + value);
    } catch (Exception ex) {
        if (exprs.length == 1) {
            LOG.info("any exception expected", ex);
            return EXPECTED;
        }
        Throwable cause = ex;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }
        Class<?> causeClass = cause.getClass();
        for (int i = 1; i < exprs.length; i++) {
            JsonString js = (JsonString) exprs[1].eval(context);
            Class<?> cls = ClassLoaderMgr.resolveClass(js.toString());
            if (cls.isAssignableFrom(causeClass)) {
                LOG.info("exception was expected " + cls.getName().toString(), ex);
                return EXPECTED;
            }
        }
        throw new RuntimeException("expected an exception, but not this one", ex);
    }
}

From source file:org.echocat.jomon.spring.AutomaticServicesDiscovery.java

protected boolean isExcluded(@Nonnull Class<?> type) {
    boolean excluded = false;
    if (_excludes != null) {
        for (final Class<?> exclude : _excludes) {
            if (exclude.isAssignableFrom(type)) {
                excluded = true;//  w ww .  j  av  a  2s  . c  o  m
                break;
            }
        }
    }
    return excluded;
}

From source file:com.vladmihalcea.concurrent.aop.OptimisticConcurrencyControlAspect.java

private boolean isRetryThrowable(Throwable throwable, Class<? extends Throwable>[] retryOn) {
    Throwable[] causes = ExceptionUtils.getThrowables(throwable);
    for (Throwable cause : causes) {
        for (Class<? extends Throwable> retryThrowable : retryOn) {
            if (retryThrowable.isAssignableFrom(cause.getClass())) {
                return true;
            }
        }//from w w w.j a  v  a2  s  .c  o m
    }
    return false;
}

From source file:com.github.parisoft.resty.response.ResponseInvocationHandler.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    final Class<?> declaringClass = method.getDeclaringClass();

    try {/*w w w .j  a  v  a 2  s .c  om*/
        if (declaringClass.isAssignableFrom(HttpResponse.class)) {
            return method.invoke(httpResponse, args);
        }

        if (declaringClass.isAssignableFrom(EntityReader.class)) {
            return method.invoke(entityReader, args);
        }

        if (declaringClass.isAssignableFrom(HttpResponseExtension.class)) {
            responseExtension.setResponse((Response) proxy);
            return method.invoke(responseExtension, args);
        }
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }

    return null;
}

From source file:jef.tools.ArrayUtils.java

/**
 * addArray apacheadd??....../*w ww .j av  a2s. c  o m*/
 */
@SuppressWarnings("unchecked")
public static <T> T[] addElement(T[] array, T data, Class<T> componentType) {
    if (data == null)
        return array;
    T[] newArray;
    if (array == null) {
        Assert.notNull(componentType, "The componentType shoule be assigned when the array is null.");
        newArray = (T[]) Array.newInstance(componentType, 1);
        newArray[0] = data;
    } else {
        Class<?> containerType = array.getClass().getComponentType();
        if (!containerType.isAssignableFrom(data.getClass())) {// prompt the
            // type
            // error.
            throw new ArrayStoreException("The new element which typed " + data.getClass().getName()
                    + " can not be put into a array whoes type is " + containerType.getName());
        }
        newArray = (T[]) Array.newInstance(containerType, array.length + 1);
        System.arraycopy(array, 0, newArray, 0, array.length);
        newArray[array.length] = data;
    }
    return newArray;
}

From source file:com.mylife.hbase.mapper.serialization.json.JsonSerializer.java

@Override
public <T> T deserialize(final byte[] byteArray, final Field field) throws IOException {
    if (byteArray == null || field == null) {
        return null;
    }// w w w .ja v a 2 s .  c  o m
    @SuppressWarnings("unchecked")
    final Class<T> type = (Class<T>) field.getType();
    if (type.isAssignableFrom(Map.class)) {
        final Type[] types = TypeHandler.getGenericTypesFromField(field);
        return OBJECT_MAPPER.reader(OBJECT_MAPPER.getTypeFactory().constructMapType(HashMap.class,
                (Class<?>) types[0], (Class<?>) types[1])).readValue(byteArray);
    }
    return OBJECT_MAPPER.readValue(byteArray, type);
}

From source file:com.haulmont.cuba.core.sys.remoting.RemoteServicesBeanCreator.java

@Nullable
protected String findLowestSubclassName(List<Class> interfaces) {
    outer: for (Class<?> intf : interfaces) {
        for (Class<?> other : interfaces) {
            if (intf != other && !other.isAssignableFrom(intf)) {
                continue outer;
            }/* w w  w . ja  v  a 2  s .  c o m*/
        }
        return intf.getName();
    }
    return null;
}

From source file:jetbrains.buildServer.server.rest.util.BeanFactory.java

private <T> boolean checkParametersMatch(final Class<?>[] argTypes, final Class[] reqTypes) {
    if (reqTypes.length != argTypes.length)
        return false;
    for (int i = 0; i < argTypes.length; i++) {
        final Class<?> paramType = argTypes[i];
        final Class<?> reqType = reqTypes[i];

        if (!reqType.isAssignableFrom(paramType)) {
            return false;
        }//from  ww  w  . j ava2s . c  om
    }
    return true;
}

From source file:org.apache.solr.kelvin.SimpleClassRegistry.java

public void addMappings(Map<String, String> mappings) throws ClassNotFoundException {
    for (Map.Entry<String, String> entry : mappings.entrySet()) {
        Class<?> target = Class.forName(entry.getValue());
        Class<?> required = this.getClass().getTypeParameters()[0].getClass();
        if (!required.isAssignableFrom(target)) {
            throw new ClassCastException(
                    String.format("%s does not implements %s", target.getName(), required.getName()));
        }/* w w w .  j ava  2s.  com*/

        map.put(entry.getKey(), target);
    }
}