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:org.apache.openjpa.util.ProxyManagerImpl.java

/**
 * Return the concrete type for proxying.
 *//*from   ww  w . j  a  v a2  s.  c  o m*/
protected Class toProxyableCollectionType(Class type) {
    if (type.getName().endsWith(PROXY_SUFFIX))
        type = type.getSuperclass();
    else if (type.isInterface()) {
        type = toConcreteType(type, _stdCollections);
        if (type == null)
            throw new UnsupportedException(_loc.get("no-proxy-intf", type));
    } else if (Modifier.isAbstract(type.getModifiers()))
        throw new UnsupportedException(_loc.get("no-proxy-abstract", type));
    return type;
}

From source file:ca.sqlpower.object.annotation.SPAnnotationProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (TypeElement el : annotations) {
        if (!this.annotations.contains(el.getQualifiedName().toString())) {
            return false;
        }//from   w  w  w  .java 2  s  .c o  m
    }
    Map<Class<? extends SPObject>, SPClassVisitor> visitors = new HashMap<Class<? extends SPObject>, SPClassVisitor>();
    for (Element typeDecl : roundEnv.getElementsAnnotatedWith(Persistable.class)) {
        SPClassVisitor visitor = new SPClassVisitor(typeDecl);
        typeDecl.accept(visitor, null);
        if (visitor.isValid() && visitor.getVisitedClass() != null) {
            visitors.put(visitor.getVisitedClass(), visitor);
        }
    }

    // This block checks if each of the classes has super classes that
    // contain persistable properties. If so, they should inherit those
    // persistable properties. Any additional packages should be
    // imported as well.
    for (Entry<Class<? extends SPObject>, SPClassVisitor> e : visitors.entrySet()) {
        Class<? extends SPObject> superClass = e.getKey();
        SPClassVisitor visitor = e.getValue();

        Multimap<String, String> mutatorImports = HashMultimap.create(visitor.getMutatorImports());
        Map<String, Class<?>> propertiesToAccess = new HashMap<String, Class<?>>(
                visitor.getPropertiesToAccess());
        Multimap<String, String> accessorAdditionalInfo = LinkedHashMultimap
                .create(visitor.getAccessorAdditionalInfo());
        Map<String, Class<?>> propertiesToMutate = new HashMap<String, Class<?>>(
                visitor.getPropertiesToMutate());
        Multimap<String, MutatorParameterObject> mutatorExtraParameters = LinkedHashMultimap
                .create(visitor.getMutatorExtraParameters());
        Multimap<String, Class<? extends Exception>> mutatorThrownTypes = HashMultimap
                .create(visitor.getMutatorThrownTypes());
        Set<String> propertiesToPersistOnlyIfNonNull = new HashSet<String>(
                visitor.getPropertiesToPersistOnlyIfNonNull());

        importedClassNames.clear();

        // Generate the persister helper file if the SPObject class is not abstract.
        if (!Modifier.isAbstract(visitor.getVisitedClass().getModifiers())) {
            generatePersisterHelperFile(superClass, visitor.getConstructorImports(),
                    visitor.getConstructorParameters(), propertiesToAccess, accessorAdditionalInfo,
                    mutatorImports, propertiesToMutate, mutatorExtraParameters, mutatorThrownTypes,
                    propertiesToPersistOnlyIfNonNull);
        } else {
            generateAbstractPersisterHelperFile(superClass, visitor.getConstructorImports(), propertiesToAccess,
                    accessorAdditionalInfo, mutatorImports, propertiesToMutate, mutatorExtraParameters,
                    mutatorThrownTypes, propertiesToPersistOnlyIfNonNull);
        }
    }
    return true;
}

From source file:org.zilverline.util.ClassFinder.java

/**
 * Finds all classes that extend the class, searching in the listAllClasses ArrayList.
 * //from  w w w. jav  a2 s .co m
 * @param theClass the parent class
 * @param listAllClasses the collection of classes to search in
 * @param listSubClasses the collection of discovered subclasses
 * @param innerClasses indicates whether inners classes should be included in the search
 */
private static void findAllSubclassesOneClass(Class theClass, List listAllClasses, List listSubClasses,
        boolean innerClasses) {
    Iterator iterClasses = null;
    String strClassName = null;
    Class c = null;
    boolean bIsSubclass = false;
    iterClasses = listAllClasses.iterator();
    while (iterClasses.hasNext()) {
        strClassName = (String) iterClasses.next();
        // only check classes if they are not inner classes
        // or we intend to check for inner classes
        if ((strClassName.indexOf("$") == -1) || innerClasses) {
            // might throw an exception, assume this is ignorable
            try {
                c = Class.forName(strClassName, false, Thread.currentThread().getContextClassLoader());

                if (!c.isInterface() && !Modifier.isAbstract(c.getModifiers())) {
                    bIsSubclass = theClass.isAssignableFrom(c);
                } else {
                    bIsSubclass = false;
                }
                if (bIsSubclass) {
                    listSubClasses.add(strClassName);
                }
            } catch (Throwable ignored) {
            }
        }
    }
}

From source file:org.hibernate.internal.util.ReflectHelper.java

/**
 * Determine if the given class is declared abstract.
 *
 * @param clazz The class to check.//from ww  w  . j a v a  2  s  .c  om
 * @return True if the class is abstract, false otherwise.
 */
public static boolean isAbstractClass(Class clazz) {
    int modifier = clazz.getModifiers();
    return Modifier.isAbstract(modifier) || Modifier.isInterface(modifier);
}

From source file:com.addthis.codec.config.Configs.java

/** should be roughly analagous to a removed method */
private static ConfigValue resolveType(Class<?> type, ConfigValue configValue, PluginMap pluginMap) {
    String classField = pluginMap.classField();
    if (configValue.valueType() != ConfigValueType.OBJECT) {
        if ((type == null) || Modifier.isAbstract(type.getModifiers())
                || Modifier.isInterface(type.getModifiers())) {
            if (configValue.valueType() == ConfigValueType.LIST) {
                Class<?> arrayType = pluginMap.arraySugar();
                if (arrayType != null) {
                    ConfigObject aliasDefaults = pluginMap.aliasDefaults("_array");
                    String arrayFieldName = aliasDefaults.toConfig().getString("_primary");
                    String arraySugarName = pluginMap.getLastAlias("_array");
                    return ConfigFactory.empty().root()
                            .withValue(classField, ConfigValueFactory.fromAnyRef(arraySugarName,
                                    pluginMap.category() + " array sugar : "
                                            + pluginMap.config().root().get("_array").origin().description()))
                            .withValue(arrayFieldName, configValue).withFallback(aliasDefaults);
                }/*from w w  w. j  av a2s  .com*/
            }
        }
        return configValue;
    }
    ConfigObject root = (ConfigObject) configValue;
    ConfigValue classValue = root.get(classField);
    // normal, explicit typing
    if ((classValue != null) && (classValue.valueType() == ConfigValueType.STRING)) {
        String classValueString = (String) classValue.unwrapped();
        ConfigObject aliasDefaults = pluginMap.aliasDefaults(classValueString);
        return root.withFallback(aliasDefaults);
    }

    if ((type == null) || Modifier.isAbstract(type.getModifiers())
            || Modifier.isInterface(type.getModifiers())) {
        // single key as type
        if (root.size() == 1) {
            String onlyKey = root.keySet().iterator().next();
            try {
                pluginMap.getClass(onlyKey); // make sure key is a valid type
                ConfigValue onlyKeyValue = root.values().iterator().next();
                ConfigObject aliasDefaults = pluginMap.aliasDefaults(onlyKey);
                if (onlyKeyValue.valueType() != ConfigValueType.OBJECT) {
                    if (aliasDefaults.get("_primary") != null) {
                        onlyKeyValue = onlyKeyValue.atPath((String) aliasDefaults.get("_primary").unwrapped())
                                .root();
                    } else {
                        throw new ConfigException.WrongType(onlyKeyValue.origin(), onlyKey, "OBJECT",
                                onlyKeyValue.valueType().toString());
                    }
                }
                ConfigObject fieldValues = (ConfigObject) onlyKeyValue;
                return fieldValues
                        .withValue(classField,
                                ConfigValueFactory.fromAnyRef(onlyKey,
                                        "single key to type from " + root.origin().description()))
                        .withFallback(aliasDefaults);
            } catch (ClassNotFoundException ignored) {
            }
        }

        // inlined type
        String matched = null;
        for (String alias : pluginMap.inlinedAliases()) {
            if (root.get(alias) != null) {
                if (matched != null) {
                    String message = String.format(
                            "no type specified, more than one key, and both %s and %s match for inlined types.",
                            matched, alias);
                    throw new ConfigException.Parse(root.origin(), message);
                }
                matched = alias;
            }
        }
        if (matched != null) {
            ConfigObject aliasDefaults = pluginMap.aliasDefaults(matched);
            ConfigValue inlinedValue = root.get(matched);
            String primaryField = (String) aliasDefaults.get("_primary").unwrapped();
            ConfigObject fieldValues = root.toConfig().withValue(primaryField, inlinedValue).root()
                    .withoutKey(matched).withFallback(aliasDefaults);
            return fieldValues.withValue(classField, ConfigValueFactory.fromAnyRef(matched,
                    "inlined key to type from " + root.origin().description()));
        }

        // default type
        ConfigValue defaultObject = pluginMap.config().root().get("_default");
        if (defaultObject != null) {
            String defaultName = pluginMap.getLastAlias("_default");
            ConfigObject aliasDefaults = pluginMap.aliasDefaults("_default");
            return root
                    .withValue(classField,
                            ConfigValueFactory.fromAnyRef(defaultName,
                                    pluginMap.category() + " default type : "
                                            + defaultObject.origin().description()))
                    .withFallback(aliasDefaults);
        }
    }
    return root;
}

From source file:cross.applicationContext.ReflectionApplicationContextGenerator.java

/**
 * Create a bean element for the given class.
 *
 * @param clazz the target class//from   w ww. ja v a 2s.c  o m
 * @return the bean element or a list of beans for each service provider
 * available
 */
public List<?> createElement(Class<?> clazz) {
    if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
        return createServiceProviderElements(clazz);
    }
    if (clazz.getConstructors().length == 0) {
        log.warn("Class {} has no public no-argument constructor!", clazz);
        return Collections.emptyList();
    }
    Object obj;
    try {
        obj = clazz.newInstance();
        //build a "bean" element for each class
        buildBeanElement(obj);
        return Arrays.asList(obj);
    } catch (InstantiationException | IllegalAccessException ex) {
        Logger.getLogger(ReflectionApplicationContextGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
    return Collections.emptyList();
}

From source file:hudson.model.Descriptor.java

/**
 * Creates a configured instance from the submitted form.
 *
 * <p>/*ww  w . ja  v  a  2 s .c  o  m*/
 * Hudson only invokes this method when the user wants an instance of <tt>T</tt>.
 * So there's no need to check that in the implementation.
 *
 * <p>
 * Starting 1.206, the default implementation of this method does the following:
 * <pre>
 * req.bindJSON(clazz,formData);
 * </pre>
 * <p>
 * ... which performs the databinding on the constructor of {@link #clazz}.
 *
 * @param req
 *      Always non-null. This object includes represents the entire submisison.
 * @param formData
 *      The JSON object that captures the configuration data for this {@link Descriptor}.
 *      See http://hudson.gotdns.com/wiki/display/HUDSON/Structured+Form+Submission
 *
 * @throws FormException
 *      Signals a problem in the submitted form.
 * @since 1.145
 */
public T newInstance(StaplerRequest req, JSONObject formData) throws FormException {
    try {
        Method m = getClass().getMethod("newInstance", StaplerRequest.class);

        if (!Modifier.isAbstract(m.getDeclaringClass().getModifiers())) {
            // this class overrides newInstance(StaplerRequest).
            // maintain the backward compatible behavior
            return newInstance(req);
        } else {
            // new behavior as of 1.206
            return req.bindJSON(clazz, formData);
        }
    } catch (NoSuchMethodException e) {
        throw new AssertionError(e); // impossible
    }
}

From source file:org.ajax4jsf.builder.config.ComponentBaseBean.java

public boolean isSuperRestoreStateMethodExists() {
    try {//from  w ww.  j a  va2s . c o  m
        Class superClass = getLoader().loadClass(getSuperclass());
        Class[] signature = { FacesContext.class, Object.class };
        try {
            Method m = superClass.getMethod("restoreState", signature);
            return !Modifier.isAbstract(m.getModifiers());
        } catch (NoSuchMethodException e) {
            return false;
        }
    } catch (ClassNotFoundException e) {
        getLog().error("superclass not found for tag " + getTag().getName(), e);
        return false;
    }
}

From source file:org.structr.core.module.ModuleService.java

public Class getNodeEntityClass(final String name) {

    Class ret = GenericNode.class;

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

        ret = nodeEntityClassCache.get(name);

        if (ret == null) {

            for (String possiblePath : nodeEntityPackages) {

                if (possiblePath != null) {

                    try {

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

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

                            nodeEntityClassCache.put(name, nodeClass);

                            // first match wins
                            break;

                        }//from  ww  w.  j  a va2 s  .c  o  m

                    } catch (ClassNotFoundException ex) {

                        // ignore
                    }

                }

            }

        }

    }

    return (ret);

}

From source file:cn.webwheel.DefaultMain.java

@SuppressWarnings("unchecked")
private void autoMap(String root, String pkg, String name) {
    Class cls;/*from w  ww  .j  ava 2  s. c  om*/
    try {
        cls = Class.forName(pkg + "." + name);
    } catch (ClassNotFoundException e) {
        return;
    }
    if (cls.isMemberClass() && !Modifier.isStatic(cls.getModifiers())) {
        return;
    }
    if (cls.isAnonymousClass() || cls.isLocalClass() || !Modifier.isPublic(cls.getModifiers())
            || Modifier.isAbstract(cls.getModifiers())) {
        return;
    }

    name = name.replace('$', '.');

    for (Method method : cls.getMethods()) {

        String pathPrefix = pkg.substring(root.length()).replace('.', '/') + '/';
        String path = pathPrefix + name + '.' + method.getName();

        Action action = getAction(cls, method);
        if (action == null)
            continue;

        if (!action.value().isEmpty()) {
            if (action.value().startsWith("?")) {
                path = path + action.value();
            } else if (action.value().startsWith(".")) {
                path = pathPrefix + name + action.value();
            } else if (!action.value().startsWith("/")) {
                path = pathPrefix + action.value();
            } else {
                path = action.value();
            }
        }
        ActionBinder binder = map(path);
        if (!action.rest().isEmpty()) {
            String rest = action.rest();
            if (!rest.startsWith("/"))
                rest = pathPrefix + rest;
            binder = binder.rest(rest);
        }
        SetterConfig cfg = binder.with(cls, method);
        if (!action.charset().isEmpty()) {
            cfg = cfg.setCharset(action.charset());
        }
        if (action.fileUploadFileSizeMax() != 0) {
            cfg = cfg.setFileUploadFileSizeMax(action.fileUploadFileSizeMax());
        }
        if (action.fileUploadSizeMax() != 0) {
            cfg.setFileUploadSizeMax(action.fileUploadSizeMax());
        }
        if (action.setterPolicy() != SetterPolicy.Auto) {
            cfg.setSetterPolicy(action.setterPolicy());
        }
    }
}