Example usage for java.lang Class isAnnotationPresent

List of usage examples for java.lang Class isAnnotationPresent

Introduction

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

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:com.amazonaws.services.dynamodbv2.datamodeling.AttributeEncryptor.java

/**
 * @return True if {@link DoNotEncrypt} IS present on the class level. False otherwise.
 *///from  w ww  .  ja  v  a  2 s  . co  m
private boolean doNotEncrypt(Class<?> clazz) {
    return clazz.isAnnotationPresent(DoNotEncrypt.class);
}

From source file:org.nuxeo.ecm.webengine.app.WebEngineModule.java

private void initRoots(WebEngine engine) throws Exception {
    ArrayList<Class<?>> roots = new ArrayList<Class<?>>();
    for (Class<?> cl : cfg.types) {
        if (cl.isAnnotationPresent(Path.class)) {
            roots.add(cl);/*from   w  w  w. java  2  s.co  m*/
        } else if (cfg.rootType != null) {
            // compat mode - should be removed later
            WebObject wo = cl.getAnnotation(WebObject.class);
            if (wo != null && wo.type().equals(cfg.rootType)) {
                log.warn("Invalid web module " + cfg.name + " from bundle " + bundle.getSymbolicName()
                        + ". The root-type " + cl
                        + " in module.xml is deprecated. Consider using @Path annotation on you root web objects.");
            }
        }
    }
    if (roots.isEmpty()) {
        log.error("No root web objects found in web module " + cfg.name + " from bundle "
                + bundle.getSymbolicName());
        //throw new IllegalStateException("No root web objects found in web module "+cfg.name+" from bundle "+bundle.getSymbolicName());
    }
    cfg.roots = roots.toArray(new Class<?>[roots.size()]);
}

From source file:org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport.java

/**
 * Returns whether the given type is a repository type.
 * //from   w w w.j ava  2 s.c om
 * @param type must not be {@literal null}.
 * @return
 */
private boolean isRepository(Class<?> type) {

    boolean isInterface = type.isInterface();
    boolean extendsRepository = Repository.class.isAssignableFrom(type);
    boolean isAnnotated = type.isAnnotationPresent(RepositoryDefinition.class);
    boolean excludedByAnnotation = type.isAnnotationPresent(NoRepositoryBean.class);

    return isInterface && (extendsRepository || isAnnotated) && !excludedByAnnotation;
}

From source file:reconf.client.factory.ConfigurationRepositoryElementFactory.java

private ConfigurationRepositoryElement createNewRepositoryFor(Class<?> arg) {

    if (!arg.isInterface()) {
        throw new ReConfInitializationError(msg.format("error.is.not.interface", arg.getCanonicalName()));
    }//from  w w w  . j a  v a  2  s  . c  o  m

    if (!arg.isAnnotationPresent(ConfigurationRepository.class)) {
        return null;
    }
    ConfigurationRepositoryElement result = new ConfigurationRepositoryElement();
    defineReloadStrategy(arg, result);

    ConfigurationRepository ann = arg.getAnnotation(ConfigurationRepository.class);
    result.setProduct(ann.product());
    result.setComponent(ann.component());
    result.setConnectionSettings(configuration.getConnectionSettings());
    result.setInterfaceClass(arg);
    result.setRate(ann.pollingRate());
    result.setTimeUnit(ann.pollingTimeUnit());
    result.setConfigurationItems(ConfigurationItemElement.from(result));
    return result;
}

From source file:com.cloudbees.sdk.ArtifactInstallFactory.java

/**
 * Finds all the commands in the given injector.
 *//*w ww  .j  a v  a  2s.  com*/
private void findCommand(boolean all, List<CommandProperties> list, Class<?> cmd) {
    if (!cmd.isAnnotationPresent(CLICommand.class))
        return;

    CommandProperties commandProperties = new CommandProperties();
    commandProperties.setClassName(cmd.getName());
    commandProperties.setName(cmd.getAnnotation(CLICommand.class).value());

    if (cmd.isAnnotationPresent(BeesCommand.class)) {
        BeesCommand beesCommand = cmd.getAnnotation(BeesCommand.class);

        if (beesCommand.experimental() && !all)
            return;

        commandProperties.setGroup(beesCommand.group());
        if (beesCommand.description().length() > 0)
            commandProperties.setDescription(beesCommand.description());
        commandProperties.setPriority(beesCommand.priority());
        if (beesCommand.pattern().length() > 0)
            commandProperties.setPattern(beesCommand.pattern());
        commandProperties.setExperimental(beesCommand.experimental());
    } else {
        try {
            commandProperties.setGroup("CLI");
            commandProperties.setPriority((Integer) BeesCommand.class.getMethod("priority").getDefaultValue());
            commandProperties.setExperimental(false);
        } catch (NoSuchMethodException e) {
            LOGGER.log(Level.SEVERE, "Internal error", e);
        }
    }

    list.add(commandProperties);

}

From source file:com.joyveb.dbpimpl.cass.prepare.mapping.BasicCassandraPersistentProperty.java

/**
 * Returns the true if the field composite primary key.
 * /*w  w w .j  a  v a 2  s .co  m*/
 * @return
 */
@Override
public boolean hasEmbeddableType() {
    Class<?> fieldType = getField().getType();
    return fieldType.isAnnotationPresent(Embeddable.class);
}

From source file:org.pmp.budgeto.app.SwaggerDispatcherConfigTest.java

@Test
public void springConf() throws Exception {

    Class<?> clazz = swaggerDispatcherConfig.getClass();
    Assertions.assertThat(clazz.getAnnotations()).hasSize(4);
    Assertions.assertThat(clazz.isAnnotationPresent(Configuration.class)).isTrue();
    Assertions.assertThat(clazz.isAnnotationPresent(EnableWebMvc.class)).isTrue();
    Assertions.assertThat(clazz.isAnnotationPresent(EnableSwagger.class)).isTrue();
    Assertions.assertThat(clazz.isAnnotationPresent(ComponentScan.class)).isTrue();
    Assertions.assertThat(clazz.getAnnotation(ComponentScan.class).basePackages())
            .containsExactly("com.ak.swaggerspringmvc.shared.app", "com.ak.spring3.music");

    Field fSpringSwaggerConfig = clazz.getDeclaredField("springSwaggerConfig");
    Assertions.assertThat(fSpringSwaggerConfig.getAnnotations()).hasSize(1);
    Assertions.assertThat(fSpringSwaggerConfig.isAnnotationPresent(Autowired.class)).isTrue();

    Method mCustomImplementation = clazz.getDeclaredMethod("customImplementation", new Class[] {});
    Assertions.assertThat(mCustomImplementation.getAnnotations()).hasSize(1);
    Assertions.assertThat(mCustomImplementation.getAnnotation(Bean.class)).isNotNull();
}

From source file:com.qq.tars.server.apps.TarsStartLifecycle.java

private ServantHomeSkeleton loadServant(Object bean) throws Exception {
    String homeName;//from   w w  w.ja v a  2s.c  om
    Class<?> homeApiClazz = null;
    Object homeClassImpl;
    ServantHomeSkeleton skeleton;
    int maxLoadLimit = -1;

    ServerConfig serverCfg = ConfigurationManager.getInstance().getServerConfig();

    homeName = bean.getClass().getAnnotation(TarsServant.class).name();
    if (StringUtils.isEmpty(homeName)) {
        throw new RuntimeException("servant name is null.");
    }
    homeName = String.format("%s.%s.%s", serverCfg.getApplication(), serverCfg.getServerName(), homeName);

    for (Class clazz : bean.getClass().getInterfaces()) {
        if (clazz.isAnnotationPresent(Servant.class)) {
            homeApiClazz = clazz;
            break;
        }
    }

    homeClassImpl = bean;

    if (TarsHelper.isServant(homeApiClazz)) {
        String servantName = homeApiClazz != null ? homeApiClazz.getAnnotation(Servant.class).name() : null;
        if (!StringUtils.isEmpty(servantName) && servantName.matches("^[\\w]+\\.[\\w]+\\.[\\w]+$")) {
            homeName = servantName;
        }
    }

    skeleton = new ServantHomeSkeleton(homeName, homeClassImpl, homeApiClazz, null, null, maxLoadLimit);
    skeleton.setAppContext(this);

    ConfigurationManager.getInstance().getServerConfig().getServantAdapterConfMap().put(homeName,
            servantAdapterConfig);

    return skeleton;
}

From source file:org.socialsignin.spring.data.dynamodb.repository.support.EnableScanAnnotationPermissions.java

public EnableScanAnnotationPermissions(Class<?> repositoryInterface) {
    // Check to see if global EnableScan is declared at interface level
    if (repositoryInterface.isAnnotationPresent(EnableScan.class)) {
        this.findAllUnpaginatedScanEnabled = true;
        this.countUnpaginatedScanEnabled = true;
        this.deleteAllUnpaginatedScanEnabled = true;
        this.findAllPaginatedScanEnabled = true;
    } else {//from   w w w . j  a va2 s  . co  m
        // Check declared methods for EnableScan annotation
        Method[] methods = ReflectionUtils.getAllDeclaredMethods(repositoryInterface);
        for (Method method : methods) {

            if (!method.isAnnotationPresent(EnableScan.class) || method.getParameterTypes().length > 0) {
                // Only consider methods which have the EnableScan
                // annotation and which accept no parameters
                continue;
            }

            if (method.getName().equals("findAll")) {
                findAllUnpaginatedScanEnabled = true;
                continue;
            }

            if (method.getName().equals("deleteAll")) {
                deleteAllUnpaginatedScanEnabled = true;
                continue;
            }

            if (method.getName().equals("count")) {
                countUnpaginatedScanEnabled = true;
                continue;
            }

        }
        for (Method method : methods) {

            if (!method.isAnnotationPresent(EnableScanCount.class) || method.getParameterTypes().length != 1) {
                // Only consider methods which have the EnableScanCount
                // annotation and which have a single pageable parameter
                continue;
            }

            if (method.getName().equals("findAll")
                    && Pageable.class.isAssignableFrom(method.getParameterTypes()[0])) {
                findAllUnpaginatedScanCountEnabled = true;
                continue;
            }

        }
        for (Method method : methods) {

            if (!method.isAnnotationPresent(EnableScan.class) || method.getParameterTypes().length != 1) {
                // Only consider methods which have the EnableScan
                // annotation and which have a single pageable parameter
                continue;
            }

            if (method.getName().equals("findAll")
                    && Pageable.class.isAssignableFrom(method.getParameterTypes()[0])) {
                findAllPaginatedScanEnabled = true;
                continue;
            }

        }
    }
    if (!findAllUnpaginatedScanCountEnabled && repositoryInterface.isAnnotationPresent(EnableScanCount.class)) {
        findAllUnpaginatedScanCountEnabled = true;
    }

}

From source file:com.evolveum.midpoint.repo.sql.query.definition.ClassDefinitionParser.java

private void addVirtualDefinitionsForClass(EntityDefinition entityDef, Class jpaType) {
    if (!jpaType.isAnnotationPresent(QueryEntity.class)) {
        return;//  w  w  w. j av a 2  s  . c om
    }

    QueryEntity qEntity = (QueryEntity) jpaType.getAnnotation(QueryEntity.class);
    for (VirtualProperty property : qEntity.properties()) {
        QName jaxbName = createQName(property.jaxbName());
        VirtualPropertyDefinition def = new VirtualPropertyDefinition(jaxbName, property.jaxbType(),
                property.jpaName(), property.jpaType());
        def.setAdditionalParams(property.additionalParams());
        entityDef.addDefinition(def);
    }

    for (VirtualReference reference : qEntity.references()) {

    }

    for (VirtualCollection collection : qEntity.collections()) {
        QName jaxbName = createQName(collection.jaxbName());

        VirtualCollectionDefinition def = new VirtualCollectionDefinition(jaxbName, collection.jaxbType(),
                collection.jpaName(), collection.jpaType());
        def.setAdditionalParams(collection.additionalParams());
        updateCollectionDefinition(def, collection.collectionType(), jaxbName, collection.jpaName());

        entityDef.addDefinition(def);
    }
}