List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:gaffer.rest.service.SimpleGraphConfigurationService.java
private static void keepPublicConcreteClasses(final Collection<Class> classes) { if (null != classes) { final Iterator<Class> itr = classes.iterator(); while (itr.hasNext()) { final Class clazz = itr.next(); if (null != clazz) { final int modifiers = clazz.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) { itr.remove();//from www.j a v a 2 s . c o m } } } } }
From source file:com.amalto.core.metadata.ClassRepository.java
private TypeMetadata loadClass(Class clazz) { String typeName = getTypeName(clazz); if (getType(typeName) != null) { // If already defined return it. return getType(typeName); } else if (getNonInstantiableType(StringUtils.EMPTY, typeName) != null) { return getNonInstantiableType(StringUtils.EMPTY, typeName); }/*ww w. j a va 2 s. c om*/ entityToJavaClass.put(typeName, clazz); if (Map.class.isAssignableFrom(clazz)) { return MAP_TYPE; } if (ArrayListHolder.class.equals(clazz)) { typeName = typeName + listCounter++; } boolean isEntity = typeStack.isEmpty(); ComplexTypeMetadata classType = new ComplexTypeMetadataImpl(StringUtils.EMPTY, typeName, isEntity); addTypeMetadata(classType); typeStack.push(classType); String keyFieldName = ""; //$NON-NLS-1$ if (isEntity && ObjectPOJO.class.isAssignableFrom(clazz)) { SimpleTypeFieldMetadata keyField = new SimpleTypeFieldMetadata(typeStack.peek(), true, false, true, "unique-id", //$NON-NLS-1$ STRING, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY); keyField.setData(LINK, "PK/unique-id"); //$NON-NLS-1$ classType.addField(keyField); } else if (isEntity) { keyFieldName = "unique-id"; //$NON-NLS-1$ } // Class is abstract / interface: load sub classes if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { Iterable<Class> subClasses = getSubclasses(clazz); ComplexTypeMetadata superType = typeStack.peek(); if (superType.isInstantiable()) { typeStack.clear(); } for (Class subClass : subClasses) { TypeMetadata typeMetadata = loadClass(subClass); typeMetadata.setInstantiable(superType.isInstantiable()); typeMetadata.addSuperType(superType); } if (superType.isInstantiable()) { typeStack.push(superType); } } // Analyze methods Method[] classMethods = getMethods(clazz); for (Method declaredMethod : classMethods) { if (!Modifier.isStatic(declaredMethod.getModifiers())) { if (isBeanMethod(declaredMethod) && isClassMethod(clazz, declaredMethod)) { String fieldName = getName(declaredMethod); if (typeStack.peek().hasField(fieldName)) { continue; // TODO Avoid override of fields (like PK) } Class<?> returnType = declaredMethod.getReturnType(); FieldMetadata newField; boolean isMany = false; boolean isKey = keyFieldName.equals(fieldName); if (Iterable.class.isAssignableFrom(returnType)) { returnType = listItemType != null ? listItemType : getListItemClass(declaredMethod, returnType); listItemType = null; isMany = true; } else if (ArrayListHolder.class.isAssignableFrom(returnType)) { listItemType = getListItemClass(declaredMethod, returnType); isMany = false; } else if (Map.class.isAssignableFrom(returnType)) { isMany = true; } else if (returnType.isArray()) { isMany = true; returnType = ((Class) returnType.getComponentType()); } else if (returnType.getName().startsWith("org.w3c.")) { //$NON-NLS-1$ // TODO Serialized XML to string column continue; } else if (Class.class.equals(returnType)) { continue; } else if (returnType.getPackage() != null && returnType.getPackage().getName().startsWith("java.io")) { //$NON-NLS-1$ continue; } if (returnType.isPrimitive() || returnType.getName().startsWith(JAVA_LANG_PREFIX)) { String fieldTypeName = returnType.getName().toLowerCase(); if (fieldTypeName.startsWith(JAVA_LANG_PREFIX)) { fieldTypeName = StringUtils.substringAfter(fieldTypeName, JAVA_LANG_PREFIX); } TypeMetadata fieldType; if (Types.BYTE.equals(fieldTypeName) && isMany) { fieldType = new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.BASE64_BINARY); } else { fieldType = new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, fieldTypeName); } newField = new SimpleTypeFieldMetadata(typeStack.peek(), isKey, isMany, isKey, fieldName, fieldType, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY); LongString annotation = declaredMethod.getAnnotation(LongString.class); if (Types.STRING.equals(fieldTypeName) && annotation != null) { fieldType.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(Integer.MAX_VALUE)); if (annotation.preferLongVarchar()) { fieldType.setData(LongString.PREFER_LONGVARCHAR, Boolean.TRUE); } } } else { ComplexTypeMetadata fieldType; if (Map.class.isAssignableFrom(returnType)) { fieldType = MAP_TYPE; } else { fieldType = (ComplexTypeMetadata) loadClass(returnType); } if (!isEntity || !fieldType.isInstantiable()) { newField = new ContainedTypeFieldMetadata(typeStack.peek(), isMany, false, fieldName, new SoftTypeRef(this, StringUtils.EMPTY, fieldType.getName(), false), Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY); } else { newField = new ReferenceFieldMetadata(typeStack.peek(), false, isMany, false, fieldName, fieldType, fieldType.getField("unique-id"), //$NON-NLS-1$ Collections.<FieldMetadata>emptyList(), StringUtils.EMPTY, true, false, STRING, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY, StringUtils.EMPTY); } } typeStack.peek().addField(newField); } } } typeStack.peek().addField(new SimpleTypeFieldMetadata(typeStack.peek(), false, false, false, "digest", //$NON-NLS-1$ new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.STRING), Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY)); return typeStack.pop(); }
From source file:io.github.benas.randombeans.util.ReflectionUtils.java
/** * Check if the type is abstract (either an interface or an abstract class). * * @param type the type to check/*from w ww . j a v a 2s . co m*/ * @param <T> the actual type to check * @return true if the type is abstract, false otherwise */ public static <T> boolean isAbstract(final Class<T> type) { return Modifier.isAbstract(type.getModifiers()); }
From source file:org.ajax4jsf.builder.config.ComponentBaseBean.java
/** * Subclasses should extend this method to provide specifc checks * /* w ww . ja va2s.co m*/ * Check existing and default properties * For properties filled from configuration, attempt to set additional parameters. * If base class have any bean properties, append it to configured * @throws ConfigurationException */ public void checkProperties() throws ParsingException { try { getLog().debug("Parse properties for Component " + getName() + " with superclass " + getSuperclass()); if (getSuperclass() != null) { Class<?> superClass = getLoader().loadClass(getSuperclass()); new ClassWalkingLogic(superClass).walk(new ClassVisitor() { public void visit(Class<?> clazz) { checkPropertiesForClass(clazz); } }); } } catch (ClassNotFoundException e) { getLog().error("superclass not found for component " + getName(), e); } if (null != getTag()) { try { Class superClass = getLoader().loadClass(getTag().getSuperclass()); PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(superClass); // for all properties, add it to component. If property have not abstract getter/setter , // add it with exist = true . If property in list of hidden names, set hidden = true. for (int i = 0; i < properties.length; i++) { PropertyDescriptor descriptor = properties[i]; Method writeMethod = descriptor.getWriteMethod(); if (containProperty(descriptor.getName())) { if (null != writeMethod && !Modifier.isAbstract(writeMethod.getModifiers()) && Modifier.isPublic(writeMethod.getModifiers())) { ((PropertyBean) this.properties.get(descriptor.getName())).setExistintag(true); } } else if (null != writeMethod && Modifier.isPublic(writeMethod.getModifiers())) { if (Arrays.asList(enabledTagProperties).contains(descriptor.getName())) { Class type = descriptor.getPropertyType(); getLog().debug("Register tag property " + descriptor.getName() + " with type name " + type.getCanonicalName()); PropertyBean property = new PropertyBean(); property.setName(descriptor.getName()); property.setDescription(descriptor.getShortDescription()); property.setDisplayname(descriptor.getDisplayName()); property.setClassname(descriptor.getPropertyType().getCanonicalName()); property.setExist(true); if (!Modifier.isAbstract(writeMethod.getModifiers())) { property.setExistintag(true); } addProperty(property); } } } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block getLog().error("superclass not found for tag " + getTag().getName(), e); } } }
From source file:org.structr.core.module.ModuleService.java
/** * Processes the information from the given module and makes them available for the service layer. * * @param module the module to process/*from w w w . j a va2 s . c o m*/ * * @throws IOException */ private void importResource(Module module) throws IOException { Set<String> classes = module.getClasses(); for (final String name : classes) { String className = StringUtils.removeStart(name, "."); logger.log(Level.FINE, "Instantiating class {0} ", className); try { // instantiate class.. Class clazz = Class.forName(className); logger.log(Level.FINE, "Class {0} instantiated: {1}", new Object[] { className, clazz }); if (!Modifier.isAbstract(clazz.getModifiers())) { // register node entity classes if (AbstractNode.class.isAssignableFrom(clazz)) { EntityContext.init(clazz); // try to instantiate class try { EntityContext.scanEntity(clazz.newInstance()); } catch (Throwable t) { } String simpleName = clazz.getSimpleName(); String fullName = clazz.getName(); nodeEntityClassCache.put(simpleName, clazz); nodeEntityPackages.add(fullName.substring(0, fullName.lastIndexOf("."))); for (Class interfaceClass : clazz.getInterfaces()) { String interfaceName = interfaceClass.getSimpleName(); Set<Class> classesForInterface = interfaceCache.get(interfaceName); if (classesForInterface == null) { classesForInterface = new LinkedHashSet<Class>(); interfaceCache.put(interfaceName, classesForInterface); } classesForInterface.add(clazz); } } // register entity classes if (AbstractRelationship.class.isAssignableFrom(clazz)) { EntityContext.init(clazz); // try to instantiate class try { EntityContext.scanEntity(clazz.newInstance()); } catch (Throwable t) { } String simpleName = clazz.getSimpleName(); String fullName = clazz.getName(); relationshipClassCache.put(simpleName, clazz); relationshipPackages.add(fullName.substring(0, fullName.lastIndexOf("."))); for (Class interfaceClass : clazz.getInterfaces()) { String interfaceName = interfaceClass.getSimpleName(); Set<Class> classesForInterface = interfaceCache.get(interfaceName); if (classesForInterface == null) { classesForInterface = new LinkedHashSet<Class>(); interfaceCache.put(interfaceName, classesForInterface); } classesForInterface.add(clazz); } } // register services if (Service.class.isAssignableFrom(clazz)) { Services.registerServiceClass(clazz); } // register agents if (Agent.class.isAssignableFrom(clazz)) { 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:io.github.pellse.decorator.util.reflection.ReflectionUtils.java
public static boolean isAbstract(Class<?> clazz) { return clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers()); }
From source file:ca.uhn.fhir.rest.method.OperationMethodBinding.java
protected OperationMethodBinding(Class<?> theReturnResourceType, Class<? extends IBaseResource> theReturnTypeFromRp, Method theMethod, FhirContext theContext, Object theProvider, boolean theIdempotent, String theOperationName, Class<? extends IBaseResource> theOperationType, OperationParam[] theReturnParams, BundleTypeEnum theBundleType) {/*ww w . j a v a 2 s .c o m*/ super(theReturnResourceType, theMethod, theContext, theProvider); myBundleType = theBundleType; myIdempotent = theIdempotent; myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); if (myIdParamIndex != null) { for (Annotation next : theMethod.getParameterAnnotations()[myIdParamIndex]) { if (next instanceof IdParam) { myCanOperateAtTypeLevel = ((IdParam) next).optional() == true; } } } else { myCanOperateAtTypeLevel = true; } Description description = theMethod.getAnnotation(Description.class); if (description != null) { myDescription = description.formalDefinition(); if (isBlank(myDescription)) { myDescription = description.shortDefinition(); } } if (isBlank(myDescription)) { myDescription = null; } if (isBlank(theOperationName)) { throw new ConfigurationException("Method '" + theMethod.getName() + "' on type " + theMethod.getDeclaringClass().getName() + " is annotated with @" + Operation.class.getSimpleName() + " but this annotation has no name defined"); } if (theOperationName.startsWith("$") == false) { theOperationName = "$" + theOperationName; } myName = theOperationName; if (theContext.getVersion().getVersion().isEquivalentTo(FhirVersionEnum.DSTU1)) { throw new ConfigurationException("@" + Operation.class.getSimpleName() + " methods are not supported on servers for FHIR version " + theContext.getVersion().getVersion().name() + " - Found one on class " + theMethod.getDeclaringClass().getName()); } if (theReturnTypeFromRp != null) { setResourceName(theContext.getResourceDefinition(theReturnTypeFromRp).getName()); } else { if (Modifier.isAbstract(theOperationType.getModifiers()) == false) { setResourceName(theContext.getResourceDefinition(theOperationType).getName()); } else { setResourceName(null); } } if (theMethod.getReturnType().isAssignableFrom(Bundle.class)) { throw new ConfigurationException("Can not return a DSTU1 bundle from an @" + Operation.class.getSimpleName() + " method. Found in method " + theMethod.getName() + " defined in type " + theMethod.getDeclaringClass().getName()); } if (theMethod.getReturnType().equals(IBundleProvider.class)) { myReturnType = ReturnTypeEnum.BUNDLE; } else { myReturnType = ReturnTypeEnum.RESOURCE; } if (getResourceName() == null) { myOtherOperatiopnType = RestOperationTypeEnum.EXTENDED_OPERATION_SERVER; } else if (myIdParamIndex == null) { myOtherOperatiopnType = RestOperationTypeEnum.EXTENDED_OPERATION_TYPE; } else { myOtherOperatiopnType = RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE; } myReturnParams = new ArrayList<OperationMethodBinding.ReturnType>(); if (theReturnParams != null) { for (OperationParam next : theReturnParams) { ReturnType type = new ReturnType(); type.setName(next.name()); type.setMin(next.min()); type.setMax(next.max()); if (type.getMax() == OperationParam.MAX_DEFAULT) { type.setMax(1); } if (!next.type().equals(IBase.class)) { if (next.type().isInterface() || Modifier.isAbstract(next.type().getModifiers())) { throw new ConfigurationException( "Invalid value for @OperationParam.type(): " + next.type().getName()); } type.setType(theContext.getElementDefinition(next.type()).getName()); } myReturnParams.add(type); } } if (myIdParamIndex != null) { myCanOperateAtInstanceLevel = true; } if (getResourceName() == null) { myCanOperateAtServerLevel = true; } }
From source file:com.crudetech.junit.categories.Categories.java
static Class<?>[] allTestClassesInClassPathMatchingPattern(String pattern) throws InitializationError { List<Class<?>> classes = new ArrayList<Class<?>>(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); MetadataReaderFactory metaDataReaderFactory = new CachingMetadataReaderFactory(); try {//from ww w.j a va 2 s .c o m String classPattern = "classpath:" + pattern.replace('.', '/') + ".class"; Resource[] res = resolver.getResources(classPattern); for (Resource r : res) { if (!r.isReadable()) { continue; } MetadataReader reader = metaDataReaderFactory.getMetadataReader(r); Class<?> c = Class.forName(reader.getClassMetadata().getClassName()); if (Modifier.isAbstract(c.getModifiers())) { continue; } classes.add(c); } return classes.toArray(new Class<?>[classes.size()]); } catch (Exception e) { throw new InitializationError(e); } }
From source file:org.pentaho.reporting.libraries.resourceloader.factory.drawable.DrawableWrapper.java
private static boolean computeIsDrawable(final Object maybeDrawable) { final Class<?> aClass = maybeDrawable.getClass(); try {/*from w w w. j a v a 2 s. c o m*/ final Method drawMethod = aClass.getMethod("draw", PARAMETER_TYPES); final int modifiers = drawMethod.getModifiers(); return (Modifier.isPublic(modifiers) && Modifier.isAbstract(modifiers) == false && Modifier.isStatic(modifiers) == false); } catch (NoSuchMethodException e) { // ignore exception return false; } }
From source file:org.apache.syncope.core.logic.init.ClassPathScanImplementationLookup.java
@Override @SuppressWarnings("unchecked") public void load() { classNames = new EnumMap<>(Type.class); for (Type type : Type.values()) { classNames.put(type, new HashSet<String>()); }//from w w w. j a v a2 s . c o m reportletClasses = new HashMap<>(); accountRuleClasses = new HashMap<>(); passwordRuleClasses = new HashMap<>(); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.addIncludeFilter(new AssignableTypeFilter(Reportlet.class)); scanner.addIncludeFilter(new AssignableTypeFilter(AccountRule.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PasswordRule.class)); scanner.addIncludeFilter(new AssignableTypeFilter(MappingItemTransformer.class)); scanner.addIncludeFilter(new AssignableTypeFilter(SchedTaskJobDelegate.class)); scanner.addIncludeFilter(new AssignableTypeFilter(ReconciliationFilterBuilder.class)); scanner.addIncludeFilter(new AssignableTypeFilter(LogicActions.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PropagationActions.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PullActions.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PushActions.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PullCorrelationRule.class)); scanner.addIncludeFilter(new AssignableTypeFilter(Validator.class)); scanner.addIncludeFilter(new AssignableTypeFilter(NotificationRecipientsProvider.class)); for (BeanDefinition bd : scanner.findCandidateComponents(StringUtils.EMPTY)) { try { Class<?> clazz = ClassUtils.resolveClassName(bd.getBeanClassName(), ClassUtils.getDefaultClassLoader()); boolean isAbsractClazz = Modifier.isAbstract(clazz.getModifiers()); if (Reportlet.class.isAssignableFrom(clazz) && !isAbsractClazz) { ReportletConfClass annotation = clazz.getAnnotation(ReportletConfClass.class); if (annotation == null) { LOG.warn("Found Reportlet {} without declared configuration", clazz.getName()); } else { classNames.get(Type.REPORTLET_CONF).add(annotation.value().getName()); reportletClasses.put(annotation.value(), (Class<? extends Reportlet>) clazz); } } if (AccountRule.class.isAssignableFrom(clazz) && !isAbsractClazz) { AccountRuleConfClass annotation = clazz.getAnnotation(AccountRuleConfClass.class); if (annotation == null) { LOG.warn("Found account policy rule {} without declared configuration", clazz.getName()); } else { classNames.get(Type.ACCOUNT_RULE_CONF).add(annotation.value().getName()); accountRuleClasses.put(annotation.value(), (Class<? extends AccountRule>) clazz); } } if (PasswordRule.class.isAssignableFrom(clazz) && !isAbsractClazz) { PasswordRuleConfClass annotation = clazz.getAnnotation(PasswordRuleConfClass.class); if (annotation == null) { LOG.warn("Found password policy rule {} without declared configuration", clazz.getName()); } else { classNames.get(Type.PASSWORD_RULE_CONF).add(annotation.value().getName()); passwordRuleClasses.put(annotation.value(), (Class<? extends PasswordRule>) clazz); } } if (MappingItemTransformer.class.isAssignableFrom(clazz) && !isAbsractClazz && !clazz.equals(JEXLMappingItemTransformerImpl.class)) { classNames.get(Type.MAPPING_ITEM_TRANSFORMER).add(clazz.getName()); } if (SchedTaskJobDelegate.class.isAssignableFrom(clazz) && !isAbsractClazz && !PullJobDelegate.class.isAssignableFrom(clazz) && !PushJobDelegate.class.isAssignableFrom(clazz) && !GroupMemberProvisionTaskJobDelegate.class.isAssignableFrom(clazz)) { classNames.get(Type.TASKJOBDELEGATE).add(bd.getBeanClassName()); } if (ReconciliationFilterBuilder.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.RECONCILIATION_FILTER_BUILDER).add(bd.getBeanClassName()); } if (LogicActions.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.LOGIC_ACTIONS).add(bd.getBeanClassName()); } if (PropagationActions.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.PROPAGATION_ACTIONS).add(bd.getBeanClassName()); } if (PullActions.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.PULL_ACTIONS).add(bd.getBeanClassName()); } if (PushActions.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.PUSH_ACTIONS).add(bd.getBeanClassName()); } if (PullCorrelationRule.class.isAssignableFrom(clazz) && !isAbsractClazz && !PlainAttrsPullCorrelationRule.class.isAssignableFrom(clazz)) { classNames.get(Type.PULL_CORRELATION_RULE).add(bd.getBeanClassName()); } if (Validator.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.VALIDATOR).add(bd.getBeanClassName()); } if (NotificationRecipientsProvider.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.NOTIFICATION_RECIPIENTS_PROVIDER).add(bd.getBeanClassName()); } } catch (Throwable t) { LOG.warn("Could not inspect class {}", bd.getBeanClassName(), t); } } classNames = Collections.unmodifiableMap(classNames); reportletClasses = Collections.unmodifiableMap(reportletClasses); accountRuleClasses = Collections.unmodifiableMap(accountRuleClasses); passwordRuleClasses = Collections.unmodifiableMap(passwordRuleClasses); LOG.debug("Implementation classes found: {}", classNames); }