List of usage examples for java.lang.reflect Modifier isInterface
public static boolean isInterface(int mod)
From source file:com.cuubez.visualizer.resource.ResourceMetaDataScanner.java
public static boolean isResource(Class<?> clazz) { if (Modifier.isInterface(clazz.getModifiers()) || Modifier.isAbstract(clazz.getModifiers())) { return false; }/*w w w . jav a 2 s .c o m*/ if (clazz.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) { return true; } Class<?> declaringClass = clazz; while (!declaringClass.equals(Object.class)) { // try a superclass Class<?> superclass = declaringClass.getSuperclass(); if (superclass.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) { return true; } // try interfaces Class<?>[] interfaces = declaringClass.getInterfaces(); for (Class<?> interfaceClass : interfaces) { if (interfaceClass.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) { return true; } } declaringClass = declaringClass.getSuperclass(); } return false; }
From source file:org.spongepowered.common.util.ReflectionUtil.java
public static <T> T createInstance(final Class<T> objectClass, Object... args) { checkArgument(!Modifier.isAbstract(objectClass.getModifiers()), "Cannot construct an instance of an abstract class!"); checkArgument(!Modifier.isInterface(objectClass.getModifiers()), "Cannot construct an instance of an interface!"); if (args == null) { args = new Object[] { null }; }/*from ww w.j a va2 s . c o m*/ final Constructor<T> ctor = findConstructor(objectClass, args); try { return ctor.newInstance(args); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { SpongeImpl.getLogger().error("Couldn't find an appropriate constructor for " + objectClass.getCanonicalName() + "with the args: " + Arrays.toString(args), e); } throw new IllegalArgumentException("Couldn't find an appropriate constructor for " + objectClass.getCanonicalName() + "the args: " + Arrays.toString(args)); }
From source file:org.lanternpowered.server.util.ReflectionHelper.java
public static <T> T createInstance(final Class<T> objectClass, @Nullable Object... args) { checkArgument(!Modifier.isAbstract(objectClass.getModifiers()), "Cannot construct an instance of an abstract class!"); checkArgument(!Modifier.isInterface(objectClass.getModifiers()), "Cannot construct an instance of an interface!"); if (args == null) { args = new Object[] { null }; }/*from w w w . ja va2s .com*/ final Constructor<T> ctor = findConstructor(objectClass, args); try { return ctor.newInstance(args); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { Lantern.getLogger().error("Couldn't find an appropriate constructor for " + objectClass.getCanonicalName() + "with the args: " + Arrays.toString(args), e); } throw new IllegalArgumentException("Couldn't find an appropriate constructor for " + objectClass.getCanonicalName() + "the args: " + Arrays.toString(args)); }
From source file:ca.uhn.fhir.rest.method.HistoryMethodBinding.java
public HistoryMethodBinding(Method theMethod, FhirContext theContext, Object theProvider) { super(toReturnType(theMethod, theProvider), theMethod, theContext, theProvider); myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext()); History historyAnnotation = theMethod.getAnnotation(History.class); Class<? extends IBaseResource> type = historyAnnotation.type(); if (Modifier.isInterface(type.getModifiers())) { if (theProvider instanceof IResourceProvider) { type = ((IResourceProvider) theProvider).getResourceType(); if (myIdParamIndex != null) { myResourceOperationType = RestOperationTypeEnum.HISTORY_INSTANCE; } else { myResourceOperationType = RestOperationTypeEnum.HISTORY_TYPE; }/*from w w w . java 2s. com*/ } else { myResourceOperationType = RestOperationTypeEnum.HISTORY_SYSTEM; } } else { if (myIdParamIndex != null) { myResourceOperationType = RestOperationTypeEnum.HISTORY_INSTANCE; } else { myResourceOperationType = RestOperationTypeEnum.HISTORY_TYPE; } } if (type != IResource.class) { myResourceName = theContext.getResourceDefinition(type).getName(); } else { myResourceName = null; } }
From source file:org.pentaho.reporting.engine.classic.core.metadata.ExpressionRegistry.java
public void registerExpression(final ExpressionMetaData metaData) { if (metaData == null) { throw new NullPointerException(); }// w w w.ja va 2 s . c o m final Class type = metaData.getExpressionType(); final int modifiers = type.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { throw new IllegalArgumentException("Expression-Implementation cannot be abstract or an interface."); } this.backend.put(type.getName(), metaData); }
From source file:main.server.DemoPageProvider.java
public DemoPageProvider(ServletContext sc) { pageDir = new File(System.getProperty("user.dir", ""), "war/WEB-INF/pages"); if (!pageDir.isDirectory()) { pageDir = new File(sc.getRealPath("WEB-INF/pages")); useSession = true;//www. jav a2 s . c o m log.info("Saving pages to session: " + pageDir); } else { log.info("Loading and saving pages from " + pageDir); } // discover our classes (in a real app they would be Spring beans or // something similar) ClassFinder cf = new ClassFinder(sc, "main"); // find all PortletFactory's and alias them so fully qualified class // names don't end up in the XML for (Class cls : cf.findClasses("$Factory", PortletFactory.class)) { log.info("Portlet factory: " + cls.getName()); xmlIO.alias(cls); } // create an instance of each DataProvider for (Class cls : cf.findClasses("DataProvider", WidgetDataProvider.class)) { int mod = cls.getModifiers(); if (!Modifier.isAbstract(mod) && !Modifier.isInterface(mod)) { log.info("Data provider: " + cls.getName()); try { add((WidgetDataProvider) cls.newInstance()); } catch (Exception e) { log.error(e, e); } } } }
From source file:org.pentaho.reporting.engine.classic.core.metadata.ReportPreProcessorRegistry.java
public void registerReportPreProcessor(final ReportPreProcessorMetaData metaData) { if (metaData == null) { throw new NullPointerException(); }/*from w w w . j a v a 2s . co m*/ final Class type = metaData.getPreProcessorType(); final int modifiers = type.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { throw new IllegalArgumentException( "report-preprocessor-Implementation cannot be abstract or an interface."); } this.backend.put(type.getName(), metaData); }
From source file:org.opoo.util.ClassUtils.java
public static boolean isAbstractClass(Class clazz) { int modifier = clazz.getModifiers(); return Modifier.isAbstract(modifier) || Modifier.isInterface(modifier); }
From source file:org.topazproject.otm.mapping.java.ClassBinder.java
/** * Creates a new ClassBinder object./*from w w w.j a v a2 s .c om*/ * * @param clazz the java class to bind this entity to * @param suppressAlias to dis-allow registration of the class name as an alias. * This allows binding the same class to multiple entities. */ public ClassBinder(Class<T> clazz, boolean suppressAlias) { this.clazz = clazz; this.suppressAlias = suppressAlias; int mod = clazz.getModifiers(); instantiable = !Modifier.isAbstract(mod) && !Modifier.isInterface(mod) && Modifier.isPublic(mod); }
From source file:com.retroduction.carma.resolvers.util.TestCaseInstantiationVerifier.java
public HashSet<String> determineUnloadableTestClassNames(Set<String> fqTestClassNames) { HashSet<String> unloadableClasses = new HashSet<String>(); for (String testClassName : fqTestClassNames) { try {//w w w .j a v a 2 s . co m Class<?> testClass = this.getLoader().loadClass(testClassName); if (Modifier.isAbstract(testClass.getModifiers()) || Modifier.isInterface(testClass.getModifiers())) { this.log.info("Skipping abstract class or interface in test set:" + testClassName); unloadableClasses.add(testClassName); continue; } } catch (Exception e) { this.log.warn("Skipping class in test set due to class loading problem:" + testClassName); this.log.debug(e); unloadableClasses.add(testClassName); continue; } catch (NoClassDefFoundError e) { this.log.warn("Skipping class in test set due to class loading problem:" + testClassName); this.log.debug(e); unloadableClasses.add(testClassName); continue; } } return unloadableClasses; }