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.codehaus.groovy.grails.plugins.springsecurity.acl.GroovyAwareAclVoter.java

/**
 * {@inheritDoc}//from  ww  w . jav  a 2  s. c  o  m
 * @see org.springframework.security.access.AccessDecisionVoter#supports(java.lang.Class)
 */
public boolean supports(final Class<?> clazz) {
    return clazz.isAssignableFrom(MethodInvocation.class);
}

From source file:com.vwf5.base.utils.DataUtil.java

/**
 * Collect distinct values of a property from an object list instead of
 * doing a for:each then call a getter/*  w w  w .j  a v  a2 s . c  o  m*/
 *
 * @param source object list
 * @param propertyName name of property
 * @param returnClass class of property
 * @return value list of property
 */
public static <T> Set<T> collectUniqueProperty(Collection<?> source, String propertyName,
        Class<T> returnClass) {
    Set<T> propertyValues = Sets.newHashSet();
    try {
        String getMethodName = "get" + upperFirstChar(propertyName);
        for (Object x : source) {
            Class<?> clazz = x.getClass();
            Method getMethod = clazz.getMethod(getMethodName);
            Object propertyValue = getMethod.invoke(x);
            if (returnClass.isAssignableFrom(propertyValue.getClass())) {
                propertyValues.add(returnClass.cast(propertyValue));
            }
        }
        return propertyValues;
    } catch (Exception e) {
        return Sets.newHashSet();
    }
}

From source file:fr.gael.drb.impl.http.HttpNode.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from   w  w  w.jav a  2 s  .co m*/
public Object getImpl(Class api) {
    if (api.isAssignableFrom(InputStream.class)) {
        try {
            URLConnection urlConnect = this.url.openConnection();

            if (this.url.getUserInfo() != null) {
                // HTTP Basic Authentication.
                String userpass = this.url.getUserInfo();
                String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
                urlConnect.setRequestProperty("Authorization", basicAuth);
            }

            urlConnect.setDoInput(true);
            urlConnect.setUseCaches(false);

            return urlConnect.getInputStream();
        } catch (IOException e) {
            return null;
        }
    }
    return null;
}

From source file:com.vwf5.base.utils.DataUtil.java

/**
 * Collect values of a property from an object list instead of doing a
 * for:each then call a getter/*from   w  w  w .  ja  v a2 s . c  o m*/
 *
 * @param source object list
 * @param propertyName name of property
 * @param returnClass class of property
 * @return value list of property
 */
public static <T> List<T> collectProperty(Collection<?> source, String propertyName, Class<T> returnClass) {
    List<T> propertyValues = Lists.newArrayList();
    try {
        String getMethodName = "get" + upperFirstChar(propertyName);
        for (Object x : source) {
            Class<?> clazz = x.getClass();
            Method getMethod = clazz.getMethod(getMethodName);
            Object propertyValue = getMethod.invoke(x);
            if (returnClass.isAssignableFrom(propertyValue.getClass())) {
                propertyValues.add(returnClass.cast(propertyValue));
            }
        }
        return propertyValues;
    } catch (Exception e) {
        return Lists.newArrayList();
    }
}

From source file:com.bstek.dorado.data.method.MethodAutoMatchingUtils.java

/**
 * ???//  w  ww.  ja  v a  2s.  c  o  m
 * 
 * @param methodDescriptor
 *            ??
 * @param object
 *            ??
 * @param parameters
 *            ??
 * @return ?
 * @throws Exception
 */
@SuppressWarnings("unchecked")
private static Object invokeMethod(MethodDescriptor methodDescriptor, Object object, Object[] parameters)
        throws Exception {
    Method method = methodDescriptor.getMethod();
    Class<?>[] parameterTypes = method.getParameterTypes();
    int[] argIndexs = methodDescriptor.getArgIndexs();
    Object[] realArgs = new Object[argIndexs.length];
    for (int i = 0; i < argIndexs.length; i++) {
        Object arg = parameters[argIndexs[i]];
        if (arg != null) {
            Class<?> defType = parameterTypes[i];
            Class<?> argType = ProxyBeanUtils.getProxyTargetType(arg.getClass());
            if (!defType.isAssignableFrom(argType)) {
                if (Number.class.isAssignableFrom(defType) && Number.class.isAssignableFrom(argType)) {
                    arg = NumberUtils.convertNumberToTargetClass((Number) arg,
                            (Class<? extends Number>) defType);
                } else if (isSimpleType(defType) || isSimpleType(argType)) {
                    arg = ConvertUtils.convert(arg, defType);
                }
            }
        }
        realArgs[i] = arg;
    }
    return method.invoke(object, realArgs);
}

From source file:net.joinedminds.masserr.util.IdentifiableBeanConverter.java

@Override
public Object convert(Class type, Object value) {
    if (type.isAssignableFrom(value.getClass())) {
        return value;
    }//w w  w  . j a  va 2  s  . c o m
    Constructor constructor;
    try {
        try {
            constructor = type.getConstructor(value.getClass());
            return constructor.newInstance(value);
        } catch (NoSuchMethodException e) {
            try {
                constructor = type.getConstructor(String.class);
                return constructor.newInstance(value.toString());
            } catch (NoSuchMethodException e1) {
                throw new ConversionException("Could not find single parameter constructor.", e1);
            }
        }
    } catch (Exception e) {
        throw new ConversionException("Could not construct " + type.getName(), e);
    }
}

From source file:org.arrow.model.definition.AbstractEventPublisherIntroduction.java

/**
 * {@inheritDoc}/*  w ww.  j  a v a2s  . co m*/
 */
@Override
protected Object doProceed(MethodInvocation mi) throws Throwable {

    Method method = mi.getMethod();
    Class<?> dc = method.getDeclaringClass();
    if (dc.isAssignableFrom(Executable.class) && method.getName().equals("execute")) {
        Execution execution = (Execution) mi.getArguments()[0];
        ExecutionService service = (ExecutionService) mi.getArguments()[1];

        Logger.getLogger(getClass()).info("publish event");
        publishEvent(execution, service);
    }

    return mi.proceed();
}

From source file:de.iew.framework.security.access.WebResourceAccessDecisionVoter.java

public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(FilterInvocation.class);
}

From source file:ca.oson.json.util.ObjectUtil.java

public static boolean isinstanceof(Annotation a, Class<? extends Annotation> c) {
    if (a.annotationType().equals(c) || a.getClass().isAnnotationPresent(c)
            || c.isAssignableFrom(a.annotationType()))
        return true;

    return false;
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.WebExpressionVoter.java

/**
 * {@inheritDoc}//  w  w w  .j  a  va2 s . co m
 * @see org.springframework.security.access.AccessDecisionVoter#supports(java.lang.Class)
 */
public boolean supports(Class<?> clazz) {
    return clazz.isAssignableFrom(FilterInvocation.class);
}