Example usage for java.lang.reflect Modifier isAbstract

List of usage examples for java.lang.reflect Modifier isAbstract

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isAbstract.

Prototype

public static boolean isAbstract(int mod) 

Source Link

Document

Return true if the integer argument includes the abstract modifier, false otherwise.

Usage

From source file:com.laxser.blitz.web.impl.module.ControllerRef.java

private boolean quicklyPass(List<Method> pastMethods, Method method, Class<?> controllerClass) {
    // public, not static, not abstract, @Ignored
    if (!Modifier.isPublic(method.getModifiers()) || Modifier.isAbstract(method.getModifiers())
            || Modifier.isStatic(method.getModifiers()) || method.isAnnotationPresent(Ignored.class)) {
        if (logger.isDebugEnabled()) {
            logger.debug("ignores method of controller " + controllerClass.getName() + "." + method.getName()
                    + "  [@ignored?not public?abstract?static?]");
        }/* w w w  .ja v a  2  s . c  om*/
        return true;
    }
    // ?(?)?????
    for (Method past : pastMethods) {
        if (past.getName().equals(method.getName())) {
            if (Arrays.equals(past.getParameterTypes(), method.getParameterTypes())) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.grouplens.grapht.util.Types.java

/**
 * Return true if the type is not abstract and not an interface, and has
 * a constructor annotated with {@link Inject} or its only constructor
 * is the default constructor./* w  w  w .j  a v a2s . com*/
 * 
 * @param type A class type
 * @return True if the class type is instantiable
 */
public static boolean isInstantiable(Class<?> type) {
    if (!Modifier.isAbstract(type.getModifiers()) && !type.isInterface()) {
        // first check for a constructor annotated with @Inject, 
        //  - this doesn't care how many we'll let the injector complain
        //    if there are more than one
        for (Constructor<?> c : type.getDeclaredConstructors()) {
            if (c.getAnnotation(Inject.class) != null) {
                return true;
            }
        }

        // check if we only have the public default constructor
        if (type.getConstructors().length == 1 && type.getConstructors()[0].getParameterTypes().length == 0) {
            return true;
        }
    }

    // no constructor available
    return false;
}

From source file:org.apache.usergrid.services.ServiceManager.java

@SuppressWarnings("unchecked")
private static Class<Service> findClass(String classname) {

    Class<Service> cls;
    try {/*from  www .  j  a v a2s  . c o  m*/
        logger.debug("Attempting to instantiate service class {}", classname);
        cls = (Class<Service>) Class.forName(classname);
        if (cls.isInterface()) {
            cls = (Class<Service>) Class.forName(classname.concat(IMPL));
        }
        if ((cls != null) && !Modifier.isAbstract(cls.getModifiers())) {
            return cls;
        }
    } catch (ClassNotFoundException e1) {
        logger.debug("Could not load class", e1);
    }
    return null;
}

From source file:org.broadleafcommerce.common.util.dao.DynamicDaoHelperImpl.java

@Override
public boolean isExcludeClassFromPolymorphism(Class<?> clazz) {
    //We filter out abstract classes because they can't be instantiated.
    if (Modifier.isAbstract(clazz.getModifiers())) {
        return true;
    }//from w w w. j  a v  a2s.c om

    //We filter out classes that are marked to exclude from polymorphism
    AdminPresentationClass adminPresentationClass = clazz.getAnnotation(AdminPresentationClass.class);
    if (adminPresentationClass == null) {
        return false;
    } else if (adminPresentationClass.excludeFromPolymorphism()) {
        return true;
    }
    return false;
}

From source file:org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer.java

@Override
public T createInstance() {
    if (Modifier.isAbstract(type.getModifiers()) || Modifier.isInterface(type.getModifiers())) {
        return null;
    } else {/* w ww.  ja  v a 2 s. com*/
        checkKryoInitialized();
        try {
            return kryo.newInstance(type);
        } catch (Throwable e) {
            return null;
        }
    }
}

From source file:gemlite.core.util.Util.java

public final static boolean isAbstractFunction(Class<?> c) {
    int modifiers = c.getModifiers();
    return Modifier.isAbstract(modifiers);
}

From source file:net.firejack.platform.core.utils.Factory.java

private <T> T convertFrom0(Class<?> clazz, Object dto) {
    if (dto == null)
        return null;
    Object bean = null;//from ww w. j  ava  2  s .  co  m
    try {
        bean = clazz.newInstance();
        List<FieldInfo> infos = fields.get(dto.getClass());
        if (infos == null) {
            infos = getAllField(dto.getClass(), dto.getClass(), new ArrayList<FieldInfo>());
            fields.put(dto.getClass(), infos);
        }
        for (FieldInfo info : infos) {
            if (info.readonly()) {
                continue;
            }

            String name = info.name();
            Object entity = bean;
            clazz = entity.getClass();
            String[] lookup = name.split("\\.");

            if (lookup.length > 1) {
                if (isNullValue(dto, info.getField().getName()))
                    continue;

                for (int i = 0; i < lookup.length - 1; i++) {
                    Object instance = get(entity, lookup[i], null);
                    if (instance == null) {
                        FieldInfo fieldInfo = getField(clazz, lookup[i]);
                        Class<?> type = fieldInfo.getType();
                        if (!type.isInterface() && !Modifier.isAbstract(type.getModifiers())) {
                            instance = type.newInstance();
                            set(entity, lookup[i], instance);

                            entity = instance;
                            clazz = type;
                        }
                    } else {
                        entity = instance;
                        clazz = instance.getClass();
                    }
                }
                name = lookup[lookup.length - 1];
            }

            FieldInfo distField = getField(clazz, name);
            if (distField != null) {
                Class<?> type = distField.getType();
                Object value = get(dto, info.getField().getName(), type);
                if (value != null) {
                    if (value instanceof AbstractDTO) {
                        if (contains(value)) {
                            Object convert = get(value);
                            set(entity, name, convert);
                        } else {
                            add(value, null);
                            Object convert = convertFrom0(type, value);
                            add(value, convert);
                            set(entity, name, convert);
                        }
                    } else if (value instanceof Collection) {
                        Collection result = (Collection) value;
                        Class<?> arrayType = distField.getGenericType();
                        if (AbstractModel.class.isAssignableFrom(arrayType)
                                || arrayType.isAnnotationPresent(XmlAccessorType.class)) {
                            try {
                                result = (Collection) value.getClass().newInstance();
                            } catch (InstantiationException e) {
                                result = new ArrayList();
                            }

                            for (Object o : (Collection) value) {
                                Object convert = convertFrom0(arrayType, o);
                                result.add(convert);
                            }
                        }
                        set(entity, name, result);
                    } else {
                        set(entity, name, value);
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.warn(e.getMessage());
    }
    return (T) bean;
}

From source file:org.cruxframework.crux.core.ioc.IocContainerManager.java

/**
 * /*from   w  ww.  j  a  va  2  s  .  c o  m*/
 * @param type
 * @param added
 * @param path
 * @param configurations
 */
private static void bindImplicityInjectionsForMethods(Class<?> type, Set<String> added, Set<String> path,
        Map<String, IocConfig<?>> configurations) {
    for (Method method : type.getDeclaredMethods()) {
        Inject inject = method.getAnnotation(Inject.class);
        Class<?>[] parameterTypes = method.getParameterTypes();
        if (inject != null && !Modifier.isAbstract(method.getModifiers()) && parameterTypes != null
                && parameterTypes.length > 0) {
            if (!added.contains(method.toString())) {
                added.add(method.toString());
                for (int i = 0; i < parameterTypes.length; i++) {
                    Class<?> parameterType = parameterTypes[i];
                    if (isBindable(parameterType, false)) {
                        if (path.contains(parameterType.getCanonicalName())) {
                            throw new IoCException(
                                    "IoC Create Looping Error between classes [" + type.getCanonicalName()
                                            + "] and [" + parameterType.getCanonicalName() + "].");
                        }
                        Set<String> methodPath = new HashSet<String>();
                        methodPath.addAll(path);
                        methodPath.add(parameterType.getCanonicalName());
                        bindTypeImplicitly(parameterType, configurations);
                        bindImplicityInjectcions(parameterType, new HashSet<String>(), methodPath, false,
                                configurations);
                    }
                }
            }
        }
    }
}

From source file:au.com.dw.testdatacapturej.reflection.util.ReflectionUtil.java

/**
 * Check if a class has a default setter method for a field, using the specific class of the field only.
 * i.e. no superclasses or interfaces./*from www. j a  v  a2s.co m*/
 *
 * Since we may want to invoke the setter method, abstract methods are not included (i.e. will return
 * false).
 *
 * @param clazz
 * @param parameterClass
 * @param setterMethodName
 * @return
 */
private static boolean hasSetterMethodForParameterClass(Class<?> clazz, String setterMethodName,
        Class<?> parameterClass) {
    boolean hasSetterMethodForParameterClass = false;

    try {
        Method method = clazz.getDeclaredMethod(setterMethodName, parameterClass);
        if (method != null) {
            int mod = method.getModifiers();
            // ignore abstract methods
            if (!Modifier.isAbstract(mod)) {
                hasSetterMethodForParameterClass = true;
            }
        }
    } catch (NoSuchMethodException nsme) {
        // no need to do anything, since this is what we are checking for
    } catch (Exception e) {
        e.printStackTrace();
    }
    return hasSetterMethodForParameterClass;
}

From source file:org.structr.module.JarConfigurationProvider.java

@Override
public Class getNodeEntityClass(final String simpleName) {

    Class nodeEntityClass = GenericNode.class;

    if ((simpleName != null) && (!simpleName.isEmpty())) {

        synchronized (SchemaService.class) {

            nodeEntityClass = nodeEntityClassCache.get(simpleName);

            if (nodeEntityClass == null) {

                for (String possiblePath : nodeEntityPackages) {

                    if (possiblePath != null) {

                        try {

                            Class nodeClass = Class.forName(possiblePath + "." + simpleName);

                            if (!Modifier.isAbstract(nodeClass.getModifiers())) {

                                nodeEntityClassCache.put(simpleName, nodeClass);
                                nodeEntityClass = nodeClass;

                                // first match wins
                                break;

                            }//from   ww w.  j a va2s. c o m

                        } catch (ClassNotFoundException ex) {

                            // ignore
                        }
                    }
                }
            }
        }
    }

    return nodeEntityClass;

}