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:alluxio.cli.fs.FileSystemShellUtilsTest.java

@Test
public void loadCommands() {
    Map<String, Command> map = FileSystemShellUtils.loadCommands(mFileSystem);

    String pkgName = Command.class.getPackage().getName();
    Reflections reflections = new Reflections(pkgName);
    Set<Class<? extends Command>> cmdSet = reflections.getSubTypesOf(Command.class);
    for (Map.Entry<String, Command> entry : map.entrySet()) {
        Assert.assertEquals(entry.getValue().getCommandName(), entry.getKey());
        Assert.assertEquals(cmdSet.contains(entry.getValue().getClass()), true);
    }//from  ww  w.  ja va 2  s  . c o m

    int expectSize = 0;
    for (Class<? extends Command> cls : cmdSet) {
        if (cls.getPackage().getName().equals(FileSystemShell.class.getPackage().getName() + ".command")
                && !Modifier.isAbstract(cls.getModifiers())) {
            expectSize++;
        }
    }
    Assert.assertEquals(expectSize, map.size());
}

From source file:edu.cmu.tetradapp.util.TetradSerializableUtils.java

/**
 * Finds all classes inside the stated scope that implement
 * TetradSerializable and serializes them out to the getCurrentDirectory()
 * directory. Abstract methods and interfaces are skipped over. For all
 * other classes C, it is assumed that C has a static constructor of the
 * following form://w  ww  .  j a v  a2  s. com
 * <pre>
 *     public static C serializableInstance() {
 *         // Returns an instance of C. May be a mind-numbingly simple
 *         // instance, no need to get fancy.
 *     }
 * </pre>
 * The instance returned may be mind-numbingly simple; there is no need to
 * get fancy. It may change over time. The point is to make sure that
 * instances serialized out with earlier versions load with the
 * currentDirectory version.
 *
 * @throws RuntimeException if clazz cannot be serialized. This exception
 *                          has an informative message and wraps the
 *                          originally thrown exception as root cause.
 */
public void serializeCurrentDirectory() throws RuntimeException {
    clearCurrentDirectory();
    Map<String, List<String>> classFields = new TreeMap<String, List<String>>();

    // Get the classes that implement SerializationCanonicalizer.
    List classes = getAssignableClasses(new File(getSerializableScope()), TetradSerializable.class);

    System.out.println(
            "Serializing exemplars of instantiable TetradSerializable " + "in " + getSerializableScope() + ".");
    System.out.println("Writing serialized examplars to " + getCurrentDirectory());

    int index = -1;

    for (Object aClass : classes) {
        Class clazz = (Class) aClass;

        if (TetradSerializableExcluded.class.isAssignableFrom(clazz)) {
            continue;
        }

        if (Modifier.isAbstract(clazz.getModifiers())) {
            continue;
        }

        if (Modifier.isInterface(clazz.getModifiers())) {
            continue;
        }

        int numFields = getNumNonSerialVersionUIDFields(clazz);

        if (numFields > 0 && serializableInstanceMethod(clazz) == null) {
            throw new RuntimeException("Class " + clazz + " does not "
                    + "\nhave a public static serializableInstance constructor.");
        }

        if (++index % 50 == 0) {
            System.out.println(index);
        }

        System.out.print(".");

        serializeClass(clazz, classFields);
    }

    try {
        File file = new File(getCurrentDirectory(), "class_fields.ser");
        FileOutputStream out = new FileOutputStream(file);
        ObjectOutputStream objOut = new ObjectOutputStream(out);
        objOut.writeObject(classFields);
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("\nFinished serializing exemplars.");
}

From source file:xiaofei.library.hermes.util.TypeUtils.java

public static void validateClass(Class<?> clazz) {
    if (clazz == null) {
        throw new IllegalArgumentException("Class object is null.");
    }//from  w  w w  .  j  a v a 2 s.co m
    if (clazz.isPrimitive() || clazz.isInterface()) {
        return;
    }
    if (clazz.isAnnotationPresent(WithinProcess.class)) {
        throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName()
                + ". Class with a WithinProcess annotation presented on it cannot be accessed"
                + " from outside the process.");
    }

    if (clazz.isAnonymousClass()) {
        throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName()
                + ". Anonymous class cannot be accessed from outside the process.");
    }
    if (clazz.isLocalClass()) {
        throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName()
                + ". Local class cannot be accessed from outside the process.");
    }
    if (Context.class.isAssignableFrom(clazz)) {
        return;
    }
    if (Modifier.isAbstract(clazz.getModifiers())) {
        throw new IllegalArgumentException("Error occurs when registering class " + clazz.getName()
                + ". Abstract class cannot be accessed from outside the process.");
    }
}

From source file:org.kuali.rice.krad.bo.ModuleConfiguration.java

/**
 * @param externalizableBusinessObjectImplementations the externalizableBusinessObjectImplementations to set
 */// w  w  w .  j  a v  a  2  s. c o  m
public void setExternalizableBusinessObjectImplementations(
        Map<Class, Class> externalizableBusinessObjectImplementations) {
    if (externalizableBusinessObjectImplementations != null) {
        for (Class implClass : externalizableBusinessObjectImplementations.values()) {
            int implModifiers = implClass.getModifiers();
            if (Modifier.isInterface(implModifiers) || Modifier.isAbstract(implModifiers)) {
                throw new RuntimeException("Externalizable business object implementation class "
                        + implClass.getName() + " must be a non-interface, non-abstract class");
            }
        }
    }
    this.externalizableBusinessObjectImplementations = externalizableBusinessObjectImplementations;
}

From source file:com.github.cherimojava.data.mongo.entity.EntityFactory.java

/**
 * Sets a default class for a given Interface, which will be used if a Add method is invoked but no underlying
 * object is existing yet. Supplied class must provide a parameterless public constructor and must be not abstract
 *
 * @param interfaze on for which the given implementation will be invoked
 * @param implementation concrete implementation of the given interface of which a new instance might be created
 *            must have a empty constructor and can't be abstract
 * @param <T>//from   www. ja v  a  2s.  c  om
 */
public static <T> void setDefaultClass(Class<T> interfaze, Class<? extends T> implementation) {
    checkArgument(interfaze.isInterface(), "Can set default Classes only for interfaces");
    checkArgument(!implementation.isInterface(), "Default class can't be an interface itself");
    checkArgument(!Modifier.isAbstract(implementation.getModifiers()), "Implementation can't be abstract");
    try {
        implementation.getConstructor();
    } catch (NoSuchMethodException e) {
        throw new IllegalArgumentException(
                "Supplied implementation does not provide a parameterless constructor.");
    }
    interfaceImpls.put(interfaze, implementation);
}

From source file:org.web4thejob.orm.EntityMetadataImpl.java

@Override
public boolean isAbstract() {
    return Modifier.isAbstract(classMetadata.getMappedClass().getModifiers());
}

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

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

    Set<String> jobActionsClasses = new HashSet<String>();
    try {//w  w  w .j  av a2  s . c  o  m
        for (Resource resource : resResolver.getResources("classpath*:**/*.class")) {

            ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource)
                    .getClassMetadata();
            if (ArrayUtils.contains(metadata.getInterfaceNames(), SyncJobActions.class.getName())) {

                try {
                    Class jobClass = Class.forName(metadata.getClassName());
                    if (!Modifier.isAbstract(jobClass.getModifiers())) {
                        jobActionsClasses.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 {}", SyncJobActions.class.getName(), e);
    }

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

From source file:com.unovo.frame.utils.SharedPreferencesHelper.java

private static boolean isContSupport(Field field) {
    return (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())
            || Modifier.isAbstract(field.getModifiers()));
}

From source file:com.thoughtworks.go.server.service.MagicalMaterialAndMaterialConfigConversionTest.java

private boolean isNotAConcrete_NonTest_MaterialConfigImplementation(Class aClass) {
    return Pattern.matches(".*(Test|Dummy).*", aClass.toString()) || Modifier.isAbstract(aClass.getModifiers());
}