Example usage for java.lang.reflect Modifier PUBLIC

List of usage examples for java.lang.reflect Modifier PUBLIC

Introduction

In this page you can find the example usage for java.lang.reflect Modifier PUBLIC.

Prototype

int PUBLIC

To view the source code for java.lang.reflect Modifier PUBLIC.

Click Source Link

Document

The int value representing the public modifier.

Usage

From source file:org.gvnix.addon.jpa.addon.batch.JpaBatchMetadata.java

/**
 * Return method to create a list of entities
 * //  w ww .  ja v a  2s  .co  m
 * @return
 */
private MethodMetadata getCreateMethod() {

    // Define parameters types

    List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(listOfEntitiesType);

    // Check if a method exist in type
    final MethodMetadata method = methodExists(CREATE_METHOD, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method
        return method;
    }

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(new AnnotationMetadataBuilder(SpringJavaType.TRANSACTIONAL));

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    JavaSymbolName parameterName = new JavaSymbolName(StringUtils.uncapitalize(entityPlural));
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(parameterName);

    // --- Create the method body ---

    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

    // for(Vet vet : vets) {
    // vet.persist();
    // }
    bodyBuilder.appendFormalLine(
            String.format("for( %s %s : %s) {", entityName, entityName.toLowerCase(), parameterName));
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine(String.format("%s.persist();", entityName.toLowerCase()));
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    JavaType returnType = JavaType.VOID_PRIMITIVE;
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, CREATE_METHOD,
            returnType, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
                                  // instance
}

From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditMetadata.java

/**
 * @return gets or creates findAllXX(revision) method
 *//* w  w w.  j  a va2  s .c  om*/
private MethodMetadata getFindAllFromRevisionMethod() {
    // method name
    JavaSymbolName methodName = findAllMethodName;

    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(JavaType.LONG_PRIMITIVE);

    // Check if a method exist in type
    final MethodMetadata method = helper.methodExists(methodName, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method
        return method;
    }

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    List<JavaSymbolName> parameterNames = helper.toSymbolName("revision");

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    revisionLogBuilder.buildBodyFindAllFromRevision(bodyBuilder, parameterNames);

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
            entityListType, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    helper.addJavaDocToMethod(methodBuilder,
            "Find all ".concat(entity.getSimpleTypeName()).concat("status on specified revision"), null);

    return methodBuilder.build(); // Build and return a MethodMetadata
}

From source file:org.gvnix.addon.web.mvc.addon.batch.WebJpaBatchMetadata.java

/**
 * Return method <code>create</code>
 * /*  w  ww  .ja  v a 2s .c o m*/
 * @return
 */
private MethodMetadata getCreateMethod() {
    // method name
    JavaSymbolName methodName = CREATE_METHOD;

    // Define method parameter types
    final List<AnnotatedJavaType> parameterTypes = Arrays.asList(
            new AnnotatedJavaType(listOfEntityType,
                    Arrays.asList(AnnotationMetadataBuilder.getInstance(SpringJavaType.REQUEST_BODY),
                            AnnotationMetadataBuilder.getInstance(Jsr303JavaType.VALID))),
            AnnotatedJavaType.convertFromJavaType(SpringJavaType.BINDING_RESULT),
            AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST));

    // Check if a method exist in type
    final MethodMetadata method = methodExists(methodName, parameterTypes);

    if (method != null) {
        // If it already exists, just return the method
        return method;
    }

    // Define method annotations
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // @RequestMapping
    AnnotationMetadataBuilder requestMappingAnnotation = helper.getRequestMappingAnnotation(null, "POST",
            APP_JSON, APP_JSON, null, "Accept=application/json");
    annotations.add(requestMappingAnnotation);
    // @ResponseBody
    AnnotationMetadataBuilder responseBodyAnnotation = new AnnotationMetadataBuilder();
    responseBodyAnnotation.setAnnotationType(SpringJavaType.RESPONSE_BODY);
    annotations.add(responseBodyAnnotation);

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(listOfEntityName);
    parameterNames.add(BINDING_RESULT_NAME);
    parameterNames.add(REQUEST_NAME);

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    buildCreateMethod(bodyBuilder);

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
            jsonResponseList, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
    // instance
}

From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java

/**
 * @return Creates constructor for XXRevsion class
 *//*  ww  w.  j  a v  a 2s .  c om*/
private ConstructorMetadata createRevisionItemConstructor() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(2);
    parameterTypes.add(new AnnotatedJavaType(context.getEntity()));
    parameterTypes.add(new AnnotatedJavaType(revisionEntityMetadata.getType()));
    parameterTypes.add(new AnnotatedJavaType(REVISON_TYPE));

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(3);
    parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(context.getEntityName())));
    parameterNames.add(REV_ITEM_REVISON_ENTITY_FIELD);
    parameterNames.add(REV_ITEM_REVISON_TYPE_FIELD);

    // Create the method body
    InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder();

    helper.buildSetterMethodBody(body, parameterNames.get(0));
    helper.buildSetterMethodBody(body, parameterNames.get(1));
    helper.buildSetterMethodBody(body, parameterNames.get(2));

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    ConstructorMetadataBuilder builder = new ConstructorMetadataBuilder(context.getMetadataId());

    builder.setParameterTypes(parameterTypes);
    builder.setParameterNames(parameterNames);
    builder.setModifier(Modifier.PUBLIC);
    builder.setAnnotations(annotations);
    builder.setThrowsTypes(throwsTypes);
    builder.setBodyBuilder(body);

    return builder.build(); // Build and return a MethodMetadata
}

From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditMetadata.java

/**
 * @return gets or creates findAllXX(aDate) method
 */// www . ja  v a  2 s. c o  m
private MethodMetadata getFindAllFromDateMethod() {
    // method name
    JavaSymbolName methodName = findAllMethodName;

    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(JdkJavaType.DATE);

    // Check if a method exist in type
    final MethodMetadata method = helper.methodExists(methodName, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method
        return method;
    }

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    List<JavaSymbolName> parameterNames = helper.toSymbolName("atDate");

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    revisionLogBuilder.buildBodyFindAllFromDate(bodyBuilder, parameterNames);

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
            entityListType, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    helper.addJavaDocToMethod(methodBuilder,
            "Find all ".concat(entity.getSimpleTypeName()).concat("status on specified date"), null);
    return methodBuilder.build(); // Build and return a MethodMetadata
}

From source file:org.gvnix.addon.jpa.addon.batch.JpaBatchMetadata.java

/**
 * Return method to update a list of entities
 * //from w w  w  .j  ava  2 s  .c  o  m
 * @return
 */
private MethodMetadata getUpdateMethod() {

    // Define parameters types

    List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(listOfEntitiesType);

    // Check if a method exist in type
    final MethodMetadata method = methodExists(UPDATE_METHOD, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method
        return method;
    }

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(new AnnotationMetadataBuilder(SpringJavaType.TRANSACTIONAL));

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    JavaSymbolName parameterName = new JavaSymbolName(entityPlural.toLowerCase());
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(parameterName);

    // --- Create the method body ---

    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

    List<JavaType> typeParams = new ArrayList<JavaType>();
    typeParams.add(entity);

    JavaType arrayList = new JavaType("java.util.ArrayList", 0, DataType.TYPE, null, typeParams);

    // List<Vet> merged = new ArrayList<Vet>();
    bodyBuilder.appendFormalLine(String.format("%s merged = new %s();", getFinalTypeName(listOfEntitiesType),
            getFinalTypeName(arrayList)));

    // for(Vet vet : vets) {
    // merged.add( vet.merge() );
    // }
    // return merged;
    bodyBuilder.appendFormalLine(
            String.format("for( %s %s : %s) {", entityName, entityName.toLowerCase(), parameterName));
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine(String.format("merged.add( %s.merge() );", entityName.toLowerCase()));
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.appendFormalLine("return merged;");

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, UPDATE_METHOD,
            listOfEntitiesType, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
                                  // instance
}

From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java

/**
 * @return Creates XXXRevision.createList(list,reader) static method
 *//*from w ww.j a v a  2s  .co  m*/
private MethodMetadata createRevisionItemCreateList() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = helper.toAnnotedJavaType(LIST_OBJECT_ARRAY, AUDIT_READER);

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    List<JavaSymbolName> parameterNames = helper.toSymbolName("list", "reader");

    // Create the method body
    InvocableMemberBodyBuilder body = new InvocableMemberBodyBuilder();
    buildRevisionItemCreateListMethodBody(body, parameterNames);

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(context.getMetadataId(),
            Modifier.PUBLIC + Modifier.STATIC, CREATE_ITEM_LIST_METHOD, context.getRevisonItemListType(),
            parameterTypes, parameterNames, body);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
}

From source file:org.gvnix.addon.web.mvc.addon.batch.WebJpaBatchMetadata.java

/**
 * Create metadata for auto-wired jpa batch service field.
 * //from w ww  .  j  a va  2  s.  co  m
 * @return a FieldMetadata object
 */
public FieldMetadata getServiceField() {
    if (serviceFiled == null) {
        JavaSymbolName curName = BATCH_SERVICE_NAME;
        // Check if field exist
        FieldMetadata currentField = governorTypeDetails.getDeclaredField(curName);
        if (currentField != null) {
            if (currentField.getAnnotation(SpringJavaType.AUTOWIRED) == null
                    || !currentField.getFieldType().equals(service)) {
                // No compatible field: look for new name
                currentField = null;
                JavaSymbolName newName = curName;
                int i = 1;
                while (governorTypeDetails.getDeclaredField(newName) != null) {
                    newName = new JavaSymbolName(curName.getSymbolName().concat(StringUtils.repeat('_', i)));
                    i++;
                }
                curName = newName;
            }
        }
        if (currentField != null) {
            serviceFiled = currentField;
        } else {
            // create field
            List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(1);
            annotations.add(new AnnotationMetadataBuilder(SpringJavaType.AUTOWIRED));
            // Using the FieldMetadataBuilder to create the field
            // definition.
            final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), Modifier.PUBLIC,
                    annotations, curName, // Field
                    service); // Field type
            serviceFiled = fieldBuilder.build(); // Build and return a
            // FieldMetadata
            // instance
        }
    }
    return serviceFiled;
}

From source file:org.gvnix.addon.jpa.addon.batch.JpaBatchMetadata.java

/**
 * Return method to delete a list of entities
 * //from  w  w  w  .  j av  a  2 s . co m
 * @return
 */
private MethodMetadata getDeleteMethod() {

    // Define parameters types

    List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(listOfEntitiesType);

    // Check if a method exist in type
    final MethodMetadata method = methodExists(DELETE_METHOD, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method
        return method;
    }

    // Define method annotations (none in this case)
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(new AnnotationMetadataBuilder(SpringJavaType.TRANSACTIONAL));

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();

    // Define method parameter names (none in this case)
    JavaSymbolName parameterName = new JavaSymbolName(entityPlural.toLowerCase());
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(parameterName);

    // --- Create the method body ---

    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

    List<JavaType> typeParams = new ArrayList<JavaType>();
    typeParams.add(entity);

    // for(Vet vet : vets) {
    // vet.remove() );
    // }
    bodyBuilder.appendFormalLine(
            String.format("for( %s %s : %s) {", entityName, entityName.toLowerCase(), parameterName));
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine(String.format("%s.remove();", entityName.toLowerCase()));
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, DELETE_METHOD,
            JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);

    return methodBuilder.build(); // Build and return a MethodMetadata
                                  // instance
}

From source file:org.gvnix.addon.web.mvc.addon.batch.WebJpaBatchMetadata.java

/**
 * Create metadata for logger static field.
 * /*from www  .  ja v  a 2s  .  c o  m*/
 * @return a FieldMetadata object
 */
public FieldMetadata getLoggerField() {
    if (loggerFiled == null) {
        JavaSymbolName curName = new JavaSymbolName("LOGGER_BATCH");
        // Check if field exist
        FieldMetadata currentField = governorTypeDetails.getDeclaredField(curName);
        if (currentField != null) {
            if (!currentField.getFieldType().equals(LOGGER_TYPE)) {
                // No compatible field: look for new name
                currentField = null;
                JavaSymbolName newName = curName;
                int i = 1;
                while (governorTypeDetails.getDeclaredField(newName) != null) {
                    newName = new JavaSymbolName(curName.getSymbolName().concat(StringUtils.repeat('_', i)));
                    i++;
                }
                curName = newName;
            }
        }
        if (currentField != null) {
            loggerFiled = currentField;
        } else {
            // Prepare initialized
            // LoggerFactory.getLogger(PetController.class);
            String initializer = String.format("%s.getLogger(%s.class);",
                    helper.getFinalTypeName(LOGGER_FACTORY_TYPE),
                    helper.getFinalTypeName(governorPhysicalTypeMetadata.getType()));

            // Using the FieldMetadataBuilder to create the field
            // definition.
            final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(),
                    Modifier.PUBLIC + Modifier.STATIC, curName, // Field
                    LOGGER_TYPE, initializer); // Field type
            loggerFiled = fieldBuilder.build(); // Build and return a
                                                // FieldMetadata
                                                // instance
        }
    }
    return loggerFiled;
}