当前位置: 首页>>代码示例>>Java>>正文


Java FieldMetadata.getModifier方法代码示例

本文整理汇总了Java中org.springframework.roo.classpath.details.FieldMetadata.getModifier方法的典型用法代码示例。如果您正苦于以下问题:Java FieldMetadata.getModifier方法的具体用法?Java FieldMetadata.getModifier怎么用?Java FieldMetadata.getModifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.roo.classpath.details.FieldMetadata的用法示例。


在下文中一共展示了FieldMetadata.getModifier方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEntityManagerField

import org.springframework.roo.classpath.details.FieldMetadata; //导入方法依赖的package包/类
/**
 * Locates the entity manager field that should be used.
 * <p>
 * If a parent is defined, it must provide the field unless a persistent
 * unit name is supplied on the child entity.
 * <p>
 * We generally expect the field to be named "entityManager" and be of type
 * javax.persistence.EntityManager. We also require it to be public or
 * protected, and annotated with @PersistenceContext. If there is an
 * existing field which doesn't meet these latter requirements, we add an
 * underscore prefix to the "entityManager" name and try again, until such
 * time as we come up with a unique name that either meets the requirements
 * or the name is not used and we will create it.
 * 
 * @return the entity manager field (never returns null)
 */
public FieldMetadata getEntityManagerField() {
    if (parent != null
            && StringUtils.isBlank(crudAnnotationValues
                    .getPersistenceUnit())) {
        // The parent is required to guarantee this is available
        return parent.getEntityManagerField();
    }

    // Need to locate it ourself
    int index = -1;
    while (true) {
        // Compute the required field name
        index++;
        final JavaSymbolName fieldSymbolName = new JavaSymbolName(
                StringUtils.repeat("_", index) + "entityManager");
        final FieldMetadata candidate = governorTypeDetails
                .getField(fieldSymbolName);
        if (candidate != null) {
            // Verify if candidate is suitable

            if (!Modifier.isPublic(candidate.getModifier())
                    && !Modifier.isProtected(candidate.getModifier())
                    && Modifier.TRANSIENT != candidate.getModifier()) {
                // Candidate is not public and not protected and not simply
                // a transient field (in which case subclasses
                // will see the inherited field), so any subsequent
                // subclasses won't be able to see it. Give up!
                continue;
            }

            if (!candidate.getFieldType().equals(ENTITY_MANAGER)) {
                // Candidate isn't an EntityManager, so give up
                continue;
            }

            if (MemberFindingUtils.getAnnotationOfType(
                    candidate.getAnnotations(), PERSISTENCE_CONTEXT) == null) {
                // Candidate doesn't have a PersistenceContext annotation,
                // so give up
                continue;
            }

            // If we got this far, we found a valid candidate
            return candidate;
        }

        // Candidate not found, so let's create one
        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(
                PERSISTENCE_CONTEXT);
        if (StringUtils.isNotBlank(crudAnnotationValues
                .getPersistenceUnit())) {
            annotationBuilder.addStringAttribute("unitName",
                    crudAnnotationValues.getPersistenceUnit());
        }
        annotations.add(annotationBuilder);

        return new FieldMetadataBuilder(getId(), Modifier.TRANSIENT,
                annotations, fieldSymbolName, ENTITY_MANAGER).build();
    }
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:78,代码来源:JpaActiveRecordMetadata.java

示例2: appendFields

import org.springframework.roo.classpath.details.FieldMetadata; //导入方法依赖的package包/类
private void appendFields() {
    final List<? extends FieldMetadata> fields = itdTypeDetails
            .getDeclaredFields();
    if (fields == null || fields.isEmpty()) {
        return;
    }

    content = true;
    for (final FieldMetadata field : fields) {
        // Append annotations
        for (final AnnotationMetadata annotation : field.getAnnotations()) {
            appendIndent();
            outputAnnotation(annotation);
            this.newLine(false);
        }

        // Append "<modifier> <fieldType> <fieldName>" portion
        appendIndent();
        if (field.getModifier() != 0) {
            append(Modifier.toString(field.getModifier()));
            append(" ");
        }
        append(field.getFieldType().getNameIncludingTypeParameters(false,
                resolver));
        append(" ");
        append(introductionTo.getSimpleTypeName());
        append(".");
        append(field.getFieldName().getSymbolName());

        // Append initializer, if present
        if (field.getFieldInitializer() != null) {
            append(" = ");
            append(field.getFieldInitializer());
        }

        // Complete the field declaration
        append(";");
        this.newLine(false);
        this.newLine();
    }
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:42,代码来源:ItdSourceFileComposer.java

示例3: getGvNIXXmlElementFieldAnnotation

import org.springframework.roo.classpath.details.FieldMetadata; //导入方法依赖的package包/类
/**
 * <p>
 * Convert field with @XmlElement annotation to field with @GvNIXXmlElementField
 * with its values.
 * </p>
 * <p>
 * Creates {@link FieldMetadata} with @GvNIXXmlElementField annotation even
 * if not exists @XmlElement.
 * </p>
 * TODO to be removed from interface?. This method could be useless outside
 * this service.
 * 
 * @param fieldMetadata
 * @return {@link FieldMetadata} with @GvNIXXmlElementField annotation.
 */
protected FieldMetadata getGvNIXXmlElementFieldAnnotation(
        FieldMetadata field) {

    AnnotationMetadata gvNixXmlElementAnnot;

    AnnotationMetadata xmlElementAnnot = MemberFindingUtils
            .getAnnotationOfType(field.getAnnotations(), new JavaType(
                    XmlElement.class.getName()));
    if (xmlElementAnnot != null) {

        // Field has XmlElement annotation: create GvNIXXmlElement from it
        gvNixXmlElementAnnot = getXmlElementFieldAnnotation(xmlElementAnnot);

    }
    else {

        AnnotationMetadata xmlElementRefAnnot = MemberFindingUtils
                .getAnnotationOfType(field.getAnnotations(), new JavaType(
                        XmlElementRef.class.getName()));
        if (xmlElementRefAnnot != null) {

            // Field has XmlElementRef: create GvNIXXmlElement from it
            gvNixXmlElementAnnot = getXmlElementRefFieldAnnotation(field);

        }
        else {

            // Field no XmlElement, XmlElementRef: create empty
            // GvNIXXmlElement
            gvNixXmlElementAnnot = new AnnotationMetadataBuilder(
                    new JavaType(GvNIXXmlElementField.class.getName()),
                    new ArrayList<AnnotationAttributeValue<?>>()).build();
        }
    }

    List<AnnotationMetadata> annots = new ArrayList<AnnotationMetadata>();
    annots.add(gvNixXmlElementAnnot);

    // Create new Field with GvNIXAnnotation.
    FieldMetadataBuilder fieldMetadataBuilder = new FieldMetadataBuilder(
            field.getDeclaredByMetadataId(), field.getModifier(),
            field.getFieldName(), field.getFieldType(),
            field.getFieldInitializer());
    for (AnnotationMetadata annotationMetadata : annots) {
        fieldMetadataBuilder.addAnnotation(annotationMetadata);
    }

    return fieldMetadataBuilder.build();
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:65,代码来源:WSExportWsdlImpl.java


注:本文中的org.springframework.roo.classpath.details.FieldMetadata.getModifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。