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.codehaus.groovy.grails.compiler.injection.GrailsASTUtils.java

public static ClassNode getFurthestUnresolvedParent(ClassNode classNode) {
    ClassNode parent = classNode.getSuperClass();

    while (parent != null && !getFullName(parent).equals("java.lang.Object") && !parent.isResolved()
            && !Modifier.isAbstract(parent.getModifiers())) {
        classNode = parent;/* w w w  .j  a  v  a  2s. co m*/
        parent = parent.getSuperClass();
    }
    return classNode;
}

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

@Override
public Class getRelationshipEntityClass(final String name) {

    Class relationClass = AbstractRelationship.class;

    if ((name != null) && (name.length() > 0)) {

        synchronized (SchemaService.class) {

            relationClass = relationshipEntityClassCache.get(name);

            if (relationClass == null) {

                for (String possiblePath : relationshipPackages) {

                    if (possiblePath != null) {

                        try {

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

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

                                relationshipEntityClassCache.put(name, nodeClass);

                                // first match wins
                                return nodeClass;

                            }//from  w w  w  . ja  v a  2 s. c  o  m

                        } catch (ClassNotFoundException ex) {

                            // ignore
                        }
                    }
                }
            }
        }
    }

    return relationClass;

}

From source file:org.solmix.datax.support.InvokerObject.java

@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object adaptValue(Class<?> targetType, Object argument, GenericParameterNode node, Class<?> javaClass,
        Class<?> javaCollectionClass, Class<?> javaKeyClass) {

    if (isCollection(targetType)) {
        try {//from   w w w.  j  av  a2s .co  m
            Object newArgValue;
            if (javaCollectionClass != void.class) {
                newArgValue = javaCollectionClass.newInstance();
            } else if (targetType.isInterface() || Modifier.isAbstract(targetType.getModifiers())) {
                if (Map.class.isAssignableFrom(targetType)) {
                    newArgValue = new LinkedMap();
                } else if (List.class.isAssignableFrom(targetType)) {
                    newArgValue = new ArrayList<Object>();
                } else if (Set.class.isAssignableFrom(targetType)) {
                    newArgValue = new HashSet<Object>();
                } else if (Queue.class.isAssignableFrom(targetType)) {
                    newArgValue = new LinkedList<Object>();
                } else if (Collection.class.isAssignableFrom(targetType)) {
                    newArgValue = new ArrayList<Object>();
                } else
                    newArgValue = argument.getClass().newInstance();
            } else {
                newArgValue = targetType.newInstance();
            }
            Iterator<Object> i = null;
            Object key = null;
            Class<?> keyClass = Object.class;
            Class<?> valueClass = null;
            Class<?> argType = argument.getClass();
            if (Collection.class.isAssignableFrom(targetType)) {
                if (argument instanceof Map) {
                    Map map = (Map) argument;
                    if (map.size() == 1) {
                        Iterator mapi = map.entrySet().iterator();
                        java.util.Map.Entry mape = (java.util.Map.Entry) mapi.next();
                        if (mape.getValue() instanceof Collection) {
                            argument = mape.getValue();
                            argType = argument.getClass();
                        } else if (mape.getValue() instanceof Map) {
                            argument = new ArrayList();
                            ((List) argument).add(mape.getValue());
                            argType = argument.getClass();
                        }
                    }
                }
                i = ((Collection) argument).iterator();
                if (node != null)
                    valueClass = node.getClassByIndex(0);
            } else if (Collection.class.isAssignableFrom(argType) && Map.class.isAssignableFrom(targetType)) {
                if (((Collection) argument).size() == 1) {
                    argument = ((Collection) argument).iterator().next();
                    argType = argument.getClass();
                    i = ((Map) argument).keySet().iterator();
                }
            } else {
                i = ((Map) argument).keySet().iterator();
                if (node != null) {
                    keyClass = node.getClassByIndex(0);
                    valueClass = node.getClassByIndex(1);
                }
            }
            if (javaClass != null)
                valueClass = javaClass;
            if (javaKeyClass != null)
                keyClass = javaKeyClass;
            boolean resetValueClass = false;
            if (valueClass == null)
                resetValueClass = true;
            while (i.hasNext()) {
                Object value = null;
                if (resetValueClass)
                    valueClass = null;
                if (Collection.class.isAssignableFrom(targetType)) {
                    value = i.next();
                } else {
                    key = i.next();
                    value = ((Map) argument).get(key);
                }
                if (valueClass == null && value != null)
                    valueClass = value.getClass();
                Object newValue = null;
                if (value != null) {
                    newValue = adaptValue(valueClass, value, node != null ? node.getChildNode() : null,
                            javaClass, javaCollectionClass, javaKeyClass);
                }
                Object newKey = key;
                if (keyClass != Object.class) {
                    newKey = adaptValue(keyClass, value, node != null ? node.getChildNode() : null, null, null,
                            null);
                }
                if (Collection.class.isAssignableFrom(targetType))
                    ((Collection) newArgValue).add(newValue);
                else
                    ((Map) argument).put(newKey, newValue);
            }
            return newArgValue;
        } catch (Exception e) {
            throw new InvokerException("transform argumnt type:" + targetType.getName() + " to value:"
                    + argument.getClass().getName(), e);
        }

    } else {
        if (targetType.isAssignableFrom(argument.getClass())) {
            return targetType.cast(argument);
        } else {
            try {
                return TransformUtils.transformType(targetType, argument);
            } catch (Exception e) {
                throw new InvokerException("transform argument value", e);
            }
        }
    }
}

From source file:com.artistech.protobuf.TuioProtoConverter.java

@Override
public Object convertFromProtobuf(final GeneratedMessage obj) {
    Object target;// w  ww. j a v a  2s  . c  om

    if (TuioProtos.Blob.class.isAssignableFrom(obj.getClass())) {
        target = new TUIO.TuioBlob();
    } else if (TuioProtos.Time.class.isAssignableFrom(obj.getClass())) {
        target = new TUIO.TuioTime();
    } else if (TuioProtos.Cursor.class.isAssignableFrom(obj.getClass())) {
        target = new TUIO.TuioCursor();
    } else if (TuioProtos.Object.class.isAssignableFrom(obj.getClass())) {
        target = new TUIO.TuioObject();
    } else if (TuioProtos.Point.class.isAssignableFrom(obj.getClass())) {
        target = new TUIO.TuioPoint();
    } else {
        return null;
    }

    try {
        PropertyDescriptor[] targetProps = Introspector.getBeanInfo(target.getClass()).getPropertyDescriptors();

        BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
        PropertyDescriptor[] messageProps = beanInfo.getPropertyDescriptors();
        Method[] methods = obj.getClass().getMethods();

        for (PropertyDescriptor targetProp : targetProps) {
            for (PropertyDescriptor messageProp : messageProps) {
                if (targetProp.getName().equals(messageProp.getName())) {
                    Method writeMethod = targetProp.getWriteMethod();
                    Method readMethod = null;
                    for (Method m : methods) {
                        if (writeMethod != null
                                && m.getName().equals(writeMethod.getName().replaceFirst("set", "get"))) {
                            readMethod = m;
                            break;
                        }
                    }
                    try {
                        if (writeMethod != null && readMethod != null && targetProp.getReadMethod() != null) {
                            boolean primitiveOrWrapper = ClassUtils
                                    .isPrimitiveOrWrapper(targetProp.getReadMethod().getReturnType());

                            if (readMethod.getParameterTypes().length > 0) {
                                if (DeepCopy) {
                                    if (!Modifier.isAbstract(targetProp.getPropertyType().getModifiers())) {
                                        //basically, ArrayList
                                        Object newInstance = targetProp.getPropertyType().newInstance();
                                        Method addMethod = newInstance.getClass().getMethod("add",
                                                Object.class);
                                        Method m = obj.getClass().getMethod(readMethod.getName() + "Count");
                                        int size = (int) m.invoke(obj);
                                        for (int ii = 0; ii < size; ii++) {
                                            Object o = readMethod.invoke(obj, ii);
                                            addMethod.invoke(newInstance, o);
                                        }
                                        writeMethod.invoke(target, newInstance);
                                    } else if (Collection.class
                                            .isAssignableFrom(targetProp.getPropertyType())) {
                                        //do something if it is a collection or iterable...
                                    }
                                }
                            } else if (primitiveOrWrapper) {
                                writeMethod.invoke(target, messageProp.getReadMethod().invoke(obj));
                            } else {
                                if (GeneratedMessage.class
                                        .isAssignableFrom(messageProp.getReadMethod().getReturnType())) {

                                    GeneratedMessage invoke = (GeneratedMessage) messageProp.getReadMethod()
                                            .invoke(obj);
                                    Object val = null;
                                    for (ProtoConverter converter : services) {
                                        if (converter.supportsConversion(invoke)) {
                                            val = convertFromProtobuf(invoke);
                                            break;
                                        }
                                    }
                                    if (val != null) {
                                        writeMethod.invoke(target, val);
                                    }
                                }
                                //                                    System.out.println("Prop1 Name!: " + targetProp.getName());
                            }
                        }
                    } catch (NullPointerException ex) {
                        //Logger.getLogger(ZeroMqMouse.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (InstantiationException | NoSuchMethodException | IllegalArgumentException
                            | SecurityException | IllegalAccessException | InvocationTargetException ex) {
                        logger.error(ex);
                    }
                    break;
                }
            }
        }
    } catch (java.beans.IntrospectionException ex) {
        logger.fatal(ex);
    }
    return target;
}

From source file:com.puppycrawl.tools.checkstyle.AllChecksTest.java

/**
 * Checks whether a class may be considered as the checkstyle check.
 * Checkstyle's checks are nonabstract classes which names end with 'Check',
 * do not contain the word 'Input' (are not input files for UTs).
 * @param loadedClass class to check./*from  w  w  w. j  a  va  2s .co  m*/
 * @param className class name to check.
 * @return true if a class may be considered as the checkstyle check.
 */
private static boolean isCheckstyleNonAbstractCheck(Class<?> loadedClass, String className) {
    return !Modifier.isAbstract(loadedClass.getModifiers()) && className.endsWith("Check")
            && !className.contains("Input");
}

From source file:pt.webdetails.cda.settings.SettingsManager.java

public DataAccessConnectionDescriptor[] getDataAccessDescriptors(boolean refreshCache) {

    ArrayList<DataAccessConnectionDescriptor> descriptors = new ArrayList<DataAccessConnectionDescriptor>();
    // First we need a list of all the data accesses. We're getting that from a .properties file, as a comma-separated array.

    Properties components = CdaEngine.getEnvironment().getCdaComponents();
    String[] dataAccesses = StringUtils.split(StringUtils.defaultString(components.getProperty("dataAccesses")),
            ",");

    // We apply some sanity checks to the dataAccesses listed:
    //    1. It can't be abstract,
    //    2. It must inherit from AbstractDataAccess
    // For any class that passes those tests, we get its getDataAccessDescripts() method, and use it to get a description.
    for (String dataAccess : dataAccesses) {

        Class<?> clazz = null;
        String className = DATA_ACCESS_PACKAGE + '.' + dataAccess;
        try {//  w ww. ja  va2s  .c om
            clazz = Class.forName(className);
        } catch (Exception e) {
            logger.error(MessageFormat.format("Couldn\'t load class {0}!", className));
            continue;
        }

        if (Modifier.isAbstract(clazz.getModifiers())) {
            logger.debug(dataAccess + " is abstract: Skipping");
        } else if (AbstractDataAccess.class.isAssignableFrom(clazz)) {
            try {
                @SuppressWarnings("unchecked")
                DataAccessConnectionDescriptor[] descriptor = DataAccessConnectionDescriptor
                        .fromClass((Class<? extends AbstractDataAccess>) clazz);
                descriptors.addAll(Arrays.asList(descriptor));
            } catch (InvocationTargetException e) {
                Throwable cause = e.getTargetException();
                if (cause.getClass() == UnsupportedOperationException.class) {
                    logger.warn("DataAccess " + dataAccess + " doesn't support discoverability!");
                } else {
                    logger.error("DataAccess " + dataAccess + " did something wrong!");
                }
            } catch (Exception e) {
                logger.error("DataAccess " + dataAccess + " did something wrong!");
            }
        }

    }
    return descriptors.toArray(new DataAccessConnectionDescriptor[descriptors.size()]);
}

From source file:org.syncope.core.rest.controller.TaskController.java

@PreAuthorize("hasRole('TASK_LIST')")
@RequestMapping(method = RequestMethod.GET, value = "/jobClasses")
public ModelAndView getJobClasses() {
    CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory();

    Set<String> jobClasses = new HashSet<String>();
    try {/*from w w  w .  j  a v  a  2 s  .  c o  m*/
        for (Resource resource : resResolver.getResources("classpath*:**/*.class")) {

            ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource)
                    .getClassMetadata();
            if (ArrayUtils.contains(metadata.getInterfaceNames(), Job.class.getName())
                    || AbstractTaskJob.class.getName().equals(metadata.getSuperClassName())
                    || ArrayUtils.contains(metadata.getInterfaceNames(), StatefulJob.class.getName())) {

                try {
                    Class jobClass = Class.forName(metadata.getClassName());
                    if (!Modifier.isAbstract(jobClass.getModifiers()) && !metadata.hasEnclosingClass()
                            && !jobClass.equals(SyncJob.class) && !jobClass.equals(ReportJob.class)
                            && !jobClass.equals(NotificationJob.class)) {

                        jobClasses.add(jobClass.getName());
                    }
                } catch (ClassNotFoundException e) {
                    LOG.error("Could not load class {}", metadata.getClassName(), e);
                }
            }
        }
    } catch (IOException e) {
        LOG.error("While searching for class implementing {}", Job.class.getName(), e);
    }

    ModelAndView result = new ModelAndView();
    result.addObject(jobClasses);
    return result;
}

From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowClientStandalone.java

private void handleClassFile(final File f, final JarEntry j) throws IOException, RuntimeException {
    final String classGuess = j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", "");
    try {//from  www.j av  a  2s .c o  m
        final Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess);
        final Ats ats = Ats.inClassHierarchy(candidate);
        if ((this.allowedClassNames.isEmpty() || this.allowedClassNames.contains(candidate.getName())
                || this.allowedClassNames.contains(candidate.getCanonicalName())
                || this.allowedClassNames.contains(candidate.getSimpleName()))
                && (ats.has(Workflow.class) || ats.has(Activities.class))
                && !Modifier.isAbstract(candidate.getModifiers())
                && !Modifier.isInterface(candidate.getModifiers()) && !candidate.isLocalClass()
                && !candidate.isAnonymousClass()) {
            if (ats.has(Workflow.class)) {
                this.workflowClasses.add(candidate);
                LOG.debug("Discovered workflow implementation class: " + candidate.getName());
            } else {
                this.activityClasses.add(candidate);
                LOG.debug("Discovered activity implementation class: " + candidate.getName());
            }
        }
    } catch (final ClassNotFoundException e) {
        LOG.debug(e, e);
    }
}

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

/**
 * @param superClass// w w w  . jav a2s .  c o m
 */
private void checkPropertiesForClass(Class<?> superClass) {
    getLog().debug("Check properties for class " + superClass.getName());
    // get all property descriptors
    PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(superClass);
    // for all properties, add it to component. If property have not abstract getter/setter ,
    // add it with exist = true . If property in list of hidden names, set hidden = true.
    PropertyBean property;
    for (int i = 0; i < properties.length; i++) {
        PropertyDescriptor descriptor = properties[i];
        if (!containProperty(descriptor.getName())) {
            if (isIgnorableProperty(superClass, descriptor.getName())) {
                continue;
            }
            Class<?> type = descriptor.getPropertyType();
            getLog().debug("Register property  " + descriptor.getName() + " with type name "
                    + type.getCanonicalName());
            property = new PropertyBean();
            property.setName(descriptor.getName());
            property.setDescription(descriptor.getShortDescription());
            property.setDisplayname(descriptor.getDisplayName());
            property.setClassname(descriptor.getPropertyType().getCanonicalName());
            property.setExist(true);
            addProperty(property);
        } else {
            // Load and check property.
            getLog().debug("Check  property  " + descriptor.getName());
            property = (PropertyBean) this.properties.get(descriptor.getName());
            if (property.getClassname() == null) {
                property.setClassname(descriptor.getPropertyType().getCanonicalName());
            } else {
                if (!property.getClassname().equals(descriptor.getPropertyType().getCanonicalName())) {
                    String message = "Class " + property.getClassname() + " for property " + property.getName()
                            + " not equals with real bean property type: "
                            + descriptor.getPropertyType().getCanonicalName();
                    getLog().error(message);
                    //throw new IllegalArgumentException(message);
                }
            }
            if (property.getDescription() == null) {
                property.setDescription(descriptor.getShortDescription());
            }
            if (property.getDisplayname() == null) {
                property.setDisplayname(descriptor.getDisplayName());
            }
            property.setExist(true);
        }
        Method getter = descriptor.getReadMethod();
        Method setter = descriptor.getWriteMethod();
        // Abstract methods
        if (null != setter && null != getter) {
            if ((Modifier.isAbstract(getter.getModifiers()) && Modifier.isAbstract(setter.getModifiers()))
                    || superClass.isInterface()) {
                getLog().debug("Detect as abstract property  " + descriptor.getName());
                property.setExist(false);
            }
        }

        if (null == setter || (!Modifier.isPublic(setter.getModifiers()))) {
            getLog().debug("Detect as hidden property  " + descriptor.getName());
            property.setHidden(true);
        }
        if (isAttachedProperty(property)) {
            property.setAttachedstate(true);
        }
        if (property.isInstanceof("javax.faces.el.MethodBinding")
                || property.isInstanceof("javax.faces.el.ValueBinding")) {
            property.setElonly(true);
        }

    }
}

From source file:com.visural.stereotyped.ui.service.StereotypeServiceImpl.java

@Cache
public List<Class> getStereotypes() {
    try {//  w  w  w.j a  v a  2  s  .c  o m
        List<Class> buildList = new ArrayList<Class>();
        // TODO: this shouldn't be hard-coded
        ClassFinder cf = new ClassFinder("", true);
        cf.addSuperClassFilter(Stereotype.class);
        Set<Class> results = cf.find();
        for (Class clazz : results) {
            // mustn't add abstract classes or stereotypes
            if (!Modifier.isAbstract(clazz.getModifiers())) {
                buildList.add(clazz);
            }
        }
        Collections.sort(buildList, new Comparator() {

            public int compare(Object o1, Object o2) {
                Class c1 = (Class) o1;
                Class c2 = (Class) o2;
                return c1.getName().compareTo(c2.getName());
            }
        });
        // overwrite top level list with new list
        return buildList;
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(PrototypeEditor.class.getName()).log(Level.SEVERE, null, ex);
        throw new IllegalStateException("Unable to load list of stereotypes.", ex);
    }
}