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.
 *//* w  ww.  j a  v a 2 s. c  o m*/
protected Class toProxyableMapType(Class type) {
    if (type.getName().endsWith(PROXY_SUFFIX))
        type = type.getSuperclass();
    else if (type.isInterface()) {
        type = toConcreteType(type, _stdMaps);
        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:com.judoscript.jamaica.parser.JamaicaDumpVisitor.java

static void printAccessFlags(int flags) {
    if (Modifier.isPublic(flags))
        out.print("public ");
    else if (Modifier.isProtected(flags))
        out.print("protected ");
    else if (Modifier.isPrivate(flags))
        out.print("private ");

    if (Modifier.isAbstract(flags))
        out.print("abstract ");
    if (Modifier.isFinal(flags))
        out.print("final ");
    if (Modifier.isNative(flags))
        out.print("native ");
    if (Modifier.isStatic(flags))
        out.print("static ");
    if (Modifier.isStrict(flags))
        out.print("strict ");
    if (Modifier.isSynchronized(flags))
        out.print("synchronized ");
    if (Modifier.isTransient(flags))
        out.print("transient ");
    if (Modifier.isVolatile(flags))
        out.print("volative ");
}

From source file:org.gridgain.grid.spi.deployment.uri.GridUriDeploymentFileProcessor.java

/**
 * Check that class may be instantiated as {@link GridComputeTask} and used
 * in deployment./* w w  w  . java2s .  c o m*/
 *
 * Loaded task class must implement interface {@link GridComputeTask}.
 * Only non-abstract, non-interfaces and public classes allowed.
 * Inner static classes also allowed for loading.
 *
 * @param cls Class to check
 * @return {@code true} if class allowed for deployment.
 */
private static boolean isAllowedTaskClass(Class<?> cls) {
    if (!GridComputeTask.class.isAssignableFrom(cls))
        return false;

    int modifiers = cls.getModifiers();

    return !Modifier.isAbstract(modifiers) && !Modifier.isInterface(modifiers)
            && (!cls.isMemberClass() || Modifier.isStatic(modifiers)) && Modifier.isPublic(modifiers);
}

From source file:cat.albirar.framework.dynabean.impl.DynaBeanDescriptor.java

/**
 * Process the annotations for the property.
 * /*from w  w w .j a v  a  2 s  . c  o m*/
 * @param propDesc The property
 */
private void processAnnotations(DynaBeanPropertyDescriptor propDesc) {
    PropertyDefaultValue pdv;
    DynaBean db;
    String msg;

    // Check for dynabean annotation at property or property type
    if (((db = getAnnotationForProperty(propDesc, DynaBean.class)) != null)
            || ((db = getAnnotationForPropertyType(propDesc, DynaBean.class)) != null)) {
        Assert.isTrue(propDesc.getPropertyType().isInterface(),
                "The property '" + propDesc.getPropertyName() + "' of type '" + implementedType.getName()
                        + " is using DynaBean annotation incorrectly. " + "Only interfaces can be DynaBean");
        // Check for DynaBean conditions
        propDesc.dynaBean = true;
        propDesc.defaultValue = new String[] { Boolean.toString(db.defaultInstantiate()) };
    } else {
        // Not a dynabean, check for PropertyDefaultValue
        if ((pdv = getAnnotationForProperty(propDesc, PropertyDefaultValue.class)) != null) {
            // Implementation was indicated?
            if (!void.class.equals(pdv.implementation())) {
                // Implementation and no default
                // The implementation is an interface (dynabean)?
                if (pdv.implementation().isInterface()
                        || Modifier.isAbstract(pdv.implementation().getModifiers())) {
                    msg = "The implementation type (" + pdv.implementation().getName() + ") for the property '"
                            + propDesc.getPropertyName() + "' isn't a concrete and instantiable class!";

                    logger.error(msg);
                    throw new IllegalArgumentException(msg);
                } else {
                    // Concrete class implementation!
                    propDesc.defaultImplementation = pdv.implementation();
                }
            } else {
                // No implementation, value was indicated?
                if (!StringUtilities.hasText(pdv.value())) {
                    // No implementation && no value, no default implementation
                    msg = "The property '".concat(propDesc.getPropertyName())
                            .concat("' was annotated with DefaultPropertyValue but "
                                    + "no value and no default implementation was indicated. Cannot be marked as 'default'");
                    logger.error(msg);
                    throw new IllegalArgumentException(msg);
                } else {
                    propDesc.defaultValue = pdv.value();
                    if (StringUtilities.hasText(pdv.pattern())) {
                        // Test if a date or calendar...
                        if (Date.class.isAssignableFrom(propDesc.getPropertyType())
                                || Calendar.class.isAssignableFrom(propDesc.getPropertyType())) {
                            // dates
                            propDesc.propertyItemEditor = new DynaBeanDateEditor(pdv.pattern()[0],
                                    Calendar.class.isAssignableFrom(propDesc.getPropertyType()));
                            getFactory().getPropertyEditorRegistry().registerCustomEditor(
                                    propDesc.getPropertyType(), propDesc.getPropertyPath(),
                                    propDesc.propertyItemEditor);
                        } else {
                            msg = String.format(
                                    "On processing '%s' property of '%s' type. The pattern property of annotation is only applicable to Date or Calendar types!",
                                    propDesc.getPropertyName(), implementedType.getName());

                            logger.error(msg);
                            throw new IllegalArgumentException(msg);
                        }
                    }
                }
            }
        } else {
            propDesc.defaultValue = null;
        }
    }
}

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

/**
 * {@inheritDoc} Return an instance of the specified type allowing access to provider-specific APIs. If the Bean
 * Validation provider implementation does not support the specified class, <code>ValidationException</code> is
 * thrown.// www  .  ja  va 2s . c  om
 *
 * @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.
 */
// @Override - not allowed in 1.5 for Interface methods
public <T> T unwrap(Class<T> type) {
    // 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.isAssignableFrom(getClass())) {
        @SuppressWarnings("unchecked")
        final T result = (T) this;
        return result;
    }
    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")
            final Class<? extends T> implClass = (Class<? extends T>) cls;
            return newInstance(implClass);
        }
    } catch (ClassNotFoundException e) {
    }
    throw new ValidationException("Type " + type + " not supported");
}

From source file:com.github.larsq.spring.embeddedamqp.SimpleAmqpMessageContainer.java

/**
 * Find set of abstract exchange routers by traversing a comprising class.
 * This method is invoked to discover available router types.
 *
 * @return/*  ww  w.j  a va 2  s . c  om*/
 */
Set<AbstractExchangeRouter> findRouters() {
    ClassStructureWalker walker = new ClassStructureWalker(Routers.class, false, true);
    Iterable<Class<?>> innerClasses = walker
            .traverseClassStructure(clz -> Sets.newHashSet(clz.getDeclaredClasses()));

    return StreamSupport.stream(innerClasses.spliterator(), false)
            .filter(AbstractExchangeRouter.class::isAssignableFrom)
            .filter(clz -> !Modifier.isAbstract(clz.getModifiers()))
            .map(clz -> (AbstractExchangeRouter) invokeInnerClassConstructor(clz)).collect(Collectors.toSet());
}

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

public boolean isSuperIsTransientMethodExists() {
    try {/*from  w  ww.  ja va  2  s.c om*/
        Class superClass = getLoader().loadClass(getSuperclass());
        Class[] signature = new Class[0];
        try {
            Method m = superClass.getMethod("isTransient", 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.nuunframework.cli.NuunCliPlugin.java

protected Specification<Class<?>> classIsAbstract() {
    return new AbstractSpecification<Class<?>>() {
        @Override/*from  ww  w.j a  va2s  . co  m*/
        public boolean isSatisfiedBy(Class<?> candidate) {

            return candidate != null && Modifier.isAbstract(candidate.getModifiers());
        }
    };
}

From source file:org.apache.ignite.spi.deployment.uri.GridUriDeploymentFileProcessor.java

/**
 * Check that class may be instantiated as {@link org.apache.ignite.compute.ComputeTask} and used
 * in deployment.// ww  w  .jav a  2 s.c  o m
 *
 * Loaded task class must implement interface {@link org.apache.ignite.compute.ComputeTask}.
 * Only non-abstract, non-interfaces and public classes allowed.
 * Inner static classes also allowed for loading.
 *
 * @param cls Class to check
 * @return {@code true} if class allowed for deployment.
 */
private static boolean isAllowedTaskClass(Class<?> cls) {
    if (!ComputeTask.class.isAssignableFrom(cls))
        return false;

    int modifiers = cls.getModifiers();

    return !Modifier.isAbstract(modifiers) && !Modifier.isInterface(modifiers)
            && (!cls.isMemberClass() || Modifier.isStatic(modifiers)) && Modifier.isPublic(modifiers);
}

From source file:org.guicerecipes.spring.support.AutowiredMemberProvider.java

/**
 * Returns a new instance of the given class if its a public non abstract class which has a public zero argument constructor otherwise returns null
 *//*w ww .j  a  v  a 2 s.  c  o  m*/
protected Object tryCreateInstance(Class<?> type) {
    Object answer = null;
    int modifiers = type.getModifiers();
    if (!Modifier.isAbstract(modifiers) && Modifier.isPublic(modifiers) && !type.isInterface()) {
        // if its a concrete class with no args make one
        Constructor<?> constructor = null;
        try {
            constructor = type.getConstructor();
        } catch (NoSuchMethodException e) {
            // ignore
        }
        if (constructor != null) {
            if (Modifier.isPublic(constructor.getModifiers())) {
                try {
                    answer = constructor.newInstance();
                } catch (InstantiationException e) {
                    throw new ProvisionException("Failed to instantiate " + constructor, e);
                } catch (IllegalAccessException e) {
                    throw new ProvisionException("Failed to instantiate " + constructor, e);
                } catch (InvocationTargetException ie) {
                    Throwable e = ie.getTargetException();
                    throw new ProvisionException("Failed to instantiate " + constructor, e);
                }
            }
        }
    }
    return answer;
}