List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
private List<ParamValidator> findContextValidators(XmlWebApplicationContext context) { String[] validatorNames = SpringUtils.getBeanNames(context.getBeanFactory(), ParamValidator.class); ArrayList<ParamValidator> globalValidators = new ArrayList<ParamValidator>(validatorNames.length); for (String beanName : validatorNames) { ParamValidator validator = (ParamValidator) context.getBean(beanName); Class<?> userClass = ClassUtils.getUserClass(validator); if (userClass.isAnnotationPresent(Ignored.class)) { if (logger.isDebugEnabled()) { logger.debug("Ignored context validator:" + validator); }//from w w w .j av a 2 s . c o m continue; } if (userClass.isAnnotationPresent(NotForSubModules.class) && context.getBeanFactory().getBeanDefinition(beanName) == null) { if (logger.isDebugEnabled()) { logger.debug("Ignored context validator (NotForSubModules):" + validator); } continue; } globalValidators.add(validator); if (logger.isDebugEnabled()) { logger.debug("add context validator: " + userClass.getName()); } } return globalValidators; }
From source file:org.lunarray.model.descriptor.builder.annotation.base.listener.entity.ProcessCreational.java
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override// www . j a va2s . c o m public void handleEvent(final UpdatedEntityTypeEvent<E, K, B> event) throws EventException { ProcessCreational.LOGGER.debug("Handling event {}", event); Validate.notNull(event, "Event may not be null."); final ProcessingContext ctx = new ProcessingContext(); ctx.setEntity(event.getEntity()); ctx.setType(ctx.getEntity().getEntityType()); ctx.setConstructor(CreationalScanUtil.findConstructor(ctx.getType())); ctx.setBuilder(event.getBuilder()); final AnnotationEntityDescriptorBuilder<E, ?, B> builder = ctx.getBuilder(); final ExtensionContainer container = builder.getBuilderContext().getExtensionContainer(); ctx.setConverter(container.getExtension(ConverterTool.class)); final ExtensionRef<ObjectFactory> factory = container.getExtensionRef(ObjectFactory.class); ctx.setFactory(factory); final ExtensionRef<Registry<N>> registry = container.getExtensionRef(Registry.class); ctx.setRegistry(registry); final Class<E> type = ctx.getType(); if (type.isAnnotationPresent(Impl.class)) { final Impl implAnn = type.getAnnotation(Impl.class); final Class<?> tentativeImpl = implAnn.value(); if (type.isAssignableFrom(tentativeImpl)) { ctx.setImpl((Class<F>) tentativeImpl); ctx.setImplConstructor(CreationalScanUtil.findConstructor(ctx.getImpl())); } } if (!CheckUtil.isNull(registry)) { final Registry<N> registryInstance = registry.get(); final Type registryTypeTmp = GenericsUtil.getEntityGenericType(registryInstance.getClass(), 0, Registry.class); if (registryTypeTmp instanceof Class) { ctx.setRegistryType((Class<N>) registryTypeTmp); } } this.registerFactoryMethods(ctx); if (!this.factories(ctx)) { this.handleConstructors(ctx); } }
From source file:org.apache.syncope.client.console.init.ClassPathScanImplementationLookup.java
@SuppressWarnings("unchecked") public void load() { pages = new ArrayList<>(); previewers = new ArrayList<>(); extPages = new ArrayList<>(); extWidgets = new ArrayList<>(); ssoLoginFormPanels = new ArrayList<>(); reportletConfs = new HashMap<>(); accountRuleConfs = new HashMap<>(); passwordRuleConfs = new HashMap<>(); pullCorrelationRuleConfs = new HashMap<>(); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false);/* w w w . j a v a 2s .c o m*/ scanner.addIncludeFilter(new AssignableTypeFilter(BasePage.class)); scanner.addIncludeFilter(new AssignableTypeFilter(AbstractBinaryPreviewer.class)); scanner.addIncludeFilter(new AssignableTypeFilter(BaseExtPage.class)); scanner.addIncludeFilter(new AssignableTypeFilter(BaseExtWidget.class)); scanner.addIncludeFilter(new AssignableTypeFilter(SSOLoginFormPanel.class)); scanner.addIncludeFilter(new AssignableTypeFilter(ReportletConf.class)); scanner.addIncludeFilter(new AssignableTypeFilter(AccountRuleConf.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PasswordRuleConf.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PullCorrelationRuleConf.class)); scanner.findCandidateComponents(getBasePackage()).forEach(bd -> { try { Class<?> clazz = ClassUtils.resolveClassName(bd.getBeanClassName(), ClassUtils.getDefaultClassLoader()); boolean isAbsractClazz = Modifier.isAbstract(clazz.getModifiers()); if (!isAbsractClazz) { if (BaseExtPage.class.isAssignableFrom(clazz)) { if (clazz.isAnnotationPresent(ExtPage.class)) { extPages.add((Class<? extends BaseExtPage>) clazz); } else { LOG.error("Could not find annotation {} in {}, ignoring", ExtPage.class.getName(), clazz.getName()); } } else if (BaseExtWidget.class.isAssignableFrom(clazz)) { if (clazz.isAnnotationPresent(ExtWidget.class)) { extWidgets.add((Class<? extends BaseExtWidget>) clazz); } else { LOG.error("Could not find annotation {} in {}, ignoring", ExtWidget.class.getName(), clazz.getName()); } } else if (BasePage.class.isAssignableFrom(clazz)) { pages.add((Class<? extends BasePage>) clazz); } else if (AbstractBinaryPreviewer.class.isAssignableFrom(clazz)) { previewers.add((Class<? extends AbstractBinaryPreviewer>) clazz); } else if (SSOLoginFormPanel.class.isAssignableFrom(clazz)) { ssoLoginFormPanels.add((Class<? extends SSOLoginFormPanel>) clazz); } else if (ReportletConf.class.isAssignableFrom(clazz)) { reportletConfs.put(clazz.getName(), (Class<? extends ReportletConf>) clazz); } else if (AccountRuleConf.class.isAssignableFrom(clazz)) { accountRuleConfs.put(clazz.getName(), (Class<? extends AccountRuleConf>) clazz); } else if (PasswordRuleConf.class.isAssignableFrom(clazz)) { passwordRuleConfs.put(clazz.getName(), (Class<? extends PasswordRuleConf>) clazz); } else if (PullCorrelationRuleConf.class.isAssignableFrom(clazz)) { pullCorrelationRuleConfs.put(clazz.getName(), (Class<? extends PullCorrelationRuleConf>) clazz); } } } catch (Throwable t) { LOG.warn("Could not inspect class {}", bd.getBeanClassName(), t); } }); pages = Collections.unmodifiableList(pages); previewers = Collections.unmodifiableList(previewers); Collections.sort(extPages, (o1, o2) -> ObjectUtils.compare(o1.getAnnotation(ExtPage.class).priority(), o2.getAnnotation(ExtPage.class).priority())); extPages = Collections.unmodifiableList(extPages); Collections.sort(extWidgets, (o1, o2) -> ObjectUtils.compare(o1.getAnnotation(ExtWidget.class).priority(), o2.getAnnotation(ExtWidget.class).priority())); extWidgets = Collections.unmodifiableList(extWidgets); ssoLoginFormPanels = Collections.unmodifiableList(ssoLoginFormPanels); reportletConfs = Collections.unmodifiableMap(reportletConfs); accountRuleConfs = Collections.unmodifiableMap(accountRuleConfs); passwordRuleConfs = Collections.unmodifiableMap(passwordRuleConfs); pullCorrelationRuleConfs = Collections.unmodifiableMap(pullCorrelationRuleConfs); LOG.debug("Binary previewers found: {}", previewers); LOG.debug("Extension pages found: {}", extPages); LOG.debug("Extension widgets found: {}", extWidgets); LOG.debug("SSO Login pages found: {}", ssoLoginFormPanels); LOG.debug("Reportlet configurations found: {}", reportletConfs); LOG.debug("Account Rule configurations found: {}", accountRuleConfs); LOG.debug("Password Rule configurations found: {}", passwordRuleConfs); LOG.debug("Pull Correlation Rule configurations found: {}", pullCorrelationRuleConfs); }
From source file:com.wit.android.support.fragment.manage.BaseFragmentFactory.java
/** * Gathers all classes of fragment factories presented within FragmentFactories annotation. Note, * that this is recursive method, which will gather all classes from * {@link com.wit.android.support.fragment.annotation.FragmentFactories @FragmentFactories} * annotation presented above the given <var>classOfFragment</var>. * * @param classOfFactory Class of fragment where to check FragmentFactories annotation. * @param factories List of already gathered factories. * @return List of all gathered classes of fragment factories. *///from www. jav a 2s . c o m private List<Class<? extends FragmentController.FragmentFactory>> gatherJoinedFactories(Class<?> classOfFactory, List<Class<? extends FragmentController.FragmentFactory>> factories) { if (classOfFactory.isAnnotationPresent(FragmentFactories.class)) { final FragmentFactories fragmentFactories = classOfFactory.getAnnotation(FragmentFactories.class); if (fragmentFactories.value().length > 0) { factories.addAll(Arrays.asList(fragmentFactories.value())); } } // Obtain also factories of super class, but only to this BaseFragmentFactory super. final Class<?> superOfFactory = classOfFactory.getSuperclass(); if (superOfFactory != null && !classOfFactory.equals(BaseFragmentFactory.class)) { gatherJoinedFactories(superOfFactory, factories); } return factories; }
From source file:org.jspare.jsdbc.JsdbcImpl.java
@Override public Result persist(Object data) throws JsdbcException { try {/* w w w. ja va2 s . co m*/ Class<?> clazz = data.getClass(); if (!clazz.isAnnotationPresent(Entity.class)) { throw new JsdbcException( String.format("Not found annotation @Entity on class [%s]", clazz.getName())); } Entity entity = data.getClass().getAnnotation(Entity.class); String domain = entity.domain(); String key = EntityUtils.findKeyByEntity(entity, data); PersistRequest request = new PersistRequest(domain, key, data); String req = serializer.toJSON(request); String result = callJsdbServer(OPER_PERSIST, JsdbcTransport.SEND, Optional.of(Domain.of(entity.domain())), req); return serializer.fromJSON(result, Result.class); } catch (SerializationException e) { throw new JsdbcException("Fail on parse result"); } }
From source file:de.matzefratze123.heavyspleef.core.flag.FlagRegistry.java
public void registerFlag(Class<? extends AbstractFlag<?>> clazz) { Validate.notNull(clazz, "clazz cannot be null"); Validate.isTrue(!registeredFlagsMap.containsValue(clazz), "Cannot register flag twice"); /* Check if the class provides the required Flag annotation */ Validate.isTrue(clazz.isAnnotationPresent(Flag.class), "Flag-Class must be annotated with the @Flag annotation"); Flag flagAnnotation = clazz.getAnnotation(Flag.class); String name = flagAnnotation.name(); Validate.isTrue(!name.isEmpty(),//from ww w . j av a 2 s. c o m "name() of annotation of flag for class " + clazz.getCanonicalName() + " cannot be empty"); /* Generate a path */ StringBuilder pathBuilder = new StringBuilder(); Flag parentFlagData = flagAnnotation; do { pathBuilder.insert(0, parentFlagData.name()); Class<? extends AbstractFlag<?>> parentFlagClass = parentFlagData.parent(); parentFlagData = parentFlagClass.getAnnotation(Flag.class); if (parentFlagData != null && parentFlagClass != NullFlag.class) { pathBuilder.insert(0, FLAG_PATH_SEPERATOR); } } while (parentFlagData != null); String path = pathBuilder.toString(); /* Check for name collides */ for (String flagPath : registeredFlagsMap.primaryKeySet()) { if (flagPath.equalsIgnoreCase(path)) { throw new IllegalArgumentException( "Flag " + clazz.getName() + " collides with " + registeredFlagsMap.get(flagPath).getName()); } } /* Check if the class can be instantiated */ try { Constructor<? extends AbstractFlag<?>> constructor = clazz.getDeclaredConstructor(); //Make the constructor accessible for future uses constructor.setAccessible(true); } catch (NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException("Flag-Class must provide an empty constructor"); } HookManager hookManager = heavySpleef.getHookManager(); boolean allHooksPresent = true; for (HookReference ref : flagAnnotation.depend()) { if (!hookManager.getHook(ref).isProvided()) { allHooksPresent = false; } } if (allHooksPresent) { for (Method method : clazz.getDeclaredMethods()) { if (!method.isAnnotationPresent(FlagInit.class)) { continue; } if ((method.getModifiers() & Modifier.STATIC) == 0) { throw new IllegalArgumentException("Flag initialization method " + method.getName() + " in type " + clazz.getCanonicalName() + " is not declared as static"); } queuedInitMethods.add(method); } if (flagAnnotation.hasCommands()) { CommandManager manager = heavySpleef.getCommandManager(); manager.registerSpleefCommands(clazz); } } registeredFlagsMap.put(path, flagAnnotation, clazz); }
From source file:com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.java
public boolean isAcceptableInterface(DfsContext dfsContext, Class<?> aClass) { return aClass.isAnnotationPresent(GraphQLInterface.class); }
From source file:org.jspare.jsdbc.JsdbcImpl.java
@Override public Result persist(Domain domain, List<?> entities) throws JsdbcException { Map<String, Object> data = new HashMap<>(); try {/*from w w w. j a v a 2s . c om*/ for (Object obj : entities) { Class<?> clazz = obj.getClass(); if (!clazz.isAnnotationPresent(Entity.class)) { throw new JsdbcException( String.format("Not found annotation @Entity on class [%s]", clazz.getName())); } Entity entity = obj.getClass().getAnnotation(Entity.class); String key = EntityUtils.findKeyByEntity(entity, obj); data.put(key, obj); } PersistBatchRequest request = new PersistBatchRequest(data); String req = serializer.toJSON(request.getEntities()); String result = callJsdbServer(OPER_PERSIST_BATCH, JsdbcTransport.SEND, Optional.of(domain), req); return serializer.fromJSON(result, Result.class); } catch (SerializationException e) { throw new JsdbcException("Fail on parse result"); } }
From source file:org.jboss.jaxb.intros.IntroductionsAnnotationReader.java
public boolean hasClassAnnotation(Class clazz, Class<? extends Annotation> annotationType) { ClassIntroConfig classAnnotations = getClassIntroConfig(clazz); if (classAnnotations != null) { return isClassAnnotationIntroAvailable(annotationType, classAnnotations); }//w w w . jav a 2 s. com return clazz.isAnnotationPresent(annotationType); }
From source file:de.xaniox.heavyspleef.core.flag.FlagManager.java
public void enableFlag(Class<? extends AbstractFlag<?>> clazz, FlagRegistry registry, Game game) { Validate.isTrue(!isFlagPresent(clazz)); Validate.isTrue(clazz.isAnnotationPresent(Flag.class)); Flag flagAnnotation = clazz.getAnnotation(Flag.class); String path = generatePath(flagAnnotation); Validate.isTrue(disabledFlags.contains(path), "Flag is not disabled"); AbstractFlag<?> flag = registry.newFlagInstance(path, AbstractFlag.class, game); if (clazz.isAnnotationPresent(BukkitListener.class)) { Bukkit.getPluginManager().registerEvents(flag, plugin); }/* w ww.j a va2 s . co m*/ if (flagAnnotation.hasGameProperties()) { Map<GameProperty, Object> flagGamePropertiesMap = new EnumMap<GameProperty, Object>(GameProperty.class); flag.defineGameProperties(flagGamePropertiesMap); if (!flagGamePropertiesMap.isEmpty()) { GamePropertyBundle properties = new GamePropertyBundle(flag, flagGamePropertiesMap); propertyBundles.add(properties); } } if (flagAnnotation.parent() != NullFlag.class) { AbstractFlag<?> parent = getFlag(flagAnnotation.parent()); flag.setParent(parent); } flags.put(path, flag); disabledFlags.remove(path); }