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.darkstar.beanCartography.utils.NameUtils.java

/**
 * @param clazz class to check/*from   w  w w.  j  ava 2 s.co m*/
 * @return the name associated to the class
 */
public static String getBusinessName(Class<?> clazz) {
    Preconditions.checkNotNull(clazz, "Class cannot be null");
    if (hasBusinessName(clazz))
        return clazz.getAnnotation(NamedClass.class).name();
    return null;
}

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

private static EncryptionContext paramsToContext(Parameters<?> params) {
    final Class<?> clazz = params.getModelClass();
    final TableAadOverride override = clazz.getAnnotation(TableAadOverride.class);
    final String tableName = ((override == null) ? params.getTableName() : override.tableName());

    return new EncryptionContext.Builder().withHashKeyName(params.getHashKeyName())
            .withRangeKeyName(params.getRangeKeyName()).withTableName(tableName)
            .withModeledClass(params.getModelClass()).withAttributeValues(params.getAttributeValues()).build();
}

From source file:bammerbom.ultimatecore.bukkit.configuration.ConfigurationSerialization.java

/**
 * Registers the given {@link ConfigurationSerializable} class by its alias
 *
 * @param clazz Class to register//www.  ja va 2s  .  c  o m
 */
public static void registerClass(Class<?> clazz) {
    DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);

    if (delegate == null) {
        registerClass(clazz, getAlias(clazz));
        registerClass(clazz, clazz.getName());
    }
}

From source file:ch.rasc.extclassgenerator.ModelAnnotationProcessor.java

private static String generateSubclassCode(Class<?> clazz, OutputConfig outputConfig) {
    Model modelAnnotation = clazz.getAnnotation(Model.class);

    String name;/*  ww  w  .j  a  v a2s  .c o m*/
    if (modelAnnotation != null && StringUtils.hasText(modelAnnotation.value())) {
        name = modelAnnotation.value();
    } else {
        name = clazz.getName();
    }

    Map<String, Object> modelObject = new LinkedHashMap<String, Object>();
    modelObject.put("extend", name + "Base");

    StringBuilder sb = new StringBuilder(100);
    sb.append("Ext.define(\"").append(name).append("\",");
    if (outputConfig.isDebug()) {
        sb.append("\n");
    }

    String configObjectString;
    try {

        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, false);

        if (!outputConfig.isSurroundApiWithQuotes()) {
            if (outputConfig.getOutputFormat() == OutputFormat.EXTJS5) {
                mapper.addMixInAnnotations(ProxyObject.class, ProxyObjectWithoutApiQuotesExtJs5Mixin.class);
            } else {
                mapper.addMixInAnnotations(ProxyObject.class, ProxyObjectWithoutApiQuotesMixin.class);
            }
            mapper.addMixInAnnotations(ApiObject.class, ApiObjectMixin.class);
        } else {
            if (outputConfig.getOutputFormat() != OutputFormat.EXTJS5) {
                mapper.addMixInAnnotations(ProxyObject.class, ProxyObjectWithApiQuotesMixin.class);
            }
        }

        if (outputConfig.isDebug()) {
            configObjectString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(modelObject);
        } else {
            configObjectString = mapper.writeValueAsString(modelObject);
        }

    } catch (JsonGenerationException e) {
        throw new RuntimeException(e);
    } catch (JsonMappingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    sb.append(configObjectString);
    sb.append(");");

    if (outputConfig.isUseSingleQuotes()) {
        return sb.toString().replace('"', '\'');
    }

    return sb.toString();

}

From source file:com.clustercontrol.accesscontrol.util.ObjectPrivilegeUtil.java

/** ??? */
private static void createObjectPrivilegeMap() {
    if (m_objectPrivilegeMap == null || m_objectPrivilegeMap.size() == 0) {
        EntityManagerFactory emf = new JpaTransactionManager().getEntityManager().getEntityManagerFactory();
        Set<EntityType<?>> entityTypes = emf.getMetamodel().getEntities();
        String str = "";
        for (EntityType<?> entityType : entityTypes) {
            Class<?> clazz = entityType.getBindableJavaType();
            if (ObjectPrivilegeTargetInfo.class.isAssignableFrom(clazz)) {
                try {
                    HinemosObjectPrivilege hinemosObjectPrivilege = clazz
                            .getAnnotation(HinemosObjectPrivilege.class);
                    String objectType = hinemosObjectPrivilege.objectType();
                    if (hinemosObjectPrivilege.isModifyCheck()) {
                        str += "[" + objectType + "," + clazz + "] ";

                        if (m_objectPrivilegeMap.get(objectType) != null) {
                            m_log.warn("duplicate objectType=" + objectType);
                        }//www  . j  a va 2  s.  c  o m
                        m_objectPrivilegeMap.put(objectType, clazz);
                    }
                } catch (Exception e) {
                    continue;
                }
            }
        }
        m_log.info("objectMap=" + str);
    }
}

From source file:com.helpinput.propertyeditors.PropertyEditorRegister.java

public static Class<?> getTargetType(Class<? extends PropertyEditor> propertyEditorType,
        Class<?>... targetType) {
    Class<?> tmpTargetType = null;
    if (!Utils.hasLength(targetType)) {
        TargetType targetTypeAnn = propertyEditorType.getAnnotation(TargetType.class);
        if (targetTypeAnn == null)
            return null;
        tmpTargetType = targetTypeAnn.value();
    } else//from   w w  w  . ja v  a 2 s  .  co  m
        tmpTargetType = targetType[0];

    return tmpTargetType;
}

From source file:bammerbom.ultimatecore.bukkit.configuration.ConfigurationSerialization.java

/**
 * Gets the correct alias for the given {@link ConfigurationSerializable}
 * class//  www.ja v a 2s  .  c om
 *
 * @param clazz Class to get alias for
 * @return Alias to use for the class
 */
public static String getAlias(Class<?> clazz) {
    DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);

    if (delegate != null) {
        if ((delegate.value() == null) || (delegate.value() == clazz)) {
            delegate = null;
        } else {
            return getAlias(delegate.value());
        }
    }

    if (delegate == null) {
        SerializableAs alias = clazz.getAnnotation(SerializableAs.class);

        if ((alias != null) && (alias.value() != null)) {
            return alias.value();
        }
    }

    return clazz.getName();
}

From source file:com.chiorichan.configuration.serialization.ConfigurationSerialization.java

/**
 * Registers the given {@link ConfigurationSerializable} class by its alias
 * /*from   w w w . ja v  a2s .  co  m*/
 * @param clazz
 *            Class to register
 */
public static void registerClass(Class<? extends ConfigurationSerializable> clazz) {
    DelegateDeserialization delegate = clazz.getAnnotation(DelegateDeserialization.class);

    if (delegate == null) {
        registerClass(clazz, getAlias(clazz));
        registerClass(clazz, clazz.getName());
    }
}

From source file:gr.abiss.calipso.tiers.util.ModelContext.java

public static String getPath(Class<?> domainClass) {
    ModelResource ar = domainClass.getAnnotation(ModelResource.class);
    ModelRelatedResource anr = domainClass.getAnnotation(ModelRelatedResource.class);

    String result;/*from  w w w  .j  a  v a  2s  .  c  om*/
    if (ar != null) {
        result = ar.path();
    } else if (anr != null) {
        result = anr.path();
    } else {
        throw new IllegalStateException("Not an entity");
    }

    if (result == null || result.trim().isEmpty()) {
        result = domainClass.getSimpleName();
        result = result.toLowerCase().charAt(0) + result.substring(1) + "s";
    }

    return result;
}

From source file:gr.abiss.calipso.tiers.util.ModelContext.java

public static ModelContext from(Class<?> domainClass) {

    ModelResource ar = domainClass.getAnnotation(ModelResource.class);
    ModelRelatedResource anr = domainClass.getAnnotation(ModelRelatedResource.class);

    ModelContext wrapper = null;/*from w  w  w  .  j  a v  a  2s  . c om*/
    if (ar != null) {
        wrapper = new ModelContext(ar, domainClass);
    } else if (anr != null) {
        wrapper = new ModelContext(anr, domainClass);
    } else {
        // look for an ancestor who might be a resource
        Class<?> superClass = domainClass.getSuperclass();
        if (superClass != null && !Object.class.equals(superClass)) {
            wrapper = from(domainClass.getSuperclass());
        }
    }
    wrapper.setModelType(domainClass);
    return wrapper;
}