List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:com.proofpoint.jaxrs.JaxrsModule.java
private static boolean isJaxRsType(Class<?> type) { if (type == null) { return false; }// w w w . j a v a 2 s . c om if (type.isAnnotationPresent(Provider.class)) { return true; } else if (type.isAnnotationPresent(Path.class)) { return true; } if (isJaxRsType(type.getSuperclass())) { return true; } for (Class<?> typeInterface : type.getInterfaces()) { if (isJaxRsType(typeInterface)) { return true; } } return false; }
From source file:edu.stanford.epad.common.plugins.impl.ClassFinderTestUtils.java
public static boolean hasAnnotation(Class<?> testClass, Class<? extends Annotation> annotationClass) { return testClass.isAnnotationPresent(annotationClass); }
From source file:org.apache.abdera2.factory.AbstractExtensionFactory.java
private static void addImpls(Object obj, Map<QName, Constructor<? extends ElementWrapper>> map) { if (obj == null) return;//from w ww . j a va2 s .co m Class<?> _class = obj instanceof Class ? (Class<?>) obj : obj.getClass(); if (_class.isAnnotationPresent(Impls.class)) { log.debug("@Impls annotation found... processing"); Impls impls = _class.getAnnotation(Impls.class); Impl[] imps = impls.value(); for (Impl impl : imps) { log.debug(String.format("Processing >> %s", impl.value().getName())); QName qname = AnnoUtil.qNameFromAnno(impl.qname()); Class<? extends ElementWrapper> _impl = impl.value(); if (qname == null) { if (_impl.isAnnotationPresent(org.apache.abdera2.common.anno.QName.class)) { org.apache.abdera2.common.anno.QName qn = _impl .getAnnotation(org.apache.abdera2.common.anno.QName.class); qname = AnnoUtil.qNameFromAnno(qn); } } if (qname != null) { log.debug(String.format(" Discovered QName: %s", qname.toString())); Constructor<? extends ElementWrapper> con = constructor(_impl); if (con != null) { map.put(qname, con); } else log.debug( " An appropriate ElementWrapper constructor could not be found! Ignoring implementation class"); } else log.debug(" A QName could not be found. Ignoring implementation class"); } } }
From source file:com.manydesigns.portofino.logic.SecurityLogic.java
public static boolean satisfiesRequiresAdministrator(HttpServletRequest request, ActionBean actionBean, Method handler) {/* w w w . j a va 2 s. c o m*/ logger.debug("Checking if action or method required administrator"); boolean requiresAdministrator = false; if (handler.isAnnotationPresent(RequiresAdministrator.class)) { logger.debug("Action method requires administrator: {}", handler); requiresAdministrator = true; } else { Class actionClass = actionBean.getClass(); while (actionClass != null) { if (actionClass.isAnnotationPresent(RequiresAdministrator.class)) { logger.debug("Action class requires administrator: {}", actionClass); requiresAdministrator = true; break; } actionClass = actionClass.getSuperclass(); } } boolean isNotAdmin = !isAdministrator(request); boolean doesNotSatisfy = requiresAdministrator && isNotAdmin; if (doesNotSatisfy) { logger.info("User is not an administrator"); return false; } return true; }
From source file:org.opensingular.flow.core.Flow.java
public static String getKeyFromDefinition(Class<? extends ProcessDefinition> clazz) { if (clazz == null) { throw new SingularFlowException(" A classe de definio do fluxo no pode ser nula "); }/* ww w. jav a2s.c o m*/ if (!clazz.isAnnotationPresent(DefinitionInfo.class)) { throw new SingularFlowException( "A definio de fluxo deve ser anotada com " + DefinitionInfo.class.getName()); } String key = clazz.getAnnotation(DefinitionInfo.class).value(); if (StringUtils.isBlank(key)) { throw new SingularFlowException( "A chave definida na anitao" + DefinitionInfo.class.getName() + " no pode ser nula"); } return key; }
From source file:net.ymate.platform.plugin.Plugins.java
/** * @param clazz ?/*from ww w . j ava2 s . c o m*/ * @return ???? * @throws Exception ?? */ private static DefaultPluginConfig loadConfig(Class<? extends IPluginFactory> clazz) throws Exception { DefaultPluginConfig _config = null; if (clazz != null && clazz.isAnnotationPresent(PluginFactory.class)) { _config = new DefaultPluginConfig(); // PluginFactory _factoryAnno = clazz.getAnnotation(PluginFactory.class); if (StringUtils.isNotBlank(_factoryAnno.pluginHome())) { _config.setPluginHome(new File(_factoryAnno.pluginHome())); } String[] _packages = _factoryAnno.autoscanPackages(); if (ArrayUtils.isEmpty(_packages)) { _packages = new String[] { clazz.getPackage().getName() }; } _config.setAutoscanPackages(Arrays.asList(_packages)); _config.setIncludedClassPath(_factoryAnno.includedClassPath()); _config.setAutomatic(_factoryAnno.automatic()); // IPluginEventListener _listener = ClassUtils.impl(_factoryAnno.listenerClass(), IPluginEventListener.class); if (_listener != null) { _config.setPluginEventListener(_listener); } else { _config.setPluginEventListener(new DefaultPluginEventListener()); } } return _config; }
From source file:com.palantir.ptoss.util.Reflections.java
/** * Checks whether or not the specified {@link Annotation} exists in the passed {@link Object}'s * class hierarchy.//w ww . j av a 2 s .com * @param object object to check * @param annotation annotation to look for * @return true is a class in this passed object's type hierarchy is annotated with the * passed {@link Annotation} */ public static boolean isClassAnnotatedForClassHierarchy(Object object, final Class<? extends Annotation> annotation) { final MutableBoolean bool = new MutableBoolean(false); visitClassHierarchy(object.getClass(), new Visitor<Class<?>>() { public void visit(Class<?> klass) { if (klass.isAnnotationPresent(annotation)) { bool.setValue(true); } } }); return bool.booleanValue(); }
From source file:org.vaadin.addons.springsecurityviewprovider.SpringSecurityViewProvider.java
@SuppressWarnings("unchecked") public final static ViewProvider createViewProvider(final Authentication authentication, Boolean enableCaching) {/*from w w w.j a v a2 s . c om*/ final SpringSecurityViewProvider springViewProvider = new SpringSecurityViewProvider(); springViewProvider.enableCaching = enableCaching; try { final ApplicationContext applicationContext = springViewProvider.applicationContext; // Retrieve the default SecurityExpressionHandler final MethodSecurityExpressionHandler securityExpressionHandler = applicationContext .getBean(DefaultMethodSecurityExpressionHandler.class); // The method that is protected in the end final Method getViewMethod = SpringSecurityViewProvider.class.getMethod("getView", String.class); // A parser to evaluate parse the permissions. final SpelExpressionParser parser = new SpelExpressionParser(); // Although beans can be retrieved by annotation they must be retrieved by name // to avoid instanciating them for (String beanName : applicationContext.getBeanDefinitionNames()) { final Class<?> beanClass = applicationContext.getType(beanName); // only work with Views that are described by our specialed Description if (beanClass.isAnnotationPresent(ViewDescription.class) && View.class.isAssignableFrom(beanClass)) { final ViewDescription viewDescription = beanClass.getAnnotation(ViewDescription.class); // requires no special permissions and can be immediatly added if (StringUtils.isBlank(viewDescription.requiredPermissions())) { springViewProvider.views.put(viewDescription.name(), (Class<? extends View>) beanClass); } // requires permissions else { // this is actually borrowed from the code in org.springframework.security.access.prepost.PreAuthorize final EvaluationContext evaluationContext = securityExpressionHandler .createEvaluationContext(authentication, new SimpleMethodInvocation( springViewProvider, getViewMethod, viewDescription.name())); // only add the view to my provider if the permissions evaluate to true if (ExpressionUtils.evaluateAsBoolean( parser.parseExpression(viewDescription.requiredPermissions()), evaluationContext)) springViewProvider.views.put(viewDescription.name(), (Class<? extends View>) beanClass); } } } } catch (NoSuchMethodException | SecurityException e) { // Won't happen } return springViewProvider; }
From source file:corner.orm.gae.GaeModule.java
public static void contributeValueEncoderSource(MappedConfiguration<Class, ValueEncoderFactory> configuration, final TypeCoercer typeCoercer, final PropertyAccess propertyAccess, final LoggerSource loggerSource, final EntityPackageManager packageManager, final ClassNameLocator classNameLocator, @Local final EntityManager entityManager) { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); for (String packageName : packageManager.getPackageNames()) { for (String className : classNameLocator.locateClassNames(packageName)) { try { final Class<?> entityClass = contextClassLoader.loadClass(className); if (entityClass.isAnnotationPresent(Entity.class)) { ValueEncoderFactory factory = new ValueEncoderFactory() { /** * @see org.apache.tapestry5.services.ValueEncoderFactory#create(java.lang.Class) *///from www . ja va 2s . c o m @Override public ValueEncoder create(Class type) { return new JpaEntityValueEncoder(entityClass, propertyAccess, typeCoercer, loggerSource.getLogger(entityClass), entityManager); } }; configuration.add(entityClass, factory); } } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } } } }
From source file:com.streamsets.datacollector.definition.StageDefinitionExtractor.java
public static List<String> getGroups(Class<? extends Stage> klass) { Set<String> set = new LinkedHashSet<>(); addGroupsToList(klass, set);/* ww w .j av a2 s .c om*/ List<Class<?>> allSuperclasses = ClassUtils.getAllSuperclasses(klass); for (Class<?> superClass : allSuperclasses) { if (!superClass.isInterface() && superClass.isAnnotationPresent(ConfigGroups.class)) { addGroupsToList(superClass, set); } } if (set.isEmpty()) { set.add(""); // the default empty group } return new ArrayList<>(set); }