List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:com.jaspersoft.jasperserver.jrsh.operation.PackageScanClassResolver.java
/** * Discovers the packages retrieves operation types. * * @param basePackage package to scan//from www . java2 s. c o m * @return operation classes */ public static Set<Class<? extends Operation>> findOperationClasses(String basePackage) { HashSet<Class<? extends Operation>> operationTypes = new HashSet<>(); MetadataScannerConfig config = readConfig(); List<String> externalPackagesToScan = config.getPackagesToScan(); List<String> classes = config.getClasses(); FilterBuilder filter = new FilterBuilder().includePackage(basePackage); // // Discover external operation types from configuration file // if (classes != null) { for (String aClass : classes) { try { Class clz = Class.forName(aClass); if (!Modifier.isAbstract(clz.getModifiers()) && Operation.class.isAssignableFrom(clz)) { operationTypes.add(clz); } } catch (ClassNotFoundException ignored) { } } } // // Prepare package filter to avoid unnecessary CP scanning // if (externalPackagesToScan != null) { for (String aPackage : externalPackagesToScan) { aPackage = chomp(aPackage, ".*"); filter.includePackage(aPackage); } } // // Retrieve internal operation types // Reflections ref = new Reflections(new SubTypesScanner(), filter); for (val subType : ref.getSubTypesOf(Operation.class)) { if (!Modifier.isAbstract(subType.getModifiers())) { operationTypes.add(subType); } } return operationTypes; }
From source file:com.laxser.blitz.web.impl.module.ErrorHandlerDispatcher.java
public ErrorHandlerDispatcher(ControllerErrorHandler errorHandler) { this.errorHandler = errorHandler; Method[] methods = this.errorHandler.getClass().getMethods(); for (final Method method : methods) { if (Modifier.isAbstract(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { continue; }/* w ww.ja v a2 s . c o m*/ if (method.getName().equals("onError")) { final Class<?>[] parameterClasses = method.getParameterTypes(); if (parameterClasses.length == 2 && parameterClasses[INVOCATION_INDEX] == Invocation.class && Throwable.class.isAssignableFrom(parameterClasses[THROWABLE_INDEX])) { delegates.add(new ErrorHandlerDelegate() { @Override public Method getMethod() { return method; } @Override public Object onError(Invocation inv, Throwable ex) throws Throwable { Object[] args = new Object[] { inv, ex }; try { return method.invoke(ErrorHandlerDispatcher.this.errorHandler, args); } catch (Throwable e) { logger.error("error happened when handling error " + ex.getClass() + " at " + ErrorHandlerDispatcher.this.toString()); throw e; } } }); } } } Collections.sort(delegates, new Comparator<ErrorHandlerDelegate>() { @Override public int compare(ErrorHandlerDelegate o1, ErrorHandlerDelegate o2) { if (o1.getMethod().getParameterTypes()[THROWABLE_INDEX] .isAssignableFrom(o2.getMethod().getParameterTypes()[THROWABLE_INDEX])) { return 1; } else if (o2.getMethod().getParameterTypes()[THROWABLE_INDEX] .isAssignableFrom(o1.getMethod().getParameterTypes()[THROWABLE_INDEX])) { return -1; } else { return o1.getMethod().getParameterTypes()[THROWABLE_INDEX].getName() .compareTo(o2.getMethod().getParameterTypes()[THROWABLE_INDEX].getName()); } } }); }
From source file:com.sinosoft.one.mvc.web.impl.module.ErrorHandlerDispatcher.java
public ErrorHandlerDispatcher(ControllerErrorHandler errorHandler) { this.errorHandler = errorHandler; Method[] methods = this.errorHandler.getClass().getMethods(); for (final Method method : methods) { if (Modifier.isAbstract(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { continue; }// w w w .ja va 2 s . c om if (method.getName().equals("onError")) { final Class<?>[] parameterClasses = method.getParameterTypes(); if (parameterClasses.length == 2 && parameterClasses[INVOCATION_INDEX] == Invocation.class && Throwable.class.isAssignableFrom(parameterClasses[THROWABLE_INDEX])) { delegates.add(new ErrorHandlerDelegate() { @Override public Method getMethod() { return method; } @Override public Object onError(Invocation inv, Throwable ex) throws Throwable { Object[] args = new Object[] { inv, ex }; try { return method.invoke(ErrorHandlerDispatcher.this.errorHandler, args); } catch (Throwable e) { logger.error("error happened when handling error " + ex.getClass() + " at " + ErrorHandlerDispatcher.this.toString()); throw e; } } }); } } } Collections.sort(delegates, new Comparator<ErrorHandlerDelegate>() { public int compare(ErrorHandlerDelegate o1, ErrorHandlerDelegate o2) { if (o1.getMethod().getParameterTypes()[THROWABLE_INDEX] .isAssignableFrom(o2.getMethod().getParameterTypes()[THROWABLE_INDEX])) { return 1; } else if (o2.getMethod().getParameterTypes()[THROWABLE_INDEX] .isAssignableFrom(o1.getMethod().getParameterTypes()[THROWABLE_INDEX])) { return -1; } else { return o1.getMethod().getParameterTypes()[THROWABLE_INDEX].getName() .compareTo(o2.getMethod().getParameterTypes()[THROWABLE_INDEX].getName()); } } }); }
From source file:edu.northwestern.bioinformatics.studycalendar.domain.delta.DeltaNodeTypeTest.java
public void testThereIsOneDeltaNodeTypePerDeltaClass() throws Exception { List<String> errors = new ArrayList<String>(); for (Class<? extends Delta> deltaClass : domainReflections.getSubTypesOf(Delta.class)) { if (Modifier.isAbstract(deltaClass.getModifiers()) || deltaClass.isAnonymousClass()) continue; try {// w w w .j ava 2 s .c o m DeltaNodeType.valueForDeltaClass(deltaClass); } catch (IllegalArgumentException iae) { errors.add(iae.getMessage()); } } if (!errors.isEmpty()) { fail("* " + StringUtils.join(errors.iterator(), "\n* ")); } }
From source file:edu.usc.goffish.gofs.namenode.NameNodeProvider.java
@SuppressWarnings("unchecked") public static Class<? extends IInternalNameNode> loadNameNodeType(String typeName) throws ClassNotFoundException, ReflectiveOperationException { Class<?> givenType = Class.forName(typeName); if (!IInternalNameNode.class.isAssignableFrom(givenType) || givenType.isInterface() || Modifier.isAbstract(givenType.getModifiers())) { throw new IllegalArgumentException( typeName + " is not a concrete class deriving from IInternalNameNode"); }//from ww w .j a v a 2s . c o m return (Class<? extends IInternalNameNode>) givenType; }
From source file:stormy.pythian.service.description.ClassRepository.java
public Set<Class<? extends PythianState>> getStateClasses() { return filter(reflections.getSubTypesOf(PythianState.class), new Predicate<Class<?>>() { public boolean apply(Class<?> input) { return !Modifier.isAbstract(input.getModifiers()); }//from w ww . j a v a2 s . com }); }
From source file:org.openmhealth.schema.service.SchemaClassServiceImpl.java
@PostConstruct public void initializeSchemaIds() throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException { Reflections reflections = new Reflections(SCHEMA_CLASS_PACKAGE); for (Class<? extends SchemaSupport> schemaClass : reflections.getSubTypesOf(SchemaSupport.class)) { if (schemaClass.isInterface() || Modifier.isAbstract(schemaClass.getModifiers())) { continue; }// w w w . j av a 2 s . c o m SchemaId schemaId; if (schemaClass.isEnum()) { schemaId = schemaClass.getEnumConstants()[0].getSchemaId(); } else { Constructor<? extends SchemaSupport> constructor = schemaClass.getDeclaredConstructor(); constructor.setAccessible(true); schemaId = constructor.newInstance().getSchemaId(); } schemaIds.add(schemaId); } }
From source file:com.alta189.bukkit.script.event.EventScanner.java
public static void scanBukkit() { Reflections reflections = new Reflections(new ConfigurationBuilder() .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.bukkit"))) .setUrls(ClasspathHelper.forClassLoader(ClasspathHelper.contextClassLoader(), ClasspathHelper.staticClassLoader()))); Set<Class<? extends Event>> classes = reflections.getSubTypesOf(Event.class); BScript plugin = BScript.getInstance(); plugin.info(/*from w w w . j ava2 s . co m*/ "Found " + classes.size() + " classes extending " + Event.class.getCanonicalName() + " in Bukkit"); for (Class<? extends Event> clazz : classes) { if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { continue; } bukkitEvent.put(clazz.getSimpleName(), clazz); String className = clazz.getCanonicalName(); if (className == null) { className = clazz.getName(); } events.put(className, clazz); simpleNameEvents.put(clazz.getSimpleName(), clazz); plugin.debug(className); } }
From source file:de.tudarmstadt.ukp.dkpro.core.testing.validation.CasValidator.java
public static CasValidator createWithAllChecks() { Reflections reflections = new Reflections(Check.class.getPackage().getName()); CasValidator validator = new CasValidator(); validator.setChecks(reflections.getSubTypesOf(Check.class).stream() .filter(c -> !Modifier.isAbstract(c.getModifiers())).collect(Collectors.toList())); return validator; }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.DeltaXmlSerializerFactoryTest.java
@SuppressWarnings({ "RawUseOfParameterizedType" }) public void testASerializerCanBeBuiltForEveryDelta() throws Exception { List<String> errors = new ArrayList<String>(); for (Class<? extends Delta> aClass : domainReflections.getSubTypesOf(Delta.class)) { if (!Modifier.isAbstract(aClass.getModifiers()) && !aClass.isAnonymousClass()) { Delta d = aClass.newInstance(); try { factory.createXmlSerializer(d); } catch (StudyCalendarError sce) { errors.add(String.format("Failure with %s: %s", d, sce.getMessage())); }/*from www. jav a 2 s .c o m*/ } } if (!errors.isEmpty()) { fail(StringUtils.join(errors.iterator(), '\n')); } }