List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:org.pantsbuild.tools.junit.impl.ConsoleRunnerImpl.java
private static boolean isTest(final Class<?> clazz) { // Must be a public concrete class to be a runnable junit Test. if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers()) || !Modifier.isPublic(clazz.getModifiers())) { return false; }/*from w w w . j a v a 2 s . co m*/ // The class must have some public constructor to be instantiated by the runner being used if (!Iterables.any(Arrays.asList(clazz.getConstructors()), IS_PUBLIC_CONSTRUCTOR)) { return false; } // Support junit 3.x Test hierarchy. if (junit.framework.Test.class.isAssignableFrom(clazz)) { return true; } // Support classes using junit 4.x custom runners. if (clazz.isAnnotationPresent(RunWith.class)) { return true; } // Support junit 4.x @Test annotated methods. return Iterables.any(Arrays.asList(clazz.getMethods()), IS_ANNOTATED_TEST_METHOD); }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadInstanceImplementationConstructors() throws ThinklabPluginException { String ipack = this.getClass().getPackage().getName() + ".implementations"; for (Class<?> cls : MiscUtilities.findSubclasses(IInstanceImplementation.class, ipack, getClassLoader())) { String concept = null;/*from w w w . jav a 2s. c o m*/ /* * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; /* * lookup implemented concept */ for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof InstanceImplementation) { concept = ((InstanceImplementation) annotation).concept(); } } if (concept != null) { String[] cc = concept.split(","); for (String ccc : cc) { logger().info("registering class " + cls + " as implementation for instances of type " + ccc); KnowledgeManager.get().registerInstanceImplementationClass(ccc, cls); } } } }
From source file:com.github.helenusdriver.driver.impl.ClassInfoImpl.java
/** * Instantiates a new <code>ClassInfo</code> object. * * @author paouelle// ww w .j a v a 2 s . c om * * @param mgr the non-<code>null</code> statement manager * @param clazz the class of POJO for which to get a class info object for * @throws NullPointerException if <code>clazz</code> is <code>null</code> * @throws IllegalArgumentException if <code>clazz</code> doesn't represent * a valid POJO class */ ClassInfoImpl(StatementManagerImpl mgr, Class<T> clazz) { this(mgr, clazz, Entity.class); org.apache.commons.lang3.Validate.isTrue(!Modifier.isAbstract(clazz.getModifiers()), "entity class '%s', cannot be abstract", clazz.getSimpleName()); }
From source file:com.github.helenusdriver.driver.impl.FieldInfoImpl.java
/** * Finds the getter method from the declaring class suitable to get a * reference to the field.//from w w w . j a va 2 s . co m * * @author paouelle * * @param declaringClass the non-<code>null</code> class declaring the field * @param prefix the non-<code>null</code> getter prefix to use * @return the getter method for the field or <code>null</code> if none found * @throws IllegalArgumentException if unable to find a suitable getter */ private Method findGetterMethod(Class<?> declaringClass, String prefix) { final String mname = prefix + WordUtils.capitalize(name, '_', '-'); try { final Method m = declaringClass.getDeclaredMethod(mname); final int mods = m.getModifiers(); if (Modifier.isAbstract(mods) || Modifier.isStatic(mods)) { return null; } final Class<?> wtype = ClassUtils.primitiveToWrapper(type); final Class<?> wrtype = ClassUtils.primitiveToWrapper( DataTypeImpl.unwrapOptionalIfPresent(m.getReturnType(), m.getGenericReturnType())); org.apache.commons.lang3.Validate.isTrue(wtype.isAssignableFrom(wrtype), "expecting getter for field '%s' with return type: %s", field, type.getName()); m.setAccessible(true); return m; } catch (NoSuchMethodException e) { return null; } }
From source file:org.openTwoFactor.client.util.TwoFactorClientCommonUtils.java
/** * Construct a class//from ww w . j av a2 s.c om * @param <T> template type * @param theClass * @return the instance */ public static <T> T newInstance(Class<T> theClass) { try { return theClass.newInstance(); } catch (Throwable e) { if (theClass != null && Modifier.isAbstract(theClass.getModifiers())) { throw new RuntimeException("Problem with class: " + theClass + ", maybe because it is abstract!", e); } throw new RuntimeException("Problem with class: " + theClass, e); } }
From source file:org.jgentleframework.utils.ReflectUtils.java
/** * Returns the first <b>abstract</b> super class of the given class. * //from w w w .j a v a2 s . c o m * @param clazz * the given class * @return returns the object class of the first abstract super class of the * given class if it exists, if not, reuturns <code>null</code> */ public static Class<?> getFirstAbstractSuperClass(Class<?> clazz) { Class<?> result = clazz.getSuperclass(); while (result != null) { if (!Modifier.isAbstract(result.getModifiers())) { result = result.getSuperclass(); } else { break; } } return result; }
From source file:cn.aposoft.util.spring.ReflectionUtils.java
private static List<Method> findConcreteMethodsOnInterfaces(Class<?> clazz) { List<Method> result = null; for (Class<?> ifc : clazz.getInterfaces()) { for (Method ifcMethod : ifc.getMethods()) { if (!Modifier.isAbstract(ifcMethod.getModifiers())) { if (result == null) { result = new LinkedList<Method>(); }/*from ww w . j a va2 s .c o m*/ result.add(ifcMethod); } } } return result; }
From source file:org.integratedmodelling.thinklab.plugin.ThinklabPlugin.java
protected void loadPersistentClasses() throws ThinklabPluginException { String ipack = this.getClass().getPackage().getName() + ".implementations"; for (Class<?> cls : MiscUtilities.findSubclasses(IPersistentObject.class, ipack, getClassLoader())) { String ext = null;/*w w w . j av a2 s. com*/ /* * lookup annotation, ensure we can use the class */ if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; /* * lookup implemented concept */ for (Annotation annotation : cls.getAnnotations()) { if (annotation instanceof PersistentObject) { ext = ((PersistentObject) annotation).extension(); if (ext.equals("__NOEXT__")) ext = null; break; } } PersistenceManager.get().registerSerializableClass(cls, ext); } }
From source file:org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.java
/** * Generate schema construct for given type * * @param javaType : Class to whcih need to generate Schema * @return : Generated QName/* w w w . j a v a 2s.c o m*/ */ protected QName generateSchema(Class<?> javaType) throws Exception { String name = getClassName(javaType); QName schemaTypeName = typeTable.getComplexSchemaType(name); if (schemaTypeName == null) { String simpleName = getSimpleClassName(javaType); String packageName = getQualifiedName(javaType.getPackage()); String targetNameSpace = resolveSchemaNamespace(packageName); XmlSchema xmlSchema = getXmlSchema(targetNameSpace); String targetNamespacePrefix = targetNamespacePrefixMap.get(targetNameSpace); if (targetNamespacePrefix == null) { targetNamespacePrefix = generatePrefix(); targetNamespacePrefixMap.put(targetNameSpace, targetNamespacePrefix); } XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema); XmlSchemaSequence sequence = new XmlSchemaSequence(); XmlSchemaComplexContentExtension complexExtension = new XmlSchemaComplexContentExtension(); XmlSchemaElement eltOuter = new XmlSchemaElement(); schemaTypeName = new QName(targetNameSpace, simpleName, targetNamespacePrefix); eltOuter.setName(simpleName); eltOuter.setQName(schemaTypeName); Class<?> sup = javaType.getSuperclass(); if ((sup != null) && (!"java.lang.Object".equals(sup.getName())) && (!"java.lang.Exception".equals(sup.getName())) && !getQualifiedName(sup.getPackage()).startsWith("org.apache.axis2") && !getQualifiedName(sup.getPackage()).startsWith("java.util")) { String superClassName = sup.getName(); String superclassname = getSimpleClassName(sup); String tgtNamespace; String tgtNamespacepfx; QName qName = typeTable.getSimpleSchemaTypeName(superClassName); if (qName != null) { tgtNamespace = qName.getNamespaceURI(); tgtNamespacepfx = qName.getPrefix(); } else { tgtNamespace = resolveSchemaNamespace(getQualifiedName(sup.getPackage())); tgtNamespacepfx = targetNamespacePrefixMap.get(tgtNamespace); QName superClassQname = generateSchema(sup); if (superClassQname != null) { tgtNamespacepfx = superClassQname.getPrefix(); tgtNamespace = superClassQname.getNamespaceURI(); } } if (tgtNamespacepfx == null) { tgtNamespacepfx = generatePrefix(); targetNamespacePrefixMap.put(tgtNamespace, tgtNamespacepfx); } //if the parent class package name is differ from the child if (!((NamespaceMap) xmlSchema.getNamespaceContext()).values().contains(tgtNamespace)) { XmlSchemaImport importElement = new XmlSchemaImport(); importElement.setNamespace(tgtNamespace); xmlSchema.getItems().add(importElement); ((NamespaceMap) xmlSchema.getNamespaceContext()).put(generatePrefix(), tgtNamespace); } QName basetype = new QName(tgtNamespace, superclassname, tgtNamespacepfx); complexExtension.setBaseTypeName(basetype); complexExtension.setParticle(sequence); XmlSchemaComplexContent contentModel = new XmlSchemaComplexContent(); contentModel.setContent(complexExtension); complexType.setContentModel(contentModel); } else { complexType.setParticle(sequence); } complexType.setName(simpleName); if (Modifier.isAbstract(javaType.getModifiers())) { complexType.setAbstract(true); } // xmlSchema.getItems().add(eltOuter); xmlSchema.getElements().add(schemaTypeName, eltOuter); eltOuter.setSchemaTypeName(complexType.getQName()); xmlSchema.getItems().add(complexType); xmlSchema.getSchemaTypes().add(schemaTypeName, complexType); // adding this type to the table typeTable.addComplexSchema(name, eltOuter.getQName()); // adding this type's package to the table, to support inheritance. typeTable.addComplexSchema(getQualifiedName(javaType.getPackage()), eltOuter.getQName()); typeTable.addClassNameForQName(eltOuter.getQName(), name); BeanExcludeInfo beanExcludeInfo = null; if (service.getExcludeInfo() != null) { beanExcludeInfo = service.getExcludeInfo().getBeanExcludeInfoForClass(getClassName(javaType)); } // we need to get properties only for this bean. hence ignore the super // class properties BeanInfo beanInfo = Introspector.getBeanInfo(javaType, javaType.getSuperclass()); for (PropertyDescriptor property : beanInfo.getPropertyDescriptors()) { String propertyName = property.getName(); if (!property.getName().equals("class") && (property.getPropertyType() != null)) { if ((beanExcludeInfo == null) || !beanExcludeInfo.isExcludedProperty(propertyName)) { Type genericFieldType = null; try { Field field = javaType.getDeclaredField(propertyName); genericFieldType = field.getGenericType(); } catch (Exception e) { //log.info(e.getMessage()); } if (genericFieldType instanceof ParameterizedType) { ParameterizedType aType = (ParameterizedType) genericFieldType; Type[] fieldArgTypes = aType.getActualTypeArguments(); try { generateSchemaforGenericFields(xmlSchema, sequence, fieldArgTypes[0], propertyName); } catch (Exception e) { generateSchemaforFieldsandProperties(xmlSchema, sequence, property.getPropertyType(), propertyName, property.getPropertyType().isArray()); } } else { generateSchemaforFieldsandProperties(xmlSchema, sequence, property.getPropertyType(), propertyName, property.getPropertyType().isArray()); } } } } } return schemaTypeName; }
From source file:com.github.helenusdriver.driver.impl.FieldInfoImpl.java
/** * Finds the setter method from the declaring class suitable to set a * value for the field./*from ww w . j a va 2s .c om*/ * * @author paouelle * * @param declaringClass the non-<code>null</code> class declaring the field * @return the setter method for the field or <code>null</code> if none found * @throws IllegalArgumentException if unable to find a suitable setter */ private Method findSetterMethod(Class<?> declaringClass) { final String mname = "set" + WordUtils.capitalize(name, '_', '-'); try { final Method m = declaringClass.getDeclaredMethod(mname, type); final int mods = m.getModifiers(); if (Modifier.isAbstract(mods) || Modifier.isStatic(mods)) { return null; } org.apache.commons.lang3.Validate.isTrue(m.getParameterCount() == 1, "expecting setter for field '%s' with one parameter", field); final Class<?> wtype = ClassUtils.primitiveToWrapper(type); final Class<?> wptype = ClassUtils.primitiveToWrapper(DataTypeImpl.unwrapOptionalIfPresent( m.getParameterTypes()[0], m.getParameters()[0].getParameterizedType())); org.apache.commons.lang3.Validate.isTrue(wtype.isAssignableFrom(wptype), "expecting setter for field '%s' with parameter type: %s", field, type.getName()); m.setAccessible(true); return m; } catch (NoSuchMethodException e) { return null; } }