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.geode.internal.DeployedJar.java

/**
 * Check to see if the class implements the Function interface. If so, it will be registered with
 * FunctionService. Also, if the functions's class was originally declared in a cache.xml file
 * then any properties specified at that time will be reused when re-registering the function.
 *
 * @param clazz Class to check for implementation of the Function class
 * @return A collection of Objects that implement the Function interface.
 *///  www  .j a va2s  . com
private Collection<Function> getRegisterableFunctionsFromClass(Class<?> clazz) {
    final List<Function> registerableFunctions = new ArrayList<>();

    try {
        if (Function.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
            boolean registerUninitializedFunction = true;
            if (Declarable.class.isAssignableFrom(clazz)) {
                try {
                    final List<Properties> propertiesList = ((InternalCache) CacheFactory.getAnyInstance())
                            .getDeclarableProperties(clazz.getName());

                    if (!propertiesList.isEmpty()) {
                        registerUninitializedFunction = false;
                        // It's possible that the same function was declared multiple times in cache.xml
                        // with different properties. So, register the function using each set of
                        // properties.
                        for (Properties properties : propertiesList) {
                            @SuppressWarnings("unchecked")
                            Function function = newFunction((Class<Function>) clazz, true);
                            if (function != null) {
                                ((Declarable) function).init(properties);
                                if (function.getId() != null) {
                                    registerableFunctions.add(function);
                                }
                            }
                        }
                    }
                } catch (CacheClosedException ignored) {
                    // That's okay, it just means there were no properties to init the function with
                }
            }

            if (registerUninitializedFunction) {
                @SuppressWarnings("unchecked")
                Function function = newFunction((Class<Function>) clazz, false);
                if (function != null && function.getId() != null) {
                    registerableFunctions.add(function);
                }
            }
        }
    } catch (Exception ex) {
        logger.error("Attempting to register function from JAR file: {}", this.file.getAbsolutePath(), ex);
    }

    return registerableFunctions;
}

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

@Cache
public List<Class<? extends Component>> getComponents() {
    try {/*from  www.  java2  s .com*/
        Thread.currentThread().setContextClassLoader(getApplicationClassLoader());
        List<Class<? extends Component>> buildList = new ArrayList<Class<? extends Component>>();
        // TODO: this shouldn't be hard-coded
        ClassFinder cf = new ClassFinder("", true);
        cf.addSuperClassFilter(Component.class);
        Set<Class> results = cf.find();
        for (Class clazz : results) {
            // mustn't add abstract classes or stereotypes
            if (!Modifier.isAbstract(clazz.getModifiers()) && !PublishedComponent.class.isAssignableFrom(clazz)
                    && !Stereotype.class.isAssignableFrom(clazz)) {
                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());
            }
        });
        return buildList;
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(PrototypeEditor.class.getName()).log(Level.SEVERE, null, ex);
        throw new IllegalStateException("Unable to load list of components.", ex);
    }
}

From source file:com.github.geequery.codegen.ast.JavaUnit.java

public boolean isAbstract() {
    return Modifier.isAbstract(modifiers);
}

From source file:net.servicefixture.util.ReflectionUtils.java

private static boolean isConcreteSubclass(Class<?> baseClass, Class<?> clazz) {
    return baseClass.isAssignableFrom(clazz) && !baseClass.equals(clazz) && !clazz.isInterface()
            && !Modifier.isAbstract(clazz.getModifiers());
}

From source file:org.enhydra.shark.asap.util.BeanSerializerShark.java

/**
 * Return XML schema for the specified type, suitable for insertion into
 * the &lt;types&gt; element of a WSDL document, or underneath an
 * &lt;element&gt; or &lt;attribute&gt; declaration.
 *
 * @param javaType the Java Class we're writing out schema for
 * @param types the Java2WSDL Types object which holds the context
 *              for the WSDL being generated.
 * @return a type element containing a schema simpleType/complexType
 * @see org.apache.axis.wsdl.fromJava.Types
 *///from   w  ww  . ja v  a2s .  c om
public Element writeSchema(Class javaType, Types types) throws Exception {

    // ComplexType representation of bean class
    Element complexType = types.createElement("complexType");

    // See if there is a super class, stop if we hit a stop class
    Element e = null;
    Class superClass = javaType.getSuperclass();
    BeanPropertyDescriptor[] superPd = null;
    List stopClasses = types.getStopClasses();
    if (superClass != null && superClass != java.lang.Object.class && superClass != java.lang.Exception.class
            && superClass != java.lang.Throwable.class && superClass != java.rmi.RemoteException.class
            && superClass != org.apache.axis.AxisFault.class
            && (stopClasses == null || !(stopClasses.contains(superClass.getName())))) {
        // Write out the super class
        String base = types.writeType(superClass);
        Element complexContent = types.createElement("complexContent");
        complexType.appendChild(complexContent);
        Element extension = types.createElement("extension");
        complexContent.appendChild(extension);
        extension.setAttribute("base", base);
        e = extension;
        // Get the property descriptors for the super class
        TypeDesc superTypeDesc = TypeDesc.getTypeDescForClass(superClass);
        if (superTypeDesc != null) {
            superPd = superTypeDesc.getPropertyDescriptors();
        } else {
            superPd = BeanUtils.getPd(superClass, null);
        }
    } else {
        e = complexType;
    }

    // Add fields under sequence element.
    // Note: In most situations it would be okay
    // to put the fields under an all element.
    // However it is illegal schema to put an
    // element with minOccurs=0 or maxOccurs>1 underneath
    // an all element.  This is the reason why a sequence
    // element is used.
    Element all = types.createElement("sequence");
    e.appendChild(all);

    if (Modifier.isAbstract(javaType.getModifiers())) {
        complexType.setAttribute("abstract", "true");
    }

    // Serialize each property
    for (int i = 0; i < propertyDescriptor.length; i++) {
        String propName = propertyDescriptor[i].getName();

        // Don't serializer properties named class
        boolean writeProperty = true;
        if (propName.equals("class")) {
            writeProperty = false;
        }

        // Don't serialize the property if it is present
        // in the super class property list
        if (superPd != null && writeProperty) {
            for (int j = 0; j < superPd.length && writeProperty; j++) {
                if (propName.equals(superPd[j].getName())) {
                    writeProperty = false;
                }
            }
        }
        if (!writeProperty) {
            continue;
        }

        // If we have type metadata, check to see what we're doing
        // with this field.  If it's an attribute, skip it.  If it's
        // an element, use whatever qname is in there.  If we can't
        // find any of this info, use the default.

        if (typeDesc != null) {
            Class fieldType = propertyDescriptor[i].getType();
            FieldDesc field = typeDesc.getFieldByName(propName);

            if (field != null) {
                QName qname = field.getXmlName();
                QName fieldXmlType = field.getXmlType();
                boolean isAnonymous = fieldXmlType != null && fieldXmlType.getLocalPart().startsWith(">");

                if (qname != null) {
                    // FIXME!
                    // Check to see if this is in the right namespace -
                    // if it's not, we need to use an <element ref="">
                    // to represent it!!!

                    // Use the default...
                    propName = qname.getLocalPart();
                }
                if (!field.isElement()) {
                    writeAttribute(types, propName, fieldType, fieldXmlType, complexType);
                } else {
                    writeField(types, propName, fieldXmlType, fieldType, propertyDescriptor[i].isIndexed(),
                            field.isMinOccursZero(), all, isAnonymous);
                }
            } else {
                writeField(types, propName, null, fieldType, propertyDescriptor[i].isIndexed(), false, all,
                        false);
            }
        } else {
            boolean done = false;
            if (propertyDescriptor[i] instanceof FieldPropertyDescriptor) {
                FieldPropertyDescriptor fpd = (FieldPropertyDescriptor) propertyDescriptor[i];
                Class clazz = fpd.getField().getType();
                if (types.getTypeQName(clazz) != null) {
                    writeField(types, propName, null, clazz, false, false, all, false);

                    done = true;
                }
            }
            if (!done) {
                writeField(types, propName, null, propertyDescriptor[i].getType(),
                        propertyDescriptor[i].isIndexed(), false, all, false);
            }

        }
    }

    // done
    return complexType;
}

From source file:net.servicefixture.util.ReflectionUtils.java

public static boolean isAbstractType(Class type) {
    return (type.isInterface() || Modifier.isAbstract(type.getModifiers())) && !type.isPrimitive();
}

From source file:org.zanata.seam.SeamAutowire.java

private <T> Class<T> getImplClass(Class<T> fieldClass) {
    // If the bean type is an interface, try to find a declared
    // implementation
    // TODO field class might a concrete superclass
    // of the impl class
    if (Modifier.isAbstract(fieldClass.getModifiers()) && this.beanImpls.containsKey(fieldClass)) {
        fieldClass = (Class<T>) this.beanImpls.get(fieldClass);
    }//from   ww  w. ja  v  a  2s  .co m

    return (Class<T>) fieldClass;
}

From source file:org.apache.bval.jsr.ApacheValidatorFactory.java

/**
 * Return an object of the specified type to allow access to the
 * provider-specific API. If the Bean Validation provider implementation
 * does not support the specified class, the ValidationException is thrown.
 *
 * @param type the class of the object to be returned.
 * @return an instance of the specified class
 * @throws ValidationException if the provider does not support the call.
 *//*w  w  w  .j a  v a 2s .co m*/
public <T> T unwrap(final Class<T> type) {
    if (type.isInstance(this)) {
        @SuppressWarnings("unchecked")
        final T result = (T) this;
        return result;
    }

    // FIXME 2011-03-27 jw:
    // This code is unsecure.
    // It should allow only a fixed set of classes.
    // Can't fix this because don't know which classes this method should support.

    if (!(type.isInterface() || Modifier.isAbstract(type.getModifiers()))) {
        return newInstance(type);
    }
    try {
        final Class<?> cls = ClassUtils.getClass(type.getName() + "Impl");
        if (type.isAssignableFrom(cls)) {
            @SuppressWarnings("unchecked")
            T result = (T) newInstance(cls);
            return result;
        }
    } catch (ClassNotFoundException e) {
        // do nothing
    }
    throw new ValidationException("Type " + type + " not supported");
}

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

public boolean isSuperSaveStateMethodExists() {
    try {//from   www .j a  v a  2 s  .  c o  m
        Class superClass = getLoader().loadClass(getSuperclass());
        Class[] signature = { FacesContext.class };
        try {
            Method m = superClass.getMethod("saveState", 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:com.mylife.hbase.mapper.HBaseEntityMapper.java

/**
 * Constructor: Sets up hTablePool and scans base package paths looking for classes annotated with @HBasePersistance
 * //from w ww .  j  av a 2 s  .co  m
 * @param hTablePool
 * @param basePackages
 */
@SuppressWarnings("unchecked")
public HBaseEntityMapper(HTablePool hTablePool, String... basePackages) {

    final HBaseAdmin hBaseAdmin;
    try {
        hBaseAdmin = new HBaseAdmin((Configuration) Whitebox.getInternalState(hTablePool, "config"));
    } catch (IOException e) {
        LOG.fatal("Could not connect to HBase failing HBase object mapping!", e);
        this.hTablePool = null;
        this.annotatedClassToAnnotatedHBaseRowKey = null;
        this.annotatedClassToAnnotatedFieldMappingWithCorrespondingGetterMethod = null;
        this.annotatedClassToAnnotatedObjectFieldMappingWithCorrespondingGetterMethod = null;
        this.annotatedClassToAnnotatedMapFieldMappingWithCorrespondingGetterMethod = null;
        return;
    }

    this.hTablePool = hTablePool;

    final Map<Class<?>, AccessibleObject> annotatedClassToAnnotatedHBaseRowKeyMap = new HashMap<Class<?>, AccessibleObject>();

    final Map<Class<?>, ImmutableMap<Field, Method>> annotatedClassToAnnotatedFieldMappingWithCorrespondingGetterMethodMap = new HashMap<Class<?>, ImmutableMap<Field, Method>>();

    final Map<Class<?>, ImmutableMap<Field, Method>> annotatedClassToAnnotatedObjectFieldMappingWithCorrespondingGetterMethodMap = new HashMap<Class<?>, ImmutableMap<Field, Method>>();

    final Map<Class<?>, ImmutableMap<Field, Method>> annotatedClassToAnnotatedMapFieldMappingWithCorrespondingGetterMethodMap = new HashMap<Class<?>, ImmutableMap<Field, Method>>();

    /*
     * Only include classes annotated with @HBasePersistance
     */
    scanner.addIncludeFilter(new AnnotationTypeFilter(HBasePersistance.class));

    for (final String basePackage : basePackages) {

        for (final BeanDefinition beanDefinition : scanner.findCandidateComponents(basePackage)) {
            final Class<?> annotatedClass;
            try {
                annotatedClass = Class.forName(beanDefinition.getBeanClassName());
            } catch (ClassNotFoundException e) {
                // should never happen
                LOG.error("ClassNotFoundException while loading class for HBase entity mapper", e);
                throw new RuntimeException(e);
            }
            /*
             * Get the hbase table name - required!
             */
            final String tableName = annotatedClass.getAnnotation(HBasePersistance.class).tableName();
            if (StringUtils.isEmpty(tableName)) {
                LOG.error("@HBasePersistance must have a non-empty tableName. Ignoring: " + annotatedClass);
                continue;
            }

            try {
                if (!hBaseAdmin.tableExists(tableName)) {
                    LOG.error("table " + tableName
                            + " in @HBasePersistance.tableName() does not exist. Ignoring: " + annotatedClass);
                    continue;
                }
            } catch (IOException e) {
                LOG.error("Could not verify table " + tableName
                        + "in @HBasePersistance.tableName() exists. Ignoring: " + annotatedClass, e);
                continue;
            }

            /*
             * Get the default hbase column family name. This will be used as default column family where fields are
             * mapped to but not required if all annotated fields specifically mention the column family they belong
             * to.
             * 
             * TODO: Current implementation makes this field required but it really isn't based on my
             * comment made previously. That is, if all annotated fields specifically mention the column family
             * where they will be found then a default column family name is unneeded.
             */
            final String defaultColumnFamilyName = annotatedClass.getAnnotation(HBasePersistance.class)
                    .defaultColumnFamilyName();
            if (StringUtils.isEmpty(defaultColumnFamilyName)) {
                LOG.error("@HBasePersistance must have a non-empty defaultColumnFamilyName. Ignoring: "
                        + annotatedClass);
                continue;
            }

            try {
                /*
                 * Confirm the hbase table and column family exists
                 */
                if (!hBaseAdmin.getTableDescriptor(Bytes.toBytes(tableName))
                        .hasFamily(Bytes.toBytes(defaultColumnFamilyName))) {
                    LOG.error("defaultColumnFamilyName (" + defaultColumnFamilyName + ") in " + tableName
                            + "in @HBasePersistance.defaultColumnFamilyName() does not exist. Ignoring: "
                            + annotatedClass);
                    continue;
                }
            } catch (IOException e) {
                LOG.error("Could not verify defaultColumnFamilyName (" + defaultColumnFamilyName + ") in "
                        + tableName + "in @HBasePersistance.defaultColumnFamilyName() exists. Ignoring: "
                        + annotatedClass, e);
                continue;
            }

            /*
             * @HBaseField : Find fields with this annotation and their corresponding getter method
             */
            Set<Field> hBaseFieldAnnotatedFieldsSet = Whitebox
                    .getFieldsAnnotatedWith(Whitebox.newInstance(annotatedClass), HBaseField.class);

            /*
             * Use a Predicate to look through all @HBaseField annotated fields and skip whole class if even one
             * field is not supported
             */
            if (CollectionUtils.exists(hBaseFieldAnnotatedFieldsSet,
                    new org.apache.commons.collections.Predicate() {

                        @Override
                        public boolean evaluate(Object object) {

                            return !TypeHandler.supports(((Field) object).getType());
                        }
                    })) {
                LOG.error("Unsupported type annotated with @HBaseField. Ignoring: " + annotatedClass);
                continue;
            }

            annotatedClassToAnnotatedFieldMappingWithCorrespondingGetterMethodMap.put(annotatedClass,
                    fieldsToGetterMap(annotatedClass, ImmutableSet.copyOf(hBaseFieldAnnotatedFieldsSet)));

            /*
             * @HBaseObjectField : Find all fields with this annotation and their corresponding getter method
             */
            annotatedClassToAnnotatedObjectFieldMappingWithCorrespondingGetterMethodMap.put(annotatedClass,
                    fieldsToGetterMap(annotatedClass, ImmutableSet.copyOf(Whitebox.getFieldsAnnotatedWith(
                            Whitebox.newInstance(annotatedClass), HBaseObjectField.class))));

            /*
             * @HBaseMapField : See if this annotation exists and if so, make sure there is only one
             */
            final Set<Field> hBaseMapFieldAnnotatedFieldsSet = Whitebox
                    .getFieldsAnnotatedWith(Whitebox.newInstance(annotatedClass), HBaseMapField.class);

            if (hBaseMapFieldAnnotatedFieldsSet.size() > 1) {
                LOG.error(
                        "@HBaseMapField can only be used on one field per class. Ignoring: " + annotatedClass);
                continue;
            }
            final Iterator<Field> hBaseMapFieldsIterator = hBaseMapFieldAnnotatedFieldsSet.iterator();
            if (hBaseMapFieldsIterator.hasNext()) {
                final Field field = hBaseMapFieldsIterator.next();
                final Type[] types = TypeHandler.getGenericTypesFromField(field);

                if ((Modifier.isAbstract(field.getType().getModifiers()) && !Map.class.equals(field.getType()))
                        || !Map.class.isAssignableFrom(field.getType())
                        || !String.class.equals((Class<?>) types[0])
                        || !String.class.equals((Class<?>) types[1])) {
                    LOG.error(
                            "@HBaseMapField must be used on a field of type java.util.Map<String, String> OR a concrete fields assignable from java.util.Map<String, String> . Ignoring: "
                                    + annotatedClass);
                    continue;
                }
                annotatedClassToAnnotatedMapFieldMappingWithCorrespondingGetterMethodMap.put(annotatedClass,
                        fieldsToGetterMap(annotatedClass,
                                ImmutableSet.copyOf(hBaseMapFieldAnnotatedFieldsSet)));

            }

            /*
             * Figure out which method or field to use as the HBaseRowKey this has to be at the end since
             * 
             * @HBaseRowKey is required in the class we can use this to key the other maps we are collecting
             */
            final Set<Field> hBaseRowKeyFields = Whitebox
                    .getFieldsAnnotatedWith(Whitebox.newInstance(annotatedClass), HBaseRowKey.class);
            if (hBaseRowKeyFields.size() > 1) {
                LOG.error("@HBaseRowKey can only be used once per class. Ignoring: " + annotatedClass);
                continue;
            }
            final Collection<Method> hBaseRowKeyMethods = Collections2.filter(
                    Arrays.asList(ReflectionUtils.getAllDeclaredMethods(annotatedClass)),
                    new Predicate<Method>() {

                        @Override
                        public boolean apply(final Method method) {
                            return method.getAnnotation(HBaseRowKey.class) != null;
                        }
                    });
            if (hBaseRowKeyFields.size() + hBaseRowKeyMethods.size() > 1) {
                LOG.error("@HBaseRowKey can only be used once per class. Ignoring: " + annotatedClass);
                continue;
            }

            if (hBaseRowKeyFields.size() + hBaseRowKeyMethods.size() == 0) {
                LOG.error("@HBaseRowKey is required. Ignoring: " + annotatedClass);
                continue;
            }

            if (hBaseRowKeyFields.isEmpty()) {
                final Method hBaseRowKeyMethod = hBaseRowKeyMethods.iterator().next();
                if (hBaseRowKeyMethod.getParameterTypes().length > 0) {
                    LOG.error("@HBaseRowKey can only be used on a no arguemnt method. Ignoring: "
                            + annotatedClass);
                    continue;
                }
                annotatedClassToAnnotatedHBaseRowKeyMap.put(annotatedClass, hBaseRowKeyMethod);
            } else {
                annotatedClassToAnnotatedHBaseRowKeyMap.put(annotatedClass,
                        hBaseRowKeyFields.iterator().next());
            }
        }
    }

    /*
     * keep only the valid classed in our maps
     */
    annotatedClassToAnnotatedFieldMappingWithCorrespondingGetterMethodMap.keySet()
            .retainAll(annotatedClassToAnnotatedHBaseRowKeyMap.keySet());
    annotatedClassToAnnotatedObjectFieldMappingWithCorrespondingGetterMethodMap.keySet()
            .retainAll(annotatedClassToAnnotatedHBaseRowKeyMap.keySet());
    annotatedClassToAnnotatedMapFieldMappingWithCorrespondingGetterMethodMap.keySet()
            .retainAll(annotatedClassToAnnotatedHBaseRowKeyMap.keySet());

    // set our state
    this.annotatedClassToAnnotatedHBaseRowKey = ImmutableMap.copyOf(annotatedClassToAnnotatedHBaseRowKeyMap);
    this.annotatedClassToAnnotatedFieldMappingWithCorrespondingGetterMethod = ImmutableMap
            .copyOf(annotatedClassToAnnotatedFieldMappingWithCorrespondingGetterMethodMap);
    this.annotatedClassToAnnotatedObjectFieldMappingWithCorrespondingGetterMethod = ImmutableMap
            .copyOf(annotatedClassToAnnotatedObjectFieldMappingWithCorrespondingGetterMethodMap);
    this.annotatedClassToAnnotatedMapFieldMappingWithCorrespondingGetterMethod = ImmutableMap
            .copyOf(annotatedClassToAnnotatedMapFieldMappingWithCorrespondingGetterMethodMap);
}