List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:nl.knaw.dans.common.lang.search.bean.SearchBeanUtil.java
private static void checkSearchBean(Class<?> sbClass) throws ObjectIsNotASearchBeanException { if (!sbClass.isAnnotationPresent(SearchBean.class)) throw new ObjectIsNotASearchBeanException(sbClass.toString()); }
From source file:org.sonatype.nexus.guice.NexusTypeBinder.java
/** * Scans the implementation's declared interfaces for one annotated with {@link RepositoryType}. *//*from w ww .j av a 2 s . c om*/ private static Class<?> getRepositoryRole(final Class<?> implementation) { for (Class<?> api : implementation.getInterfaces()) { if (api.isAnnotationPresent(RepositoryType.class)) { return api; } } return null; }
From source file:com.liferay.apio.architect.internal.annotation.representor.processor.TypeProcessor.java
private static void _addListType(Builder builder, Method method, Class<?> listClass) { if (listClass.isAnnotationPresent(Type.class)) { ParsedType parsedType = _processType(listClass, true); builder.addListParsedType(new FieldData<>(method, parsedType)); } else {//from w w w .j a v a2s . c o m FieldData<Class<?>> listFieldData = new FieldData<>(method, listClass); builder.addListFieldData(listFieldData); } }
From source file:com.liferay.apio.architect.internal.annotation.representor.processor.TypeProcessor.java
private static void _addFields(Builder builder, Method method, Class<?> returnType) { if (returnType.isAnnotationPresent(Type.class)) { ParsedType parsedType = _processType(returnType, true); builder.addParsedType(new FieldData<>(method, parsedType)); } else {//from w w w.j a v a 2 s .co m FieldData fieldData = new FieldData<>(method, returnType); builder.addFieldData(fieldData); } }
From source file:org.sonatype.nexus.guice.NexusTypeBinder.java
/** * Checks for both kinds of @Named; uses fully-qualified classname if name is missing or blank. *///w ww . j a v a 2 s .c o m private static String getRepositoryHint(final Class<?> implementation) { String name = null; if (implementation.isAnnotationPresent(javax.inject.Named.class)) { name = implementation.getAnnotation(javax.inject.Named.class).value(); } else if (implementation.isAnnotationPresent(com.google.inject.name.Named.class)) { name = implementation.getAnnotation(com.google.inject.name.Named.class).value(); } return StringUtils.isNotBlank(name) ? name : implementation.getName(); }
From source file:com.sqewd.open.dal.services.EntitySchema.java
public static EntitySchema loadSchema(Class<?> type) throws Exception { if (!type.isAnnotationPresent(Entity.class)) throw new Exception("Class [" + type.getCanonicalName() + "] has not been annotated as an Entity."); StructEntityReflect enref = ReflectionUtils.get().getEntityMetadata(type); return loadSchema(enref); }
From source file:com.apifest.oauth20.LifecycleEventHandlers.java
@SuppressWarnings("unchecked") public static void loadLifecycleHandlers(URLClassLoader classLoader, String customJar) { try {//from www .j a v a 2 s. c o m if (classLoader != null) { JarFile jarFile = new JarFile(customJar); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.isDirectory() || !entry.getName().endsWith(".class")) { continue; } // remove .class String className = entry.getName().substring(0, entry.getName().length() - 6); className = className.replace('/', '.'); try { // REVISIT: check for better solution if (className.startsWith("org.jboss.netty") || className.startsWith("org.apache.log4j") || className.startsWith("org.apache.commons")) { continue; } Class<?> clazz = classLoader.loadClass(className); if (clazz.isAnnotationPresent(OnRequest.class) && LifecycleHandler.class.isAssignableFrom(clazz)) { requestEventHandlers.add((Class<LifecycleHandler>) clazz); log.debug("preIssueTokenHandler added {}", className); } if (clazz.isAnnotationPresent(OnResponse.class) && LifecycleHandler.class.isAssignableFrom(clazz)) { responseEventHandlers.add((Class<LifecycleHandler>) clazz); log.debug("postIssueTokenHandler added {}", className); } if (clazz.isAnnotationPresent(OnException.class) && ExceptionEventHandler.class.isAssignableFrom(clazz)) { exceptionHandlers.add((Class<ExceptionEventHandler>) clazz); log.debug("exceptionHandlers added {}", className); } } catch (ClassNotFoundException e1) { // continue } } } } catch (MalformedURLException e) { log.error("cannot load lifecycle handlers", e); } catch (IOException e) { log.error("cannot load lifecycle handlers", e); } catch (IllegalArgumentException e) { log.error(e.getMessage()); } }
From source file:jp.rikinet.util.dto.DtoFactory.java
/** * JSON ?????????/*www . ja v a2 s . c o m*/ * ????? * @param clazz Root ?? */ public static void register(Class<? extends Root> clazz) { if (!clazz.isAnnotationPresent(DtoType.class)) return; DtoType dt = clazz.getAnnotation(DtoType.class); classTable.put(dt.value(), clazz); }
From source file:org.apache.sling.contextaware.config.impl.metadata.AnnotationClassParser.java
/** * Checks if the given class is suitable to be mapped with context-aware configuration. * The given class has to be an annotation class, and the {@link Configuration} annotation has to be present. * @param clazz Given class// www . j a v a 2 s . c o m * @return True if class is suitable for context-aware configuration */ public static boolean isContextAwareConfig(Class<?> clazz) { return clazz.isAnnotation() && clazz.isAnnotationPresent(Configuration.class); }
From source file:org.panthercode.arctic.core.reflect.ReflectionUtils.java
/** * Filters a list of classes with a given pattern. * * @param classList list with classes/*from w w w . j a v a 2s . co m*/ * @param filter pattern for filtering * @return Returns a filtered list. * @throws NullPointerException Is thrown if one of the parameters is <tt>null</tt>. */ public static List<Class<?>> filterClassListByAnnotation(final List<Class<?>> classList, final Class<? extends Annotation> filter) throws NullPointerException { ArgumentUtils.assertNotNull(classList, "list"); ArgumentUtils.assertNotNull(filter, "filter"); final List<Class<?>> filteredList = new ArrayList<>(); for (Class<?> clazz : classList) { if (clazz.isAnnotationPresent(filter)) { filteredList.add(clazz); } } return filteredList; }