List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:org.jacpfx.spring.launcher.AFXSpringJavaConfigLauncher.java
private void initWorkbench(final Stage stage, final Launcher<AnnotationConfigApplicationContext> launcher, final Class<? extends FXWorkbench> workbenchHandler) { if (workbenchHandler.isAnnotationPresent(Workbench.class)) { this.workbench = createWorkbench(launcher, workbenchHandler); workbench.init(launcher, stage); postInit(stage);/*from w w w. ja v a2s . c o m*/ } else { throw new AnnotationNotFoundException("no @Workbench annotation found on class"); } }
From source file:de.taimos.dvalin.jaxrs.swagger.SwaggerScanner.java
private boolean hasAnnotation(Class<?> clz, Class<? extends Annotation> ann) { if (clz.isAnnotationPresent(ann)) { return true; }//from w w w . j a va 2s . co m for (Class<?> iface : clz.getInterfaces()) { if (this.hasAnnotation(iface, ann)) { return true; } } return (clz.getSuperclass() != null) && this.hasAnnotation(clz.getSuperclass(), ann); }
From source file:jails.http.converter.xml.Jaxb2RootElementHttpMessageConverter.java
@Override public boolean canRead(Class<?> clazz, MediaType mediaType) { return (clazz.isAnnotationPresent(XmlRootElement.class) || clazz.isAnnotationPresent(XmlType.class)) && canRead(mediaType); }
From source file:com.mmnaseri.dragonfly.events.CallbackResolver.java
@Override public synchronized void postProcessMetadataContext(TableMetadataContext tableMetadataContext) { log.info("Looking up entity callbacks"); final Collection<Class<?>> entityTypes = tableMetadataContext.getEntityTypes(); eventHandlers.add(new EntityEventCallback()); for (Class<?> entityType : entityTypes) { if (entityType.isAnnotationPresent(EntityListeners.class)) { final EntityListeners listeners = entityType.getAnnotation(EntityListeners.class); for (final Class type : listeners.value()) { log.info("Registering external callback: " + type); eventHandlers.add(new EntityEventCallback(entityType, type)); }/* ww w . j a va2s. com*/ } } handlersFound = true; if (contextFound) { registerHandlers(); } }
From source file:com.braffdev.server.core.module.containerhandler.mapper.clazz.ClassMapper.java
/** * @param clazz/* w w w .j a va2 s . c o m*/ * @return */ private boolean isServlet(Class<?> clazz) { return clazz.isAnnotationPresent(Controller.class); }
From source file:com.braffdev.server.core.module.containerhandler.mapper.clazz.ClassMapper.java
/** * @param clazz/* w w w. ja v a2 s .co m*/ * @return */ private boolean isComponent(Class<?> clazz) { return clazz.isAnnotationPresent(Component.class); }
From source file:support.RightSeeker.java
public RightStack createSpringRightsFromJar(Class startclass, String prefix) throws Exception { mapping = new HashMap(); RightStack result = RightStack.getInstance(prefix); Collection string = JarScan.scanClasses(JarScan.getFilePathToClasses(startclass)); for (Object cls : string) { Class cl = Class.forName(cls.toString()); if (cl.isAnnotationPresent(org.springframework.stereotype.Controller.class)) { Object obj = cl.newInstance(); Method[] methods = obj.getClass().getDeclaredMethods(); for (Method method : methods) { String mappingName = ""; if (cl.isAnnotationPresent(RequestMapping.class)) { RequestMapping rm = (RequestMapping) cl.getAnnotation(RequestMapping.class); if (rm.value().length > 0) { mappingName = rm.value()[0]; }//from ww w . j a va 2 s. com } if (method.isAnnotationPresent(support.commons.Right.class)) { support.commons.Right methAnn = method.getAnnotation(support.commons.Right.class); if (method.isAnnotationPresent(RequestMapping.class)) { RequestMapping rmmethod = method.getAnnotation(RequestMapping.class); if (rmmethod.value().length > 0) { mappingName += rmmethod.value()[0]; } } String action = method.getName(); if (StringAdapter.NotNull(methAnn.name())) { action = methAnn.name(); } Right rt = result.add(cl.getName(), action, cl.getName(), methAnn.description()); if (StringAdapter.NotNull(mappingName)) { mapping.put(mappingName, rt); } } } } } return result; }
From source file:gumga.framework.application.GumgaUntypedRepository.java
private List<Class> getAllIndexedEntities() { List<Class> aRetornar = new ArrayList<>(); Session session = em.unwrap(Session.class); SessionFactory sessionFactory = session.getSessionFactory(); Map<String, ClassMetadata> map = (Map<String, ClassMetadata>) sessionFactory.getAllClassMetadata(); for (String k : map.keySet()) { Class mappedClass = map.get(k).getMappedClass(); if (mappedClass.isAnnotationPresent(Entity.class) && mappedClass.isAnnotationPresent(Indexed.class)) { aRetornar.add(mappedClass);//from w ww . j a v a2 s .co m } } return aRetornar; }
From source file:com.jroossien.boxx.nms.NMS.java
public <T> Object loadFromNMS(Class<T> dep) { if (!dep.isAnnotationPresent(NMSDependant.class)) return null; NMSDependant nmsDependant = dep.getAnnotation(NMSDependant.class); Class<?> impl = null;/*w w w .j a v a 2 s . com*/ try { impl = Class.forName(nmsDependant.implementationPath() + "." + dep.getSimpleName() + "_" + version); return impl.newInstance(); } catch (ClassNotFoundException e) { Boxx.get().error("The current version is not supported: " + version + ".\n" + e.getMessage()); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } return impl; }
From source file:org.b3log.latke.servlet.RequestProcessors.java
/** * Scans classpath (classes directory) to discover request processor classes. *//* w ww . j a v a2 s . co m*/ private static void discoverFromClassesDir() { final String webRoot = AbstractServletListener.getWebRoot(); final File classesDir = new File( webRoot + File.separator + "WEB-INF" + File.separator + "classes" + File.separator); @SuppressWarnings("unchecked") final Collection<File> classes = FileUtils.listFiles(classesDir, new String[] { "class" }, true); final ClassLoader classLoader = RequestProcessors.class.getClassLoader(); try { for (final File classFile : classes) { final String path = classFile.getPath(); final String className = StringUtils .substringBetween(path, "WEB-INF" + File.separator + "classes" + File.separator, ".class") .replaceAll("\\/", ".").replaceAll("\\\\", "."); final Class<?> clz = classLoader.loadClass(className); if (clz.isAnnotationPresent(RequestProcessor.class)) { LOGGER.log(Level.FINER, "Found a request processor[className={0}]", className); final Method[] declaredMethods = clz.getDeclaredMethods(); for (int i = 0; i < declaredMethods.length; i++) { final Method mthd = declaredMethods[i]; final RequestProcessing annotation = mthd.getAnnotation(RequestProcessing.class); if (null == annotation) { continue; } addProcessorMethod(annotation, clz, mthd); } } } } catch (final Exception e) { LOGGER.log(Level.SEVERE, "Scans classpath (classes directory) failed", e); } }