List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:org.structr.module.JarConfigurationProvider.java
private void importResource(Module module) throws IOException { final Set<String> classes = module.getClasses(); for (final String name : classes) { String className = StringUtils.removeStart(name, "."); logger.log(Level.FINE, "Instantiating class {0} ", className); try {//from ww w .j a v a2s . c o m // instantiate class.. Class clazz = Class.forName(className); int modifiers = clazz.getModifiers(); logger.log(Level.FINE, "Class {0} instantiated: {1}", new Object[] { className, clazz }); // register node entity classes if (NodeInterface.class.isAssignableFrom(clazz)) { registerEntityType(clazz); } // register entity classes if (AbstractRelationship.class.isAssignableFrom(clazz) && !(Modifier.isAbstract(modifiers))) { registerEntityType(clazz); } // register services if (Service.class.isAssignableFrom(clazz) && !(Modifier.isAbstract(modifiers))) { Services.getInstance().registerServiceClass(clazz); } // register agents if (Agent.class.isAssignableFrom(clazz) && !(Modifier.isAbstract(modifiers))) { String simpleName = clazz.getSimpleName(); String fullName = clazz.getName(); agentClassCache.put(simpleName, clazz); agentPackages.add(fullName.substring(0, fullName.lastIndexOf("."))); } } catch (Throwable t) { } } }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadRESTHandlers() throws ThinklabException { String ipack = this.getClass().getPackage().getName() + ".rest"; for (Class<?> cls : MiscUtilities.findSubclasses(IRESTHandler.class, ipack, getClassLoader())) { /*//from w ww . ja va 2 s . c o m * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof RESTResourceHandler) { String path = ((RESTResourceHandler) annotation).path(); String description = ((RESTResourceHandler) annotation).description(); RESTManager.get().registerService(path, (Class<?>) cls); break; } } } }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadTransformations() throws ThinklabException { String ipack = this.getClass().getPackage().getName() + ".transformations"; for (Class<?> cls : MiscUtilities.findSubclasses(ITransformation.class, ipack, getClassLoader())) { /*/*from w w w .j ava 2 s . c o m*/ * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof DataTransformation) { String name = ((DataTransformation) annotation).id(); try { TransformationFactory.get().registerTransformation(name, (ITransformation) cls.newInstance()); } catch (Exception e) { throw new ThinklabValidationException(e); } break; } } } }
From source file:net.firejack.platform.model.service.reverse.ReverseEngineeringService.java
private EntityModel createBeanEntity(Class clazz, RegistryNodeModel registryNodeModel, List<RelationshipModel> relationships, Map<String, EntityModel> models) { if (clazz == Object.class) return null; EntityModel model = models.get(clazz.getName()); if (model != null) return model; String name = clazz.getSimpleName().replaceAll("\\B([A-Z]+)\\B", " $1"); EntityModel entityModel;/*from w ww. j a va 2 s .c o m*/ if (clazz.isMemberClass()) { entityModel = new SubEntityModel(); name = "Nested " + name; registryNodeModel = models.get(clazz.getEnclosingClass().getName()); } else { entityModel = new EntityModel(); } models.put(clazz.getName(), entityModel); entityModel.setName(name); entityModel.setLookup(DiffUtils.lookup(registryNodeModel.getLookup(), name)); entityModel.setPath(registryNodeModel.getLookup()); entityModel.setAbstractEntity(Modifier.isAbstract(clazz.getModifiers())); entityModel.setTypeEntity(true); entityModel.setReverseEngineer(true); entityModel.setExtendedEntity( createBeanEntity(clazz.getSuperclass(), registryNodeModel, relationships, models)); entityModel.setProtocol(EntityProtocol.HTTP); entityModel.setParent(registryNodeModel); Field[] declaredFields = clazz.getDeclaredFields(); List<FieldModel> fields = new ArrayList<FieldModel>(declaredFields.length); for (Field field : declaredFields) { analyzeField(field.getName(), field.getGenericType(), TYPE, entityModel, field.getAnnotation(XmlElement.class), models, relationships, fields); XmlElements xmlElements = field.getAnnotation(XmlElements.class); if (xmlElements != null) { XmlElement[] elements = xmlElements.value(); List<EntityModel> options = new ArrayList<EntityModel>(elements.length); RegistryNodeModel parent = clazz.isMemberClass() ? registryNodeModel.getParent() : registryNodeModel; for (XmlElement element : elements) { if (element.type().isAnnotationPresent(XmlAccessorType.class)) { EntityModel entity = createBeanEntity(element.type(), parent, relationships, models); options.add(entity); } } FieldModel fieldModel = fields.get(fields.size() - 1); fieldModel.setOptions(options); } } entityModel.setFields(fields); return entityModel; }
From source file:org.broadinstitute.sting.commandline.ArgumentTypeDescriptor.java
@Override @SuppressWarnings("unchecked") public Object parse(ParsingEngine parsingEngine, ArgumentSource source, Type fulltype, ArgumentMatches matches) {// w ww . jav a2 s . co m Class type = makeRawTypeIfNecessary(fulltype); Type componentType; Object result; if (Collection.class.isAssignableFrom(type)) { // If this is a generic interface, pick a concrete implementation to create and pass back. // Because of type erasure, don't worry about creating one of exactly the correct type. if (Modifier.isInterface(type.getModifiers()) || Modifier.isAbstract(type.getModifiers())) { if (java.util.List.class.isAssignableFrom(type)) type = ArrayList.class; else if (java.util.Queue.class.isAssignableFrom(type)) type = java.util.ArrayDeque.class; else if (java.util.Set.class.isAssignableFrom(type)) type = java.util.TreeSet.class; } componentType = getCollectionComponentType(source.field); ArgumentTypeDescriptor componentArgumentParser = parsingEngine .selectBestTypeDescriptor(makeRawTypeIfNecessary(componentType)); Collection collection; try { collection = (Collection) type.newInstance(); } catch (InstantiationException e) { logger.fatal( "ArgumentParser: InstantiationException: cannot convert field " + source.field.getName()); throw new ReviewedStingException( "constructFromString:InstantiationException: Failed conversion " + e.getMessage()); } catch (IllegalAccessException e) { logger.fatal( "ArgumentParser: IllegalAccessException: cannot convert field " + source.field.getName()); throw new ReviewedStingException( "constructFromString:IllegalAccessException: Failed conversion " + e.getMessage()); } for (ArgumentMatch match : matches) { for (ArgumentMatch value : match) { Object object = componentArgumentParser.parse(parsingEngine, source, componentType, new ArgumentMatches(value)); collection.add(object); // WARNING: Side effect! parsingEngine.addTags(object, value.tags); } } result = collection; } else if (type.isArray()) { componentType = type.getComponentType(); ArgumentTypeDescriptor componentArgumentParser = parsingEngine .selectBestTypeDescriptor(makeRawTypeIfNecessary(componentType)); // Assemble a collection of individual values used in this computation. Collection<ArgumentMatch> values = new ArrayList<ArgumentMatch>(); for (ArgumentMatch match : matches) for (ArgumentMatch value : match) values.add(value); result = Array.newInstance(makeRawTypeIfNecessary(componentType), values.size()); int i = 0; for (ArgumentMatch value : values) { Object object = componentArgumentParser.parse(parsingEngine, source, componentType, new ArgumentMatches(value)); Array.set(result, i++, object); // WARNING: Side effect! parsingEngine.addTags(object, value.tags); } } else throw new ReviewedStingException("Unsupported compound argument type: " + type); return result; }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadKnowledgeImporters() { String ipack = this.getClass().getPackage().getName() + ".importers"; for (Class<?> cls : MiscUtilities.findSubclasses(IKnowledgeImporter.class, ipack, getClassLoader())) { /*// ww w .ja v a 2s. c om * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof org.integratedmodelling.thinklab.interfaces.annotations.KnowledgeLoader) { String fmt = ((org.integratedmodelling.thinklab.interfaces.annotations.KnowledgeLoader) annotation) .format(); KBoxManager.get().registerImporterClass(fmt, cls); break; } } } }
From source file:org.evosuite.setup.TestClusterGenerator.java
public static boolean canUse(Constructor<?> c) { if (c.isSynthetic()) { return false; }//ww w. j av a 2 s. c o m // synthetic constructors are OK if (Modifier.isAbstract(c.getDeclaringClass().getModifiers())) return false; // TODO we could enable some methods from Object, like getClass //if (c.getDeclaringClass().equals(java.lang.Object.class)) // return false;// handled here to avoid printing reasons if (c.getDeclaringClass().equals(java.lang.Thread.class)) return false;// handled here to avoid printing reasons if (c.getDeclaringClass().isAnonymousClass()) return false; if (c.getDeclaringClass().isLocalClass()) { logger.debug("Skipping constructor of local class {}", c.getName()); return false; } if (c.getDeclaringClass().isMemberClass() && !canUse(c.getDeclaringClass())) return false; if (!Properties.USE_DEPRECATED && c.getAnnotation(Deprecated.class) != null) { logger.debug("Skipping deprecated constructor {}", c.getName()); return false; } if (isForbiddenNonDeterministicCall(c)) { return false; } if (Modifier.isPublic(c.getModifiers())) { makeAccessible(c); return true; } // If default access rights, then check if this class is in the same package as the target class if (!Modifier.isPrivate(c.getModifiers())) { // && !Modifier.isProtected(c.getModifiers())) { String packageName = ClassUtils.getPackageName(c.getDeclaringClass()); if (packageName.equals(Properties.CLASS_PREFIX)) { makeAccessible(c); return true; } } return false; }
From source file:org.statefulj.framework.core.StatefulFactory.java
/** * @param reflections/* w ww. ja v a2 s . c o m*/ * @throws InstantiationException * @throws IllegalAccessException */ private void loadPersistenceSupportBeanFactories(Reflections reflections, Map<Class<?>, PersistenceSupportBeanFactory> persistenceFactories) throws InstantiationException, IllegalAccessException { Set<Class<? extends PersistenceSupportBeanFactory>> persistenceFactoryTypes = reflections .getSubTypesOf(PersistenceSupportBeanFactory.class); for (Class<?> persistenceFactoryType : persistenceFactoryTypes) { if (!Modifier.isAbstract(persistenceFactoryType.getModifiers())) { PersistenceSupportBeanFactory factory = (PersistenceSupportBeanFactory) persistenceFactoryType .newInstance(); Class<?> key = factory.getKey(); if (key != null) { persistenceFactories.put(key, factory); } } } }
From source file:org.statefulj.framework.core.StatefulFactory.java
/** * @return/*from w w w. j a v a 2 s . c o m*/ * @throws InstantiationException * @throws IllegalAccessException */ private void loadEndpointBinders(Reflections reflections, Map<String, EndpointBinder> binders) throws InstantiationException, IllegalAccessException { Set<Class<? extends EndpointBinder>> endpointBinders = reflections.getSubTypesOf(EndpointBinder.class); for (Class<?> binderClass : endpointBinders) { if (!Modifier.isAbstract(binderClass.getModifiers())) { EndpointBinder binder = (EndpointBinder) binderClass.newInstance(); binders.put(binder.getKey(), binder); } } }
From source file:org.evosuite.utils.generic.GenericClass.java
/** * True if this represents an abstract class * * @return */ public boolean isAbstract() { return Modifier.isAbstract(rawClass.getModifiers()); }