List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:com.impetus.kundera.metadata.processor.IndexProcessor.java
public final void process(final Class<?> clazz, EntityMetadata metadata) { metadata.setIndexName(clazz.getSimpleName()); Index idx = clazz.getAnnotation(Index.class); if (null != idx) { boolean isIndexable = idx.index(); metadata.setIndexable(isIndexable); if (!isIndexable) { log.debug("@Entity " + clazz.getName() + " will not be indexed."); return; }//from w w w . j av a 2 s . co m } log.debug("Processing @Entity " + clazz.getName() + " for Indexes."); // scan for fields for (Field f : clazz.getDeclaredFields()) { if (f.isAnnotationPresent(Column.class)) { Column c = f.getAnnotation(Column.class); String alias = c.name().trim(); if (alias.isEmpty()) { alias = f.getName(); } metadata.addIndexProperty(metadata.new PropertyIndex(f, alias)); } else if (f.isAnnotationPresent(Id.class)) { metadata.addIndexProperty(metadata.new PropertyIndex(f, f.getName())); } } }
From source file:jp.gr.java_conf.ka_ka_xyz.processor.AnnotationProcessor.java
public AnnotationProcessor(Class<?> clazz) { if (clazz != null) { Annotation classAnnotation = clazz.getAnnotation(Access.class); Access access = null;//from w w w. j ava 2 s. com if (classAnnotation instanceof Access) { access = (Access) classAnnotation; } boolean isFieldAccess = (access == null || AccessType.FIELD == access.value()); if (isFieldAccess) { List<Field> fields = new ArrayList<Field>(); getFields(clazz, fields); for (Field field : fields) { registerFieldAnnotation(field); } } else { Method[] methods = getMethods(clazz); for (Method method : methods) { registerMethodAnnotation(method, clazz); } } } }
From source file:com.javaforge.tapestry.acegi.service.impl.SecurityUtilsImpl.java
public Collection<ConfigAttribute> createConfigAttributeDefinition(Class securedClass) { Annotation a = securedClass.getAnnotation(Secured.class); String[] attributeTokens = ((Secured) a).value(); List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(attributeTokens.length); for (String token : attributeTokens) { attributes.add(new SecurityConfig(token)); }/*from www. j ava2 s . co m*/ return attributes; }
From source file:it.tidalwave.northernwind.frontend.impl.ui.DefaultViewFactory.java
/******************************************************************************************************************* * * ******************************************************************************************************************/ @PostConstruct//from www .j av a 2s .c o m /* package */ void initialize() // FIXME: gets called twice throws IOException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalArgumentException, IllegalAccessException, SecurityException { final ClassScanner classScanner = new ClassScanner().withAnnotationFilter(ViewMetadata.class); for (final Class<?> viewClass : classScanner.findClasses()) { final ViewMetadata viewMetadata = viewClass.getAnnotation(ViewMetadata.class); final String typeUri = viewMetadata.typeUri(); final ViewBuilder viewBuilder = new ViewBuilder(viewClass, viewMetadata.controlledBy()); viewBuilderMapByTypeUri.put(typeUri, viewBuilder); } if (logConfigurationEnabled) { logConfiguration(); } }
From source file:net.seedboxer.web.utils.mapper.Mapper.java
@PostConstruct public void init() throws ClassNotFoundException { if (packages != null) { mappings = new HashMap<Class<?>, Class<?>>(); List<Class<?>> annotated = new ArrayList<Class<?>>(); try {//w w w . j av a 2 s . c om for (String p : packages) { String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(SystemPropertyUtils.resolvePlaceholders(p)) + "/" + CLASS_RESOURCE_PATTERN; Resource[] resources = resourcePatternResolver.getResources(packageSearchPath); for (Resource resource : resources) { if (resource.isReadable()) { MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource); if (this.annotationFilter.match(metadataReader, metadataReaderFactory)) { annotated.add(Class.forName(metadataReader.getAnnotationMetadata().getClassName())); } } } } } catch (IOException ex) { throw new RuntimeException("I/O failure during classpath scanning", ex); } for (Class<?> clazz : annotated) { Class<?> toMap = clazz.getAnnotation(MAPPER_ANNOTATION).value(); // Binding One-to-One mappings.put(clazz, toMap); mappings.put(toMap, clazz); } } }
From source file:com.bstek.dorado.common.service.ExposedServiceAnnotationBeanPostProcessor.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) {/*from w w w . j a va 2 s. c o m*/ boolean defaultExposed = (beanType.getAnnotation(Expose.class) != null) && (beanType.getAnnotation(Unexpose.class) == null); for (Method method : beanType.getMethods()) { Expose annotation = method.getAnnotation(Expose.class); boolean exposed = defaultExposed || ((annotation != null) && (beanType.getAnnotation(Unexpose.class) == null)); if (!exposed) { continue; } pendingDataObjects.add(new PendingObject(annotation, beanName, method.getName())); } }
From source file:com.bstek.dorado.view.registry.DefaultComponentTypeRegister.java
@Override protected ComponentTypeRegisterInfo getRegisterInfo() throws Exception { String classType = getClassType(); if (StringUtils.isEmpty(classType)) { setClassType(getBeanName());//from w w w .ja v a 2 s . c o m } ComponentTypeRegisterInfo registerInfo = super.getRegisterInfo(); Class<? extends Component> cl = registerInfo.getClassType(); Widget widget = null; if (cl != null) { widget = cl.getAnnotation(Widget.class); if (widget != null) { dependsPackage = widget.dependsPackage(); } } registerInfo.setDependsPackage(dependsPackage); return registerInfo; }
From source file:org.vaadin.spring.navigator.Presenter.java
private String getViewName() { String result = null;/* w w w .ja v a2s . co m*/ Class<?> clazz = getClass(); if (clazz.isAnnotationPresent(VaadinPresenter.class)) { VaadinPresenter vp = clazz.getAnnotation(VaadinPresenter.class); result = vp.viewName(); } else { logger.error("Presenter [{}] does not have a @VaadinPresenter annotation!", clazz.getSimpleName()); } return result; }
From source file:cern.molr.mole.impl.RunnableSpringMole.java
@Override public void run(String missionContentClassName, Object... args) throws MissionExecutionException { if (null == missionContentClassName) { throw new MissionExecutionException( new IllegalArgumentException("Mission content class name cannot be null")); }/*from w ww .j a va 2s . c o m*/ try { Class<?> missionContentClass = Class.forName(missionContentClassName); MoleSpringConfiguration moleSpringConfigurationAnnotation = missionContentClass .getAnnotation(MoleSpringConfiguration.class); if (null == moleSpringConfigurationAnnotation) { throw new IllegalArgumentException(String.format("Mission content class must be annotated with %s", MoleSpringConfiguration.class.getName())); } ApplicationContext context = new ClassPathXmlApplicationContext( moleSpringConfigurationAnnotation.locations()); Object missionContentInstance = context.getBean(missionContentClass); if (!(missionContentInstance instanceof Runnable)) { throw new IllegalArgumentException(String .format("Mission content class must implement the %s interface", Runnable.class.getName())); } ((Runnable) missionContentInstance).run(); } catch (Exception exception) { throw new MissionExecutionException(exception); } }
From source file:com.flipkart.foxtrot.core.querystore.actions.spi.AnalyticsLoader.java
@Override public void start() throws Exception { Reflections reflections = new Reflections("com.flipkart.foxtrot", new SubTypesScanner()); Set<Class<? extends Action>> actions = reflections.getSubTypesOf(Action.class); if (actions.isEmpty()) { throw new Exception("No analytics actions found!!"); }//from w ww . ja va 2 s .co m List<NamedType> types = new ArrayList<>(); for (Class<? extends Action> action : actions) { AnalyticsProvider analyticsProvider = action.getAnnotation(AnalyticsProvider.class); if (null == analyticsProvider.request() || null == analyticsProvider.opcode() || analyticsProvider.opcode().isEmpty() || null == analyticsProvider.response()) { throw new Exception("Invalid annotation on " + action.getCanonicalName()); } if (analyticsProvider.opcode().equalsIgnoreCase("default")) { logger.warn("Action " + action.getCanonicalName() + " does not specify cache token. " + "Using default cache."); } register(new ActionMetadata(analyticsProvider.request(), action, analyticsProvider.cacheable(), analyticsProvider.opcode())); types.add(new NamedType(analyticsProvider.request(), analyticsProvider.opcode())); types.add(new NamedType(analyticsProvider.response(), analyticsProvider.opcode())); logger.info("Registered action: " + action.getCanonicalName()); } objectMapper.getSubtypeResolver().registerSubtypes(types.toArray(new NamedType[types.size()])); }