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.web.screen.roo.addon.AbstractPatternMetadata.java

/**
 * Generates the MethodMedata of//from   w w  w .j av  a 2s  .  c o  m
 * filterBindingErrors(entityList,BindingResult) method for ITD
 * <p>
 * The generated method returns a list of ObjectErrors related to selected
 * rows.
 * </p>
 * 
 * @return
 */
protected MethodMetadata getFilterBindingErrorsMethod() {
    // Specify the desired method name
    JavaSymbolName methodName = FILTER_BINDING_ERRORS_NAME;
    ImportRegistrationResolver importResolver = builder.getImportRegistrationResolver();

    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    List<AnnotationMetadata> annotations = new ArrayList<AnnotationMetadata>();
    parameterTypes.add(new AnnotatedJavaType(getEntityList(), annotations));
    parameterTypes.add(BINDING_RESULT.getValue());

    // Check if a method with the same signature already exists in the
    // target type
    MethodMetadata method = methodExists(methodName, parameterTypes);
    if (method != null) {
        // If it already exists, just return null and omit its
        // generation via the ITD
        return null;
    }

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    String entitiesParamName = "entities";
    parameterNames.add(new JavaSymbolName(entitiesParamName));
    parameterNames.add(BINDING_RESULT.getKey());
    String bindingParamName = BINDING_RESULT.getKey().getSymbolName();

    JavaType returnType = OBJECT_ERROR_LIST_TYPE;

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

    JavaType returnImplementedType = new JavaType("java.util.ArrayList", 0, DataType.TYPE, null,
            Arrays.asList(OBJECT_ERROR_TYPE));

    JavaType selecteItemsType = new JavaType(LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
            Arrays.asList(JavaType.INT_OBJECT));

    bodyBuilder.appendFormalLine(String.format("%s result = new %s();",
            returnType.getNameIncludingTypeParameters(false, importResolver),
            returnImplementedType.getNameIncludingTypeParameters(false, importResolver)));

    bodyBuilder.appendFormalLine(String.format("%s selecteds = entities.getSelected();",
            selecteItemsType.getNameIncludingTypeParameters(false, importResolver)));

    bodyBuilder.appendFormalLine(String.format("for (%s objError : %s.getAllErrors()) {",
            OBJECT_ERROR_TYPE.getNameIncludingTypeParameters(false, importResolver), bindingParamName));

    bodyBuilder.indent();

    JavaType fieldValidationErrorType = new JavaType("org.springframework.validation.FieldError");

    String fieldValidationError = fieldValidationErrorType.getNameIncludingTypeParameters(false,
            importResolver);

    bodyBuilder.appendFormalLine(String.format("if (objError instanceof %s) {", fieldValidationError));
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine(String
            .format("String[] str = ((%s)objError).getField().split(\"[\\\\[\\\\]]\");", fieldValidationError));

    bodyBuilder.appendFormalLine("if (str.length == 3) {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("Integer row = null;");
    bodyBuilder.appendFormalLine("try {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("// name == \"list[0]fieldName\"");
    bodyBuilder.appendFormalLine("row = Integer.parseInt(str[1]);");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("} catch (NumberFormatException e) {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("// unexpected name format: add error");
    bodyBuilder.appendFormalLine("result.add(objError);");
    bodyBuilder.appendFormalLine("continue;");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.appendFormalLine("if (selecteds.contains(row)) {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("result.add(objError);");
    bodyBuilder.appendFormalLine("continue;");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("} else {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("continue;");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.appendFormalLine("result.add(objError);");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.appendFormalLine("return result;");

    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
            returnType, parameterTypes, parameterNames, bodyBuilder);

    method = methodBuilder.build();
    controllerMethods.add(method);
    return method;
}

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Returns <code>deleteDatatablesDetail</code> method <br>
 * This method is default delete request handler for detail datatables
 * controllers// w ww. jav a 2  s  .co m
 * 
 * @return
 */
private MethodMetadata getDeleteDatatablesDetailMethod() {

    // @RequestMapping(value = "/{id}", method = RequestMethod.DELETE,
    // produces = "text/html", params = "datatablesRedirect")
    // public String deleteDatatablesDetail(@RequestParam(value =
    // "datatablesRedirect", required = true) String redirect,
    // @PathVariable("id") Long id, @RequestParam(value = "page", required =
    // false) Integer page,
    // @RequestParam(value = "size", required = false) Integer size, Model
    // uiModel) {

    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();

    parameterTypes.add(helper.createRequestParam(JavaType.STRING, DATATABLES_REDIRECT, true, null));
    final List<AnnotationAttributeValue<?>> annotationAttributes = new ArrayList<AnnotationAttributeValue<?>>();
    annotationAttributes.add(new StringAttributeValue(new JavaSymbolName("value"), "id"));
    parameterTypes.add(new AnnotatedJavaType(entityIdentifier.getFieldType(),
            new AnnotationMetadataBuilder(new JavaType("org.springframework.web.bind.annotation.PathVariable"),
                    annotationAttributes).build()));
    parameterTypes.add(helper.createRequestParam(JavaType.INT_OBJECT, PAGE_VAR, false, null));
    parameterTypes.add(helper.createRequestParam(JavaType.INT_OBJECT, SIZE_VAR, false, null));
    parameterTypes.addAll(AnnotatedJavaType.convertFromJavaTypes(MODEL));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(new JavaSymbolName("deleteDatatablesDetail"), parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

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

    // @RequestMapping(value = "/{id}", method = RequestMethod.DELETE,
    // produces = "text/html", params = "datatablesRedirect")
    AnnotationMetadataBuilder requestMappingAnnotation = helper.getRequestMappingAnnotation(null, null, null,
            DatatablesConstants.RQST_MAP_ANN_VAL_HTML, null, null);
    requestMappingAnnotation.addEnumAttribute(METHOD_VAR, REQUEST_METHOD, "DELETE");
    requestMappingAnnotation.addStringAttribute(PARAMS_VAR, DATATABLES_REDIRECT);
    requestMappingAnnotation.addStringAttribute("value", "/{id}");
    annotations.add(requestMappingAnnotation);

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

    // Define method parameter names
    final List<JavaSymbolName> parameterNames = Arrays.asList(new JavaSymbolName("redirect"),
            new JavaSymbolName("id"), new JavaSymbolName(PAGE_VAR), new JavaSymbolName(SIZE_VAR), UI_MODEL);

    // Add method javadoc (not generated to disk because #10229)
    CommentStructure comments = new CommentStructure();
    JavadocComment javadoc = new JavadocComment("Delete an entity and redirect to given URL.");
    comments.addComment(javadoc, CommentStructure.CommentLocation.BEGINNING);

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

    bodyBuilder
            .appendFormalLine("// Do common delete operations (find, remove, add pagination attributes, ...)");
    // String view = delete(id, page, size, uiModel);
    bodyBuilder.appendFormalLine("String view = delete(id, page, size, uiModel);");
    // if (redirect == null || redirect.trim().isEmpty()) {
    // return view;
    // }
    bodyBuilder.appendFormalLine("// If no redirect, return common list view");
    bodyBuilder.appendFormalLine("if (redirect == null || redirect.trim().isEmpty()) {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("return view;");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");
    bodyBuilder.appendFormalLine("// Redirect to given URL: master datatables");
    // return "redirect:".concat(redirect);
    bodyBuilder.appendFormalLine("return \"redirect:\".concat(redirect);");

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
            new JavaSymbolName("deleteDatatablesDetail"), JavaType.STRING, parameterTypes, parameterNames,
            bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    methodBuilder.setThrowsTypes(throwsTypes);
    methodBuilder.setCommentStructure(comments);

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

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Gets <code>populateParameterMap</code> method. This method transforms a
 * HttpServlerRequest Map<String,String[]> into a Map<String,String>
 * /* w w  w.  ja  v  a2 s . c o  m*/
 * @return
 */
private MethodMetadata getPopulateParameterMapMethod() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(HTTP_SERVLET_REQUEST);

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(POPULATE_PARAMETERS_MAP, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

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

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

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(new JavaSymbolName(DatatablesConstants.REQUEST_PARAMETER_NAME));

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

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

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

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Gets a method to manage AJAX data request of a datatables which draw the
 * result of a Roo Dynamic finder.//  w w w. ja v a 2s  .  co  m
 * 
 * @param finderMethod
 * @param queryHolder
 * @return
 */
private MethodMetadata getAjaxFinderMethod(FinderMetadataDetails finderMethod, QueryHolderTokens queryHolder) {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();

    // Add datatable request parameters
    parameterTypes.add(new AnnotatedJavaType(DATATABLES_CRITERIA_TYPE,
            new AnnotationMetadataBuilder(DATATABLES_PARAMS).build()));

    // Prepares @RequestParam method parameters based on
    // finder information
    List<AnnotatedJavaType> finderParamTypes = finderMethod.getFinderMethodMetadata().getParameterTypes();
    List<JavaSymbolName> finderParamNames = finderMethod.getFinderMethodMetadata().getParameterNames();
    JavaType paramType;
    for (int i = 0; i < finderParamTypes.size(); i++) {
        paramType = finderParamTypes.get(i).getJavaType();
        if (paramType.isBoolean()) {
            // Boolean's false value is omitted on request, so must be
            // optional (by default will get false)
            parameterTypes.add(
                    helper.createRequestParam(paramType, finderParamNames.get(i).getSymbolName(), false, null));
        } else if (paramType.getFullyQualifiedTypeName()
                .equals(new JavaType(Date.class).getFullyQualifiedTypeName())) {
            AnnotationMetadata dateTimeFormatAnnotation = finderMethod.getFinderMethodParamFields().get(i)
                    .getAnnotation(SpringJavaType.DATE_TIME_FORMAT);
            parameterTypes.add(helper.createDateTimeRequestParam(paramType,
                    finderParamNames.get(i).getSymbolName(), null, null, dateTimeFormatAnnotation));

        } else {
            parameterTypes.add(
                    helper.createRequestParam(paramType, finderParamNames.get(i).getSymbolName(), null, null));
        }

    }
    if (!isStantardMode()) {
        // For render mode request and response are needed to
        // perform internal request for item render
        parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST));
        parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_RESPONSE));
    }

    JavaSymbolName methodName = new JavaSymbolName(finderMethod.getFinderName());

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(methodName, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }
    // get Finder-name value
    String finderNameValue = finderMethod.getFinderName();
    finderNameValue = finderNameValue.substring(finderNameValue.indexOf("By"));
    // Define method annotations
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    AnnotationMetadataBuilder methodAnnotation = new AnnotationMetadataBuilder();
    methodAnnotation.setAnnotationType(REQUEST_MAPPING);
    methodAnnotation.addStringAttribute(HEADERS, ACCEPT_APPLICATION_JSON);
    methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_VAL_NAME, "/datatables/ajax");
    methodAnnotation.addStringAttribute(PARAMS_VAR, "ajax_find=".concat(finderNameValue));
    methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_PROD_NAME, APPLICATION_JSON);
    annotations.add(methodAnnotation);
    annotations.add(new AnnotationMetadataBuilder(RESPONSE_BODY));

    // Define method throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();
    if (!isStantardMode()) {
        // On render mode internal render request
        // can throw ServletException or IOException
        throwsTypes.add(SERVLET_EXCEPTION);
        throwsTypes.add(IO_EXCEPTION);
    }

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(CRITERIA_PARAM_NAME);
    for (JavaSymbolName paramName : finderParamNames) {
        parameterNames.add(paramName);
    }
    if (!isStantardMode()) {
        // For render mode request and response are needed to
        // perform internal request for item render
        parameterNames.add(REQUEST_PARAM_NAME);
        parameterNames.add(RESPONSE_PARAM_NAME);
    }

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    buildFinderAjaxMethodBody(bodyBuilder, finderMethod, queryHolder);

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

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

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Gets <code>populateDatatablesConfig</code> method <br>
 * This method insert on Model all configuration properties which will need
 * ".tagx" to render final page. <br>
 * This properties are:/*from  www  .j a  va  2  s  .c o  m*/
 * <ul>
 * <li><em>datatablesHasBatchSupport</em> informs if there is batch entity
 * operations support on controller (used for multi-row delete operation)</li>
 * <li><em>datatablesUseAjax</em> informs datatables data mode (
 * <em>true</em> : AJAX <em>false</em> DOM)</li>
 * <li><em>finderNameParam</em> sets the name of parameter that will contain
 * the {@code finderName} (only for AJAX mode)</li>
 * <li><em>datatablesStandardMode</em> informs render mode (<em>true</em>
 * for standard datatable view; <em>false</em> for single-item-page,
 * one-cell-per-item or render-jspx datatable modes)</li>
 * </ul>
 * 
 * @return
 */
private MethodMetadata getPopulateDatatablesConfig() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(MODEL);

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(POPULATE_DATATABLES_CONFIG, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

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

    AnnotationMetadataBuilder annotation = new AnnotationMetadataBuilder(MODEL_ATTRIBUTE);
    // @ModelAttribute
    annotations.add(annotation);

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

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(UI_MODEL);

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine(
            String.format("uiModel.addAttribute(\"datatablesHasBatchSupport\", %s);", hasJpaBatchSupport()));
    bodyBuilder.appendFormalLine(String.format("uiModel.addAttribute(\"datatablesUseAjax\",%s);", isAjax()));
    bodyBuilder.appendFormalLine(
            String.format("uiModel.addAttribute(\"datatablesInlineEditing\",%s);", isInlineEditing()));
    bodyBuilder.appendFormalLine(
            String.format("uiModel.addAttribute(\"datatablesInlineCreating\",%s);", isInlineEditing()));

    // TODO
    bodyBuilder.appendFormalLine(
            String.format("uiModel.addAttribute(\"datatablesSecurityApplied\",%s);", isSecurityApplied()));

    bodyBuilder.appendFormalLine(
            String.format("uiModel.addAttribute(\"datatablesStandardMode\",%s);", isStantardMode()));
    if (isAjax()) {
        bodyBuilder.appendFormalLine("uiModel.addAttribute(\"finderNameParam\",\"ajax_find\");");
    }

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
            POPULATE_DATATABLES_CONFIG, 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.datatables.addon.DatatablesMetadata.java

/**
 * Gets <code>populateItemForRender</code> method <br>
 * This methods prepares request attributes to render a entity item in
 * non-standard render mode. User can make push-in of this method to
 * customize the parameters received on target .jspx view.
 * /*  w ww .  j a va  2  s .c  o  m*/
 * @return
 */
private MethodMetadata getPopulateItemForRenderMethod() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(HTTP_SERVLET_REQUEST,
            entity, JavaType.BOOLEAN_PRIMITIVE);

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(POPULATE_ITEM_FOR_RENDER, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

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

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

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(REQUEST_PARAM_NAME);
    parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(entityName)));
    parameterNames.add(new JavaSymbolName("editing"));

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

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
            POPULATE_ITEM_FOR_RENDER, 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.datatables.addon.DatatablesMetadata.java

/**
 * Gets <code>checkFilterExpressions</code> method <br>
 * This methods checks if the current filter expression is appropieta for
 * the property type.// ww w . j a  v  a 2 s .  com
 * 
 * @return If is correct, return true, if not, return false,
 */
private MethodMetadata getCheckFilterExpressionsMethod() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();

    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(WEB_REQUEST));
    parameterTypes.add(helper.createRequestParam(JavaType.STRING, "property", false, null));
    parameterTypes.add(helper.createRequestParam(JavaType.STRING, "expression", false, null));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(CHECK_FILTER_EXPRESSIONS, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

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

    AnnotationMetadataBuilder methodAnnotation = new AnnotationMetadataBuilder();
    methodAnnotation.setAnnotationType(REQUEST_MAPPING);
    methodAnnotation.addStringAttribute(HEADERS, ACCEPT_APPLICATION_JSON);
    methodAnnotation.addStringAttribute(PARAMS_VAR, "checkFilters");
    annotations.add(methodAnnotation);
    annotations.add(new AnnotationMetadataBuilder(RESPONSE_BODY));

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

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(REQUEST_PARAM_NAME);
    parameterNames.add(new JavaSymbolName("property"));
    parameterNames.add(new JavaSymbolName("expression"));

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

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

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

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Returns <code>geti18nText</code> method <br>
 * This method returns column type after AJAX request
 * /*from   www .j ava2 s  . c o m*/
 * @return
 */
private MethodMetadata geti18nTextRequestMethod() {
    // Define method parameter types

    final List<AnnotatedJavaType> parameterTypes = Arrays.asList(new AnnotatedJavaType(MODEL),
            AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST),
            helper.createRequestParam(JavaType.STRING, "_locale_", false, null));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(GET_I18N_TEXT, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

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

    // @RequestMapping
    AnnotationMetadataBuilder methodAnnotation = new AnnotationMetadataBuilder();
    methodAnnotation.setAnnotationType(REQUEST_MAPPING);

    // @RequestMapping(headers = "Accept=application/json"...
    methodAnnotation.addStringAttribute(HEADERS, ACCEPT_APPLICATION_JSON);

    // @RequestMapping(params = "geti18nText"...
    methodAnnotation.addStringAttribute(PARAMS_VAR, "geti18nText");

    // @ResponseBody
    annotations.add(new AnnotationMetadataBuilder(RESPONSE_BODY));

    annotations.add(methodAnnotation);

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

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(UI_MODEL);
    parameterNames.add(new JavaSymbolName(DatatablesConstants.REQUEST_PARAMETER_NAME));
    parameterNames.add(new JavaSymbolName("locale"));

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

    buildGeti18nTextMethodBody(bodyBuilder);

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

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

From source file:org.gvnix.addon.datatables.addon.DatatablesMetadata.java

/**
 * Returns <code>getColumnType</code> method <br>
 * This method is to return column type after AJAX request
 * //ww w.j a v a2  s  .  c  om
 * @return
 */
private MethodMetadata getColumnTypeRequestMethod() {
    // Define method parameter types

    final List<AnnotatedJavaType> parameterTypes = Arrays.asList(new AnnotatedJavaType(MODEL),
            AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST),
            helper.createRequestParam(JavaType.STRING, "_columnName_", false, null));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(GET_COLUMN_TYPE, parameterTypes);
    if (method != null) {
        // If it already exists, just return the method and omit its
        // generation via the ITD
        return method;
    }

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

    // @RequestMapping
    AnnotationMetadataBuilder methodAnnotation = new AnnotationMetadataBuilder();
    methodAnnotation.setAnnotationType(REQUEST_MAPPING);

    // @RequestMapping(headers = "Accept=application/json"...
    methodAnnotation.addStringAttribute(HEADERS, ACCEPT_APPLICATION_JSON);

    // @RequestMapping(params = "getColumnType"...
    methodAnnotation.addStringAttribute(PARAMS_VAR, "getColumnType");

    // @ResponseBody
    annotations.add(new AnnotationMetadataBuilder(RESPONSE_BODY));

    annotations.add(methodAnnotation);

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

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(UI_MODEL);
    parameterNames.add(new JavaSymbolName(DatatablesConstants.REQUEST_PARAMETER_NAME));
    parameterNames.add(new JavaSymbolName("columnName"));

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

    buildGetColumnTypeMethodBody(bodyBuilder);

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

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