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:org.b3log.latke.servlet.RequestProcessors.java

/**
 * Invokes a processor method with the specified request URI, method and context.
 *
 * @param requestURI the specified request URI
 * @param contextPath the specified context path
 * @param method the specified method/*from  ww w  .  j av a 2 s .c  om*/
 * @param context the specified context
 * @return invoke result, returns {@code null} if invoke failed
 */
public static Object invoke(final String requestURI, final String contextPath, final String method,
        final HTTPRequestContext context) {
    final ProcessorMethod processMethod = getProcessorMethod(requestURI, contextPath, method);

    if (null == processMethod) {
        LOGGER.log(Level.WARNING, "Can not find process method for request[requestURI={0}, method={1}]",
                new Object[] { requestURI, method });
        return null;
    }

    final Method processorMethod = processMethod.getProcessorMethod();
    final Class<?> processorClass = processMethod.getProcessorClass();
    Object processorObject = processors.get(processorMethod);

    try {
        if (null == processorObject) {
            final Object instance = processorClass.newInstance();

            processors.put(processorMethod, instance);
            processorObject = instance;
        }

        final Map<String, Object> args = new LinkedHashMap<String, Object>();

        final Class<?>[] parameterTypes = processorMethod.getParameterTypes();
        final String[] parameterName = processMethod.getMethodParamNames();

        // TODO need Optimization
        String relativeRequestURI = requestURI;

        if (contextPath != null && contextPath.length() > 1) {
            relativeRequestURI = requestURI.substring(contextPath.length());
        }
        final Map<String, String> pathVariableValueMap = processMethod.pathVariableValueMap(relativeRequestURI);

        final List<AbstractHTTPResponseRenderer> rendererList = new ArrayList<AbstractHTTPResponseRenderer>();

        for (int i = 0; i < parameterTypes.length; i++) {
            final Class<?> paramClass = parameterTypes[i];

            if (paramClass.equals(HTTPRequestContext.class)) {
                args.put(parameterName[i], context);
            } else if (paramClass.equals(HttpServletRequest.class)) {
                args.put(parameterName[i], context.getRequest());
            } else if (paramClass.equals(HttpServletResponse.class)) {
                args.put(parameterName[i], context.getResponse());
            } else if (AbstractHTTPResponseRenderer.class.isAssignableFrom(paramClass)
                    && !paramClass.equals(AbstractHTTPResponseRenderer.class)) {
                final AbstractHTTPResponseRenderer ins = (AbstractHTTPResponseRenderer) paramClass
                        .newInstance();
                final String rid = getRendererId(processorClass, processorMethod, i);

                ins.setRendererId(rid);
                rendererList.add(ins);
                args.put(parameterName[i], ins);

            } else if (pathVariableValueMap.containsKey(parameterName[i])) {
                args.put(parameterName[i], getConverter(processMethod.getConvertClass())
                        .convert(parameterName[i], pathVariableValueMap.get(parameterName[i]), paramClass));
            } else {
                args.put(parameterName[i], null);
            }
        }

        // before invoke(first class before advice and then method before advice).
        final List<Class<? extends BeforeRequestProcessAdvice>> beforeAdviceClassList = new ArrayList<Class<? extends BeforeRequestProcessAdvice>>();

        if (processorClass.isAnnotationPresent(Before.class)) {
            final Class<? extends BeforeRequestProcessAdvice>[] ac = processorClass.getAnnotation(Before.class)
                    .adviceClass();

            beforeAdviceClassList.addAll(Arrays.asList(ac));
        }
        if (processorMethod.isAnnotationPresent(Before.class)) {
            final Class<? extends BeforeRequestProcessAdvice>[] ac = processorMethod.getAnnotation(Before.class)
                    .adviceClass();

            beforeAdviceClassList.addAll(Arrays.asList(ac));
        }

        BeforeRequestProcessAdvice binstance;

        try {
            for (Class<? extends BeforeRequestProcessAdvice> clz : beforeAdviceClassList) {
                binstance = (BeforeRequestProcessAdvice) adviceMap.get(clz);
                if (binstance == null) {
                    binstance = clz.newInstance();
                }
                binstance.doAdvice(context, args);
            }
        } catch (final RequestReturnAdviceException re) {
            return null;
        } catch (final RequestProcessAdviceException e) {
            final JSONObject exception = e.getJsonObject();

            LOGGER.log(Level.WARNING, "Occurs an exception before request processing [errMsg={0}]",
                    exception.optString(Keys.MSG));

            final JSONRenderer ret = new JSONRenderer();

            ret.setJSONObject(exception);
            context.setRenderer(ret);
            return null;
        }

        for (int j = 0; j < rendererList.size(); j++) {
            rendererList.get(j).preRender(context, args);
        }

        final Object ret = processorMethod.invoke(processorObject, args.values().toArray());

        for (int j = rendererList.size() - 1; j >= 0; j--) {
            rendererList.get(j).postRender(context, ret);
        }

        // after invoke(first method before advice and then class before advice).
        final List<Class<? extends AfterRequestProcessAdvice>> afterAdviceClassList = new ArrayList<Class<? extends AfterRequestProcessAdvice>>();

        if (processorMethod.isAnnotationPresent(After.class)) {
            final Class<? extends AfterRequestProcessAdvice>[] ac = processorMethod.getAnnotation(After.class)
                    .adviceClass();

            afterAdviceClassList.addAll(Arrays.asList(ac));
        }

        if (processorClass.isAnnotationPresent(After.class)) {
            final Class<? extends AfterRequestProcessAdvice>[] ac = processorClass.getAnnotation(After.class)
                    .adviceClass();

            afterAdviceClassList.addAll(Arrays.asList(ac));
        }

        AfterRequestProcessAdvice instance;

        for (Class<? extends AfterRequestProcessAdvice> clz : afterAdviceClassList) {
            instance = (AfterRequestProcessAdvice) adviceMap.get(clz);
            if (instance == null) {
                instance = clz.newInstance();
            }
            instance.doAdvice(context, ret);
        }

        return ret;

    } catch (final Exception e) {
        LOGGER.log(Level.SEVERE, "Invokes processor method failed [method="
                + processorMethod.getDeclaringClass().getSimpleName() + '#' + processorMethod.getName() + ']',
                e);

        return null;
    }
}

From source file:net.ceos.project.poi.annotated.core.Engine.java

/**
 * Initialize the configuration to apply at the Excel.
 * /*from w w  w  .j  a va  2 s .  c  om*/
 * @param configCriteria
 *            the {@link XConfigCriteria}
 * @param oC
 *            the {@link Class<?>}
 * @param insideCollection
 *            true if this configuration is inside of one collection
 * @param excludeCascadeInit
 *            true if to exclude the initialization of the parameter cascade
 *            level
 * @throws ConfigurationException
 *             given when basic configuration is missing.
 */
private void initializeConfigurationData(final XConfigCriteria configCriteria, final Class<?> oC,
        final boolean insideCollection, final boolean excludeCascadeInit) throws ConfigurationException {
    /* Process @XlsConfiguration */
    if (PredicateFactory.isAnnotationXlsConfigurationPresent.test(oC)) {
        XlsConfiguration xlsAnnotation = (XlsConfiguration) oC.getAnnotation(XlsConfiguration.class);
        initializeXlsConfiguration(configCriteria, xlsAnnotation);
    } else {
        throw new ConfigurationException(ExceptionMessage.CONFIGURATION_XLSCONFIGURATION_MISSING.getMessage());
    }
    /* Process @XlsSheet */
    if (PredicateFactory.isAnnotationXlsSheetPresent.test(oC)) {
        XlsSheet xlsAnnotation = (XlsSheet) oC.getAnnotation(XlsSheet.class);
        initializeXlsSheet(configCriteria, xlsAnnotation, excludeCascadeInit);
        if (insideCollection && oC.isAnnotationPresent(XlsElement.class)) {
            /**
             * if the collection is an attribut inside an object we get the
             * sheet title name from the element
             */
            XlsElement xlsElement = (XlsElement) oC.getAnnotation(XlsElement.class);
            if (!xlsElement.parentSheet()) {
                configCriteria.setTitleSheet(xlsElement.title());
                configCriteria.setElement(xlsElement);
            }
        }
    } else {
        throw new ConfigurationException(ExceptionMessage.CONFIGURATION_XLSSHEET_MISSING.getMessage());
    }
}

From source file:com.github.gekoh.yagen.ddl.CreateDDL.java

public void init(DDLGenerator.Profile profile) {
    currentProfile = profile;//from  w  w w.  j  av a 2  s  .c o  m
    boolean selectiveRendering = false;

    for (Class entityClass : profile.getEntityClasses()) {

        Class baseClass = TableConfig.getClassOfTableAnnotation(entityClass);

        if (baseClass == null || baseClass != entityClass) {
            continue;
        }

        String nameLC = getProfile().getNamingStrategy().classToTableName(baseClass.getName()).toLowerCase();

        TableConfig tableConfig = tblNameToConfig.get(nameLC);
        if (tableConfig == null) {
            tblNameToConfig.put(nameLC, tableConfig = new TableConfig(this, baseClass, nameLC));
            String tableName = tableConfig.getTableName();
            String shortName = getShortName(tableName);

            String definedForTable = tblShortNameToTblName.get(shortName);
            if (definedForTable != null && !definedForTable.equals(tableName)) {
                throw new IllegalStateException(
                        "error setting short name for table '" + tableName + "': short name '" + shortName
                                + "' already defined for table '" + definedForTable + "'");
            }
            tblShortNameToTblName.put(shortName, tableName);
        }

        if (profile.getOnlyRenderEntities() != null
                && !profile.getOnlyRenderEntities().matcher(baseClass.getName()).matches()) {
            tableConfig.setTableToBeRendered(false);
        } else if (baseClass.isAnnotationPresent(Profile.class)
                && (Arrays.asList(((Profile) baseClass.getAnnotation(Profile.class)).value())
                        .contains(profile.getName()))) {
            // at least one Profile annotation contains the name of current profile,
            // so only entities shall be rendered which have an appropriate Profile annotation
            selectiveRendering = true;
        }

        if (baseClass.isAnnotationPresent(Generated.class)) {
            if (((Generated) baseClass.getAnnotation(Generated.class)).isView()) {
                externalViews.add(nameLC);
            }
            tableConfig.setTableToBeRendered(false);
        }
    }

    for (Class entityClass : profile.getEntityClasses()) {
        Class baseClass = TableConfig.getClassOfTableAnnotation(entityClass);

        if (baseClass == null) {
            continue;
        }

        String nameLC = getProfile().getNamingStrategy().classToTableName(baseClass.getName()).toLowerCase();

        TableConfig tableConfig = tblNameToConfig.get(nameLC);

        if (entityClass == baseClass && selectiveRendering
                && (!baseClass.isAnnotationPresent(Profile.class)
                        || !(Arrays.asList(((Profile) baseClass.getAnnotation(Profile.class)).value())
                                .contains(profile.getName())))) {
            tableConfig.setTableToBeRendered(false);
        }

        tableConfig.scanEntityClass(entityClass, selectiveRendering);
    }
}

From source file:org.apache.solr.core.SolrResourceLoader.java

/**
 * This method loads a class either with its FQN or a short-name (solr.class-simplename or class-simplename).
 * It tries to load the class with the name that is given first and if it fails, it tries all the known
 * solr packages. This method caches the FQN of a short-name in a static map in-order to make subsequent lookups
 * for the same class faster. The caching is done only if the class is loaded by the webapp classloader and it
 * is loaded using a shortname./*from w ww.  jav  a 2  s  . com*/
 *
 * @param cname The name or the short name of the class.
 * @param subpackages the packages to be tried if the cname starts with solr.
 * @return the loaded class. An exception is thrown if it fails
 */
public <T> Class<? extends T> findClass(String cname, Class<T> expectedType, String... subpackages) {
    if (subpackages == null || subpackages.length == 0 || subpackages == packages) {
        subpackages = packages;
        String c = classNameCache.get(cname);
        if (c != null) {
            try {
                return Class.forName(c, true, classLoader).asSubclass(expectedType);
            } catch (ClassNotFoundException e) {
                //this is unlikely
                log.error("Unable to load cached class-name :  " + c + " for shortname : " + cname + e);
            }

        }
    }

    Class<? extends T> clazz = null;
    try {
        // first try legacy analysis patterns, now replaced by Lucene's Analysis package:
        final Matcher m = legacyAnalysisPattern.matcher(cname);
        if (m.matches()) {
            final String name = m.group(4);
            log.trace("Trying to load class from analysis SPI using name='{}'", name);
            try {
                if (CharFilterFactory.class.isAssignableFrom(expectedType)) {
                    return clazz = CharFilterFactory.lookupClass(name).asSubclass(expectedType);
                } else if (TokenizerFactory.class.isAssignableFrom(expectedType)) {
                    return clazz = TokenizerFactory.lookupClass(name).asSubclass(expectedType);
                } else if (TokenFilterFactory.class.isAssignableFrom(expectedType)) {
                    return clazz = TokenFilterFactory.lookupClass(name).asSubclass(expectedType);
                } else {
                    log.warn(
                            "'{}' looks like an analysis factory, but caller requested different class type: {}",
                            cname, expectedType.getName());
                }
            } catch (IllegalArgumentException ex) {
                // ok, we fall back to legacy loading
            }
        }

        // first try cname == full name
        try {
            return clazz = Class.forName(cname, true, classLoader).asSubclass(expectedType);
        } catch (ClassNotFoundException e) {
            String newName = cname;
            if (newName.startsWith(project)) {
                newName = cname.substring(project.length() + 1);
            }
            for (String subpackage : subpackages) {
                try {
                    String name = base + '.' + subpackage + newName;
                    log.trace("Trying class name " + name);
                    return clazz = Class.forName(name, true, classLoader).asSubclass(expectedType);
                } catch (ClassNotFoundException e1) {
                    // ignore... assume first exception is best.
                }
            }

            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error loading class '" + cname + "'",
                    e);
        }

    } finally {
        if (clazz != null) {
            //cache the shortname vs FQN if it is loaded by the webapp classloader  and it is loaded
            // using a shortname
            if (clazz.getClassLoader() == SolrResourceLoader.class.getClassLoader()
                    && !cname.equals(clazz.getName()) && (subpackages.length == 0 || subpackages == packages)) {
                //store in the cache
                classNameCache.put(cname, clazz.getName());
            }

            // print warning if class is deprecated
            if (clazz.isAnnotationPresent(Deprecated.class)) {
                log.warn(
                        "Solr loaded a deprecated plugin/analysis class [{}]. Please consult documentation how to replace it accordingly.",
                        cname);
            }
        }
    }
}

From source file:org.vulpe.model.dao.impl.jpa.AbstractVulpeBaseDAOJPA.java

private List<ENTITY> loadRelationshipsMountChild(final Relationship relationship, final List<Map> result,
        final Map<ID, ID> relationshipIds, final String parentName, final Class propertyType,
        final Map<String, String> hqlAttributes, final OneToMany oneToMany) {
    final List<ENTITY> childs = new ArrayList<ENTITY>();
    try {/*from   w w  w  .  j  a v  a 2s  . c o  m*/
        for (final Map map : result) {
            final ENTITY child = (ENTITY) (oneToMany != null ? oneToMany.targetEntity().newInstance()
                    : propertyType.newInstance());
            VulpeReflectUtil.setFieldValue(child, "id", map.get("id"));
            relationshipIds.put(child.getId(), (ID) map.get(parentName));
            childs.add(child);
        }
        for (final String attribute : relationship.attributes()) {
            if (hqlAttributes.containsKey(attribute)) {
                final String attributeParent = attribute.substring(0, attribute.indexOf('['));
                final String hqlAttribute = hqlAttributes.get(attribute);
                final List<ID> ids = new ArrayList<ID>();
                for (final ENTITY child : childs) {
                    Map map = null;
                    for (final Map resultMap : result) {
                        if (child.getId().equals((Long) resultMap.get("id"))) {
                            map = resultMap;
                            break;
                        }
                    }
                    if (StringUtils.isNotBlank(attributeParent)) {
                        final Class attributeType = PropertyUtils.getPropertyType(propertyType.newInstance(),
                                attributeParent);
                        final VulpeEntity<ID> newAttribute = (VulpeEntity<ID>) attributeType.newInstance();
                        newAttribute.setId((ID) map.get(attributeParent));
                        ids.add(newAttribute.getId());
                        VulpeReflectUtil.setFieldValue(child, attributeParent, newAttribute);
                    } else {
                        ids.add(child.getId());
                    }
                }
                if (StringUtils.isNotBlank(attributeParent)) {
                    final Query queryAttribute = getEntityManager().createQuery(hqlAttribute)
                            .setParameter("ids", ids);
                    final List<Map> listAttributeMap = (List<Map>) queryAttribute.getResultList();
                    for (ENTITY child : childs) {
                        final Class attributeType = PropertyUtils.getPropertyType(propertyType.newInstance(),
                                attributeParent);
                        final VulpeEntity<ID> newAttribute = (VulpeEntity<ID>) attributeType.newInstance();
                        for (Map map : listAttributeMap) {
                            if (((Long) map.get("id")).equals(child.getId())) {
                                loadRelationshipsMountProperties(map, newAttribute, attribute, null);
                            }
                        }
                        VulpeReflectUtil.setFieldValue(child, attributeParent, newAttribute);
                    }
                } else {
                    final Query queryAttribute = getEntityManager().createQuery(hqlAttribute)
                            .setParameter("ids", ids);
                    final List<Map> listAttributeMap = (List<Map>) queryAttribute.getResultList();
                    for (final ENTITY child : childs) {
                        for (final Map map : listAttributeMap) {
                            if (((Long) map.get("id")).equals(child.getId())) {
                                loadRelationshipsMountProperties(map, child, attribute, null);
                            }
                        }
                    }
                }
            } else {
                for (final ENTITY child : childs) {
                    Map map = null;
                    for (final Map resultMap : result) {
                        if (child.getId().equals((Long) resultMap.get("id"))) {
                            map = resultMap;
                            break;
                        }
                    }
                    final Class attributeType = PropertyUtils.getPropertyType(child, attribute);
                    boolean manyToOne = attributeType.isAnnotationPresent(ManyToOne.class)
                            || VulpeEntity.class.isAssignableFrom(attributeType);
                    VulpeReflectUtil.instanciate(child, attribute + (manyToOne ? ".id" : ""),
                            map.get(attribute));
                }
            }
        }
        if (relationship.forceLoad()) {
            if (!"default".equals(relationship.forceLoadQueryConfiguration())) {
                for (final ENTITY entity : childs) {
                    entity.setQueryConfigurationName(relationship.forceLoadQueryConfiguration());
                }
            }
            loadRelationships(childs, null, false);
        }
    } catch (Exception e) {
        LOG.error(e.getMessage());
    }
    return childs;
}

From source file:org.kuali.rice.core.framework.persistence.jpa.metadata.MetadataManager.java

private static void extractFieldMetadata(Class clazz, EntityDescriptor entityDescriptor) {
    // Don't want to get parent fields if overridden in children since we are walking the tree from child to parent
    Set<String> cachedFields = new HashSet<String>();
    do {//  w ww  . ja va 2  s.  com
        for (Field field : clazz.getDeclaredFields()) {
            if (cachedFields.contains(field.getName())) {
                continue;
            }
            cachedFields.add(field.getName());

            int mods = field.getModifiers();
            if (Modifier.isFinal(mods) || Modifier.isStatic(mods) || Modifier.isTransient(mods)
                    || field.isAnnotationPresent(Transient.class)) {
                continue;
            }

            // Basic Fields
            FieldDescriptor fieldDescriptor = new FieldDescriptor();
            fieldDescriptor.setClazz(field.getType());
            fieldDescriptor.setTargetClazz(field.getType());
            fieldDescriptor.setName(field.getName());

            if (field.isAnnotationPresent(Id.class)) {
                fieldDescriptor.setId(true);

                if (entityDescriptor.getIdClass() != null) {
                    // pull the column from IdClass
                    try {
                        Field idClassField = entityDescriptor.getIdClass().getDeclaredField(field.getName());
                        idClassField.setAccessible(true);
                        addColumnInformationToFieldDescriptor(fieldDescriptor, idClassField);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            if (field.isAnnotationPresent(Column.class)) {

                if (!field.isAnnotationPresent(Id.class) || entityDescriptor.getIdClass() == null) {
                    // only populate if we haven't populated already
                    addColumnInformationToFieldDescriptor(fieldDescriptor, field);
                }
            } else if (!field.isAnnotationPresent(Id.class) || entityDescriptor.getIdClass() == null) {
                fieldDescriptor.setColumn(field.getName());
            }
            if (field.isAnnotationPresent(Version.class)) {
                fieldDescriptor.setVersion(true);
            }
            if (field.isAnnotationPresent(Lob.class)) {
                fieldDescriptor.setLob(true);
            }
            if (field.isAnnotationPresent(Temporal.class)) {
                fieldDescriptor.setTemporal(true);
                fieldDescriptor.setTemporalType(field.getAnnotation(Temporal.class).value());
            }

            // Relationships
            if (field.isAnnotationPresent(OneToOne.class)) {
                OneToOneDescriptor descriptor = new OneToOneDescriptor();
                OneToOne relation = field.getAnnotation(OneToOne.class);
                descriptor.setAttributeName(field.getName());
                if (relation.targetEntity().equals(void.class)) {
                    descriptor.setTargetEntity(field.getType());
                } else {
                    descriptor.setTargetEntity(relation.targetEntity());
                    fieldDescriptor.setTargetClazz(relation.targetEntity());
                }

                descriptor.setCascade(relation.cascade());
                descriptor.setFetch(relation.fetch());
                descriptor.setMappedBy(relation.mappedBy());
                descriptor.setOptional(relation.optional());
                if (field.isAnnotationPresent(JoinColumn.class)) {
                    JoinColumn jc = field.getAnnotation(JoinColumn.class);
                    descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                    FieldDescriptor jcFkField = entityDescriptor.getFieldByColumnName(jc.name());
                    if (jcFkField != null) {
                        descriptor.addFkField(jcFkField.getName());
                    } else {
                        //check to see if foreign key is in an AttributeOverride annotation
                        if (clazz.isAnnotationPresent(AttributeOverrides.class)) {
                            for (AttributeOverride override : ((AttributeOverrides) clazz
                                    .getAnnotation(AttributeOverrides.class)).value()) {
                                if (jc.name().equals(override.column().name())) {
                                    entityDescriptor.getFieldByName(override.name())
                                            .setColumn(override.column().name());
                                    jcFkField = entityDescriptor.getFieldByName(override.name());
                                    if (jcFkField != null) {
                                        descriptor.addFkField(jcFkField.getName());
                                    }
                                }
                            }
                        }
                        if (clazz.isAnnotationPresent(AttributeOverride.class)) {
                            AttributeOverride override = (AttributeOverride) clazz
                                    .getAnnotation(AttributeOverride.class);
                            if (jc.name().equals(override.column().name())) {
                                entityDescriptor.getFieldByName(override.name())
                                        .setColumn(override.column().name());
                                jcFkField = entityDescriptor.getFieldByName(override.name());
                                if (jcFkField != null) {
                                    descriptor.addFkField(jcFkField.getName());
                                }
                            }
                        }
                    }
                    //descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName());
                    descriptor.setInsertable(jc.insertable());
                    descriptor.setUpdateable(jc.updatable());
                }
                if (field.isAnnotationPresent(JoinColumns.class)) {
                    JoinColumns jcs = field.getAnnotation(JoinColumns.class);
                    for (JoinColumn jc : jcs.value()) {
                        descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                        descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName());
                        descriptor.setInsertable(jc.insertable());
                        descriptor.setUpdateable(jc.updatable());
                    }
                }
                entityDescriptor.add(descriptor);
            }

            if (field.isAnnotationPresent(OneToMany.class)) {
                OneToManyDescriptor descriptor = new OneToManyDescriptor();
                OneToMany relation = field.getAnnotation(OneToMany.class);
                descriptor.setAttributeName(field.getName());
                if (relation.targetEntity().equals(void.class)) {
                    descriptor.setTargetEntity(
                            (Class) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]);
                } else {
                    descriptor.setTargetEntity(relation.targetEntity());
                    fieldDescriptor.setTargetClazz(relation.targetEntity());
                }
                descriptor.setCascade(relation.cascade());
                descriptor.setFetch(relation.fetch());
                descriptor.setMappedBy(relation.mappedBy());
                EntityDescriptor mappedBy = (entityDescriptor.getClazz().equals(descriptor.getTargetEntity()))
                        ? entityDescriptor
                        : MetadataManager.getEntityDescriptor(descriptor.getTargetEntity());
                ObjectDescriptor od = mappedBy.getObjectDescriptorByName(descriptor.getMappedBy());
                if (od != null) {
                    for (String fk : od.getForeignKeyFields()) {
                        descriptor.addFkField(fk);
                    }
                }
                if (field.isAnnotationPresent(JoinTable.class)) {
                    JoinTable jt = field.getAnnotation(JoinTable.class);
                    for (JoinColumn jc : jt.joinColumns()) {
                        descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName());
                        descriptor.setInsertable(jc.insertable());
                        descriptor.setUpdateable(jc.updatable());
                        descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                    }
                    for (JoinColumn jc : jt.inverseJoinColumns()) {
                        descriptor.setInsertable(jc.insertable());
                        descriptor.setUpdateable(jc.updatable());
                        descriptor.addInverseJoinColumnDescriptor(constructJoinDescriptor(jc));
                    }
                } else {
                    if (field.isAnnotationPresent(JoinColumn.class)) {
                        JoinColumn jc = field.getAnnotation(JoinColumn.class);
                        FieldDescriptor jcFkField = entityDescriptor.getFieldByColumnName(jc.name());
                        if (jcFkField != null) {
                            descriptor.addFkField(jcFkField.getName());
                        }
                        descriptor.setInsertable(jc.insertable());
                        descriptor.setUpdateable(jc.updatable());
                        descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                    }
                    if (field.isAnnotationPresent(JoinColumns.class)) {
                        JoinColumns jcs = field.getAnnotation(JoinColumns.class);
                        for (JoinColumn jc : jcs.value()) {
                            descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName());
                            descriptor.setInsertable(jc.insertable());
                            descriptor.setUpdateable(jc.updatable());
                            descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                        }
                    }
                }
                entityDescriptor.add(descriptor);
            }

            if (field.isAnnotationPresent(ManyToOne.class)) {
                ManyToOne relation = field.getAnnotation(ManyToOne.class);
                ManyToOneDescriptor descriptor = new ManyToOneDescriptor();
                descriptor.setAttributeName(field.getName());
                if (relation.targetEntity().equals(void.class)) {
                    descriptor.setTargetEntity(field.getType());
                } else {
                    descriptor.setTargetEntity(relation.targetEntity());
                    fieldDescriptor.setTargetClazz(relation.targetEntity());
                }
                descriptor.setCascade(relation.cascade());
                descriptor.setFetch(relation.fetch());
                descriptor.setOptional(relation.optional());
                if (field.isAnnotationPresent(JoinColumn.class)) {
                    JoinColumn jc = field.getAnnotation(JoinColumn.class);
                    descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                    FieldDescriptor jcFkField = entityDescriptor.getFieldByColumnName(jc.name());
                    if (jcFkField != null) {
                        descriptor.addFkField(jcFkField.getName());
                    }
                    //descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName());
                    //descriptor.addFkField(entitesByClass.get(field.getType()).getFieldByColumnName(jc.name()).getName());
                    descriptor.setInsertable(jc.insertable());
                    descriptor.setUpdateable(jc.updatable());
                }
                if (field.isAnnotationPresent(JoinColumns.class)) {
                    JoinColumns jcs = field.getAnnotation(JoinColumns.class);
                    for (JoinColumn jc : jcs.value()) {
                        descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                        descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName());
                        descriptor.setInsertable(jc.insertable());
                        descriptor.setUpdateable(jc.updatable());
                    }
                }
                entityDescriptor.add(descriptor);
            }

            if (field.isAnnotationPresent(ManyToMany.class)) {
                ManyToManyDescriptor descriptor = new ManyToManyDescriptor();
                ManyToMany relation = field.getAnnotation(ManyToMany.class);
                descriptor.setAttributeName(field.getName());
                if (relation.targetEntity().equals(void.class)) {
                    descriptor.setTargetEntity(
                            (Class) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]);
                } else {
                    descriptor.setTargetEntity(relation.targetEntity());
                    fieldDescriptor.setTargetClazz(relation.targetEntity());
                }
                descriptor.setCascade(relation.cascade());
                descriptor.setFetch(relation.fetch());
                descriptor.setMappedBy(relation.mappedBy());
                if (field.isAnnotationPresent(JoinTable.class)) {
                    JoinTable jt = field.getAnnotation(JoinTable.class);
                    descriptor.setJoinTableName(jt.name());
                    for (JoinColumn jc : jt.joinColumns()) {
                        descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                        descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName());
                        descriptor.setInsertable(jc.insertable());
                        descriptor.setUpdateable(jc.updatable());
                    }
                    for (JoinColumn jc : jt.inverseJoinColumns()) {
                        descriptor.addInverseJoinColumnDescriptor(constructJoinDescriptor(jc));
                        descriptor.setInsertable(jc.insertable());
                        descriptor.setUpdateable(jc.updatable());
                        // TODO: Should we add inverse join columns?
                    }
                } else {
                    if (field.isAnnotationPresent(JoinColumn.class)) {
                        JoinColumn jc = field.getAnnotation(JoinColumn.class);
                        FieldDescriptor jcFkField = entityDescriptor.getFieldByColumnName(jc.name());
                        if (jcFkField != null) {
                            descriptor.addFkField(jcFkField.getName());
                        }
                        descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                        descriptor.setInsertable(jc.insertable());
                        descriptor.setUpdateable(jc.updatable());
                    }
                    if (field.isAnnotationPresent(JoinColumns.class)) {
                        JoinColumns jcs = field.getAnnotation(JoinColumns.class);
                        for (JoinColumn jc : jcs.value()) {
                            descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc));
                            descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName());
                            descriptor.setInsertable(jc.insertable());
                            descriptor.setUpdateable(jc.updatable());
                        }
                    }
                }
                entityDescriptor.add(descriptor);
            }

            // Add the field to the entity
            entityDescriptor.add(fieldDescriptor);
        }
        clazz = clazz.getSuperclass();
    } while (clazz != null && !(clazz.equals(Object.class)));
}

From source file:org.codehaus.enunciate.modules.rest.RESTOperation.java

/**
 * Construct a REST operation./*from   ww  w.  ja v  a 2 s.c  o m*/
 *
 * @param resource The resource for this operation.
 * @param contentType The content type of the operation.
 * @param verb     The verb for the operation.
 * @param method   The method.
 * @param parameterNames The parameter names.
 */
protected RESTOperation(RESTResource resource, String contentType, VerbType verb, Method method,
        String[] parameterNames) {
    this.resource = resource;
    this.verb = verb;
    this.method = method;
    this.contentType = contentType;

    int properNounIndex = -1;
    Class properNoun = null;
    Boolean properNounOptional = null;
    int nounValueIndex = -1;
    Class nounValue = null;
    Boolean nounValueOptional = Boolean.FALSE;
    int contentTypeParameterIndex = -1;
    adjectiveTypes = new HashMap<String, Class>();
    adjectiveIndices = new HashMap<String, Integer>();
    adjectivesOptional = new HashMap<String, Boolean>();
    complexAdjectives = new ArrayList<String>();
    contextParameterTypes = new HashMap<String, Class>();
    contextParameterIndices = new HashMap<String, Integer>();
    Class[] parameterTypes = method.getParameterTypes();
    HashSet<Class> contextClasses = new HashSet<Class>();
    for (int i = 0; i < parameterTypes.length; i++) {
        Class parameterType = Collection.class.isAssignableFrom(parameterTypes[i])
                ? getCollectionTypeAsArrayType(method, i)
                : parameterTypes[i];

        boolean isAdjective = true;
        String adjectiveName = "arg" + i;
        if ((parameterNames != null) && (parameterNames.length > i) && (parameterNames[i] != null)) {
            adjectiveName = parameterNames[i];
        }
        boolean adjectiveOptional = !parameterType.isPrimitive();
        boolean adjectiveComplex = false;
        Annotation[] parameterAnnotations = method.getParameterAnnotations()[i];
        for (Annotation annotation : parameterAnnotations) {
            if (annotation instanceof ProperNoun) {
                if (parameterType.isArray()) {
                    throw new IllegalStateException(
                            "Proper nouns must be simple types, found an array or collection for parameter " + i
                                    + " of method " + method.getDeclaringClass().getName() + "."
                                    + method.getName() + ".");
                } else if (properNoun == null) {
                    ProperNoun properNounInfo = (ProperNoun) annotation;
                    if (properNounInfo.optional()) {
                        if (parameterType.isPrimitive()) {
                            throw new IllegalStateException(
                                    "An optional proper noun cannot be a primitive type for method "
                                            + method.getDeclaringClass().getName() + "." + method.getName()
                                            + ".");
                        }

                        properNounOptional = true;
                    }

                    if (!properNounInfo.converter().equals(ProperNoun.DEFAULT.class)) {
                        try {
                            ConvertUtils.register((Converter) properNounInfo.converter().newInstance(),
                                    parameterType);
                        } catch (ClassCastException e) {
                            throw new IllegalArgumentException("Illegal converter class for method "
                                    + method.getDeclaringClass().getName() + "." + method.getName()
                                    + ". Must be an instance of org.apache.commons.beanutils.Converter.");
                        } catch (Exception e) {
                            throw new IllegalArgumentException("Unable to instantiate converter class "
                                    + properNounInfo.converter().getName() + " on method "
                                    + method.getDeclaringClass().getName() + "." + method.getName() + ".", e);
                        }
                    }

                    properNoun = parameterType;
                    properNounIndex = i;
                    isAdjective = false;
                    break;
                } else {
                    throw new IllegalStateException("There are two proper nouns for method "
                            + method.getDeclaringClass().getName() + "." + method.getName() + ".");
                }
            } else if (annotation instanceof NounValue) {
                if ((!parameterType.isAnnotationPresent(XmlRootElement.class))
                        && (!parameterType.equals(DataHandler.class)) && (!(parameterType.isArray()
                                && parameterType.getComponentType().equals(DataHandler.class)))) {
                    LOG.warn(
                            "Enunciate doesn't support unmarshalling objects of type " + parameterType.getName()
                                    + ". Unless a custom content type handler is provided, this operation ("
                                    + method.getDeclaringClass() + "." + method.getName() + ") will fail.");
                }

                if (nounValue == null) {
                    if (((NounValue) annotation).optional()) {
                        if (parameterType.isPrimitive()) {
                            throw new IllegalStateException(
                                    "An optional noun value cannot be a primitive type for method "
                                            + method.getDeclaringClass().getName() + "." + method.getName()
                                            + ".");
                        }

                        nounValueOptional = true;
                    }

                    nounValue = parameterType;
                    nounValueIndex = i;
                    isAdjective = false;
                    break;
                } else {
                    throw new IllegalStateException("There are two proper nouns for method "
                            + method.getDeclaringClass().getName() + "." + method.getName() + ".");
                }
            } else if (annotation instanceof ContextParameter) {
                ContextParameter contextParameterInfo = (ContextParameter) annotation;
                String contextParameterName = contextParameterInfo.value();

                if (!contextParameterInfo.converter().equals(ContextParameter.DEFAULT.class)) {
                    try {
                        ConvertUtils.register((Converter) contextParameterInfo.converter().newInstance(),
                                parameterType);
                    } catch (ClassCastException e) {
                        throw new IllegalArgumentException("Illegal converter class for method "
                                + method.getDeclaringClass().getName() + "." + method.getName()
                                + ". Must be an instance of org.apache.commons.beanutils.Converter.");
                    } catch (Exception e) {
                        throw new IllegalArgumentException(
                                "Unable to instantiate converter class "
                                        + contextParameterInfo.converter().getName() + " on method "
                                        + method.getDeclaringClass().getName() + "." + method.getName() + ".",
                                e);
                    }
                }

                contextParameterTypes.put(contextParameterName, parameterType);
                contextParameterIndices.put(contextParameterName, i);
                isAdjective = false;
                break;
            } else if (annotation instanceof ContentTypeParameter) {
                contentTypeParameterIndex = i;
                isAdjective = false;
                break;
            } else if (annotation instanceof Adjective) {
                Adjective adjectiveInfo = (Adjective) annotation;
                adjectiveOptional = adjectiveInfo.optional();
                if (adjectiveOptional && parameterType.isPrimitive()) {
                    throw new IllegalStateException(
                            "An optional adjective cannot be a primitive type for method "
                                    + method.getDeclaringClass().getName() + "." + method.getName() + ".");
                }

                if (!"##default".equals(adjectiveInfo.name())) {
                    adjectiveName = adjectiveInfo.name();
                }

                adjectiveComplex = adjectiveInfo.complex();

                if (!adjectiveInfo.converter().equals(Adjective.DEFAULT.class)) {
                    try {
                        ConvertUtils.register((Converter) adjectiveInfo.converter().newInstance(),
                                parameterType);
                    } catch (ClassCastException e) {
                        throw new IllegalArgumentException("Illegal converter class for method "
                                + method.getDeclaringClass().getName() + "." + method.getName()
                                + ". Must be an instance of org.apache.commons.beanutils.Converter.");
                    } catch (Exception e) {
                        throw new IllegalArgumentException("Unable to instantiate converter class "
                                + adjectiveInfo.converter().getName() + " on method "
                                + method.getDeclaringClass().getName() + "." + method.getName() + ".", e);
                    }
                }

                break;
            }
        }

        if (isAdjective) {
            this.adjectiveTypes.put(adjectiveName, parameterType);
            this.adjectiveIndices.put(adjectiveName, i);
            this.adjectivesOptional.put(adjectiveName, adjectiveOptional);
            if (adjectiveComplex) {
                this.complexAdjectives.add(adjectiveName);
            }
        }

        if (parameterType.isArray()) {
            contextClasses.add(parameterType.getComponentType());
        } else {
            contextClasses.add(parameterType);
        }
    }

    Class returnType = null;
    if (!Void.TYPE.equals(method.getReturnType())) {
        returnType = method.getReturnType();

        if (!returnType.isAnnotationPresent(XmlRootElement.class)
                && (!DataHandler.class.isAssignableFrom(returnType))) {
            LOG.warn("Enunciate doesn't support marshalling objects of type " + returnType.getName()
                    + ". Unless a custom content type handler is provided, this operation ("
                    + method.getDeclaringClass() + "." + method.getName() + ") will fail.");
        }

        contextClasses.add(returnType);
    }

    for (Class exceptionClass : method.getExceptionTypes()) {
        for (Method exceptionMethod : exceptionClass.getMethods()) {
            if ((exceptionMethod.isAnnotationPresent(RESTErrorBody.class))
                    && (exceptionMethod.getReturnType() != Void.TYPE)) {
                //add the error body to the context classes.
                contextClasses.add(exceptionMethod.getReturnType());
            }
        }
    }

    //now load any additional context classes as specified by @RESTSeeAlso
    if (method.isAnnotationPresent(RESTSeeAlso.class)) {
        contextClasses.addAll(Arrays.asList(method.getAnnotation(RESTSeeAlso.class).value()));
    }
    if (method.getDeclaringClass().isAnnotationPresent(RESTSeeAlso.class)) {
        contextClasses
                .addAll(Arrays.asList(method.getDeclaringClass().getAnnotation(RESTSeeAlso.class).value()));
    }
    if ((method.getDeclaringClass().getPackage() != null)
            && (method.getDeclaringClass().getPackage().isAnnotationPresent(RESTSeeAlso.class))) {
        contextClasses.addAll(Arrays
                .asList(method.getDeclaringClass().getPackage().getAnnotation(RESTSeeAlso.class).value()));
    }

    String jsonpParameter = null;
    JSONP jsonpInfo = method.getAnnotation(JSONP.class);
    if (jsonpInfo == null) {
        jsonpInfo = method.getDeclaringClass().getAnnotation(JSONP.class);
        if (jsonpInfo == null) {
            jsonpInfo = method.getDeclaringClass().getPackage().getAnnotation(JSONP.class);
        }
    }
    if (jsonpInfo != null) {
        jsonpParameter = jsonpInfo.paramName();
    }

    String charset = "utf-8";
    org.codehaus.enunciate.rest.annotations.ContentType contentTypeInfo = method
            .getAnnotation(org.codehaus.enunciate.rest.annotations.ContentType.class);
    if (contentTypeInfo == null) {
        contentTypeInfo = method.getDeclaringClass()
                .getAnnotation(org.codehaus.enunciate.rest.annotations.ContentType.class);
        if (contentTypeInfo == null) {
            contentTypeInfo = method.getDeclaringClass().getPackage()
                    .getAnnotation(org.codehaus.enunciate.rest.annotations.ContentType.class);
        }
    }
    if (contentTypeInfo != null) {
        charset = contentTypeInfo.charset();
    }

    String defaultNamespace = "";
    if (method.getDeclaringClass().getPackage() != null
            && method.getDeclaringClass().getPackage().isAnnotationPresent(XmlSchema.class)) {
        defaultNamespace = method.getDeclaringClass().getPackage().getAnnotation(XmlSchema.class).namespace();
    }

    this.properNounType = properNoun;
    this.properNounIndex = properNounIndex;
    this.properNounOptional = properNounOptional;
    this.nounValueType = nounValue;
    this.nounValueIndex = nounValueIndex;
    this.nounValueOptional = nounValueOptional;
    this.resultType = returnType;
    this.charset = charset;
    this.JSONPParameter = jsonpParameter;
    this.contextClasses = contextClasses;
    this.contentTypeParameterIndex = contentTypeParameterIndex;
    this.defaultNamespace = defaultNamespace;
}

From source file:org.apache.nifi.controller.FlowController.java

/**
 * <p>//from w ww .  j a  v  a  2 s  . c  om
 * Creates a new ProcessorNode with the given type and identifier and
 * optionally initializes it.
 * </p>
 *
 * @param type the fully qualified Processor class name
 * @param id the unique ID of the Processor
 * @param firstTimeAdded whether or not this is the first time this
 * Processor is added to the graph. If {@code true}, will invoke methods
 * annotated with the {@link OnAdded} annotation.
 * @return new processor node
 * @throws NullPointerException if either arg is null
 * @throws ProcessorInstantiationException if the processor cannot be
 * instantiated for any reason
 */
public ProcessorNode createProcessor(final String type, String id, final boolean firstTimeAdded)
        throws ProcessorInstantiationException {
    id = id.intern();

    boolean creationSuccessful;
    Processor processor;
    try {
        processor = instantiateProcessor(type, id);
        creationSuccessful = true;
    } catch (final ProcessorInstantiationException pie) {
        LOG.error("Could not create Processor of type " + type + " for ID " + id
                + "; creating \"Ghost\" implementation", pie);
        final GhostProcessor ghostProc = new GhostProcessor();
        ghostProc.setIdentifier(id);
        ghostProc.setCanonicalClassName(type);
        processor = ghostProc;
        creationSuccessful = false;
    }

    final ComponentLog logger = new SimpleProcessLogger(id, processor);
    final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(
            controllerServiceProvider, variableRegistry);
    final ProcessorNode procNode;
    if (creationSuccessful) {
        procNode = new StandardProcessorNode(processor, id, validationContextFactory, processScheduler,
                controllerServiceProvider, nifiProperties, variableRegistry, logger);
    } else {
        final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
        final String componentType = "(Missing) " + simpleClassName;
        procNode = new StandardProcessorNode(processor, id, validationContextFactory, processScheduler,
                controllerServiceProvider, componentType, type, nifiProperties, variableRegistry, logger);
    }

    final LogRepository logRepository = LogRepositoryFactory.getRepository(id);
    logRepository.addObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID, LogLevel.WARN,
            new ProcessorLogObserver(getBulletinRepository(), procNode));

    try {
        final Class<?> procClass = processor.getClass();
        if (procClass.isAnnotationPresent(DefaultSettings.class)) {
            DefaultSettings ds = procClass.getAnnotation(DefaultSettings.class);
            try {
                procNode.setYieldPeriod(ds.yieldDuration());
            } catch (Throwable ex) {
                LOG.error(String.format("Error while setting yield period from DefaultSettings annotation:%s",
                        ex.getMessage()), ex);
            }
            try {

                procNode.setPenalizationPeriod(ds.penaltyDuration());
            } catch (Throwable ex) {
                LOG.error(
                        String.format("Error while setting penalty duration from DefaultSettings annotation:%s",
                                ex.getMessage()),
                        ex);
            }
            try {
                procNode.setBulletinLevel(ds.bulletinLevel());
            } catch (Throwable ex) {
                LOG.error(String.format("Error while setting bulletin level from DefaultSettings annotation:%s",
                        ex.getMessage()), ex);
            }

        }
    } catch (Throwable ex) {
        LOG.error(String.format("Error while setting default settings from DefaultSettings annotation: %s",
                ex.getMessage()), ex);
    }

    if (firstTimeAdded) {
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(processor.getClass(),
                processor.getIdentifier())) {
            ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, processor);
        } catch (final Exception e) {
            logRepository.removeObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID);
            throw new ComponentLifeCycleException(
                    "Failed to invoke @OnAdded methods of " + procNode.getProcessor(), e);
        }

        if (firstTimeAdded) {
            try (final NarCloseable nc = NarCloseable.withComponentNarLoader(procNode.getProcessor().getClass(),
                    processor.getIdentifier())) {
                ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class,
                        procNode.getProcessor());
            }
        }
    }

    return procNode;
}

From source file:it.isislab.dmason.util.SystemManagement.Master.thrower.DMasonMaster.java

private boolean isThinSimulation(String simulation) {

    URL url;/*from  w  w  w. j  a  va  2s  . com*/
    Class c;
    Object instance;
    try {
        if (simulation.contains(".jar")) {
            File simFile = new File(FTP_HOME + dirSeparator + SIMULATION_DIR + dirSeparator + simulation);
            url = new URL("file:" + simFile.getAbsolutePath());

            JarClassLoader cl = new JarClassLoader(url);

            cl.addToClassPath();

            String main = cl.getMainClassName();
            System.out.println("main: " + main);

            c = cl.loadClass(main);

        } else {
            c = Class.forName(simulation);

        }
        return c.isAnnotationPresent(ThinAnnotation.class);

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;

}

From source file:adalid.core.AbstractEntity.java

private void annotateAbstractClass(Class<?> type) {
    // AbstractClass annotation cannot be "inherited"
    _annotatedWithAbstractClass = type.isAnnotationPresent(AbstractClass.class);
    //      if (_annotatedWithAbstractClass) {
    //          AbstractClass annotation = type.getAnnotation(AbstractClass.class);
    //      }//from   w  w  w . ja v  a 2 s .  co  m
}