Example usage for java.lang Class getAnnotation

List of usage examples for java.lang Class getAnnotation

Introduction

In this page you can find the example usage for java.lang Class getAnnotation.

Prototype

@SuppressWarnings("unchecked")
public <A extends Annotation> A getAnnotation(Class<A> annotationClass) 

Source Link

Usage

From source file:com.github.rvesse.airline.model.MetadataLoader.java

public static <C> ParserMetadata<C> loadParser(Class<?> cliClass) {
    if (cliClass == null)
        return ParserBuilder.<C>defaultConfiguration();

    Annotation annotation = cliClass.getAnnotation(Parser.class);
    if (annotation == null)
        return ParserBuilder.<C>defaultConfiguration();

    return loadParser((Parser) annotation);
}

From source file:com.sf.ddao.crud.param.CRUDTableNameParameter.java

private synchronized void init(Context context) {
    if (tableName != null) {
        return;//  ww  w .ja  v  a 2s .c om
    }
    final Class<?> crudDaoBeanClass = getCRUDDaoBean(context, argNum);
    TableName tableName = crudDaoBeanClass.getAnnotation(TableName.class);
    if (tableName != null) {
        this.tableName = tableName.value();
    } else {
        this.tableName = crudDaoBeanClass.getSimpleName();
    }
}

From source file:hr.fer.zemris.vhdllab.platform.listener.AutoPublishListenerBeanPostProcessor.java

@SuppressWarnings("unchecked")
@Override//from   w w  w  .j a v  a 2 s . c o  m
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    List<Class<?>> implementedInterfaces = ClassUtils.getAllInterfaces(bean.getClass());
    for (Class<?> implementedInterface : implementedInterfaces) {
        AutoPublished autoPublished = implementedInterface.getAnnotation(AutoPublished.class);
        if (autoPublished != null) {
            Class<?> publisherClass = autoPublished.publisher();
            Object object = context.getBean(StringUtils.uncapitalize(publisherClass.getSimpleName()));
            try {
                MethodUtils.invokeMethod(object, "addListener", bean);
            } catch (Exception e) {
                throw new IllegalStateException("Auto publishing event listener failed", e);
            }
        }
    }
    return bean;
}

From source file:com.strandls.alchemy.inject.json.AlchemyJsonModuleLister.java

/**
 * Get all guice {@link Module}s for a give environment.
 *
 * @param environment//from  ww w .  j  a v  a2s  . c  o  m
 *            the environment to get modules for. Cannot be
 *            <code>null</code>.
 * @return list of json modules matching the environment.
 */
public Collection<Module> getModules(@NonNull final Environment environment) {
    // get all classes with Alchemy module marker
    final Set<Class<?>> classes = typeQueryHandler.getTypesAnnotatedWith(".*", AlchemyJsonModule.class);
    final List<Module> modules = new ArrayList<Module>();

    log.debug("Looking for json modules in Environment: {}", environment);
    for (final Class<?> klass : classes) {
        final AlchemyJsonModule marker = klass.getAnnotation(AlchemyJsonModule.class);

        // match against desired environment
        if (environment.isCompatible(marker.value())) {
            log.debug("For Environment: {} found : {}", environment, klass);
            modules.add((Module) injector.getInstance(klass));
        }
    }
    return modules;
}

From source file:org.elasticsoftware.elasticactors.runtime.MessagesScanner.java

@PostConstruct
public void init() {
    String[] basePackages = ScannerHelper.findBasePackagesOnClasspath(applicationContext.getClassLoader());
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

    for (String basePackage : basePackages) {
        configurationBuilder.addUrls(ClasspathHelper.forPackage(basePackage));
    }/*from   ww w. ja  va  2s . c o m*/

    Reflections reflections = new Reflections(configurationBuilder);

    Set<Class<?>> messageClasses = reflections.getTypesAnnotatedWith(Message.class);

    for (Class<?> messageClass : messageClasses) {
        Message messageAnnotation = messageClass.getAnnotation(Message.class);
        // get the serialization framework
        SerializationFramework framework = applicationContext
                .getBean(messageAnnotation.serializationFramework());
        if (framework != null) {
            framework.register(messageClass);
        } else {
            logger.error(String.format("Could not find framework %s for message class %s",
                    messageAnnotation.serializationFramework().getSimpleName(), messageClass.getName()));
        }
    }
}

From source file:name.martingeisse.wicket.autoform.describe.DefaultAutoformBeanDescriberHelper.java

@Override
protected <A extends Annotation> A getBeanAnnotation(final Class<? extends Serializable> beanDescriptor,
        final Class<A> annotationClass) {
    return beanDescriptor.getAnnotation(annotationClass);
}

From source file:rascal.ConfigurableTestExecutionListener.java

@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
    Configurable configurable = testContext.getTestMethod().getAnnotation(Configurable.class);
    if (configurable != null) {
        if (configurable.value().isEmpty()) {
            String defaultPath = testContext.getTestClass().getName() + CONFIGURATION_NAME_SEPARATOR
                    + testContext.getTestMethod().getName();
            injectConfiguration(testContext, defaultPath);
        } else {//www . j a va2 s . c om
            injectConfiguration(testContext, configurable.value());
        }
    } else {
        Class<?> testClass = testContext.getTestClass();
        while ((configurable = testClass.getAnnotation(Configurable.class)) == null) {
            testClass = testClass.getSuperclass();
            if (testClass == null || testClass.equals(Object.class)) {
                break;
            }
        }
        if (configurable != null) {
            if (configurable.value().isEmpty()) {
                String defaultPath = testClass.getName();
                injectConfiguration(testContext, defaultPath);
            } else {
                injectConfiguration(testContext, configurable.value());
            }
        }
    }
}

From source file:dpfmanager.shell.application.launcher.ui.GuiLauncher.java

private EmbeddedFXWorkbench createWorkbench(final Launcher<ClassPathXmlApplicationContext> launcher,
        final Class<? extends FXWorkbench> workbenchHandler) {
    final Workbench annotation = workbenchHandler.getAnnotation(Workbench.class);
    final String id = annotation.id();
    if (id.isEmpty())
        throw new AttributeNotFoundException("no workbench id found for: " + workbenchHandler);
    final FXWorkbench handler = launcher.registerAndGetBean(workbenchHandler, id, Scope.SINGLETON);
    return new EmbeddedFXWorkbench(handler, getWorkbenchDecorator());
}

From source file:org.jacpfx.spring.launcher.AFXSpringJavaConfigLauncher.java

private EmbeddedFXWorkbench createWorkbench(final Launcher<AnnotationConfigApplicationContext> launcher,
        final Class<? extends FXWorkbench> workbenchHandler) {
    final Workbench annotation = workbenchHandler.getAnnotation(Workbench.class);
    final String id = annotation.id();
    if (id.isEmpty())
        throw new AttributeNotFoundException("no workbench id found for: " + workbenchHandler);
    final FXWorkbench handler = launcher.registerAndGetBean(workbenchHandler, id, Scope.SINGLETON);
    return new EmbeddedFXWorkbench(handler);
}

From source file:org.elasticsoftware.elasticactors.base.serialization.JacksonSerializationFramework.java

@Override
public void register(Class<?> messageClass) {
    Message messageAnnotation;/*from w  ww.  j a  v a2 s . c  o m*/
    if ((messageAnnotation = messageClass.getAnnotation(Message.class)) != null
            && this.getClass().equals(messageAnnotation.serializationFramework())) {
        deserializers.putIfAbsent(messageClass, new JacksonMessageDeserializer(messageClass, objectMapper));
    }
}