Example usage for java.lang.reflect Modifier PRIVATE

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

Introduction

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

Prototype

int PRIVATE

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

Click Source Link

Document

The int value representing the private modifier.

Usage

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

/**
 * Returns <code>retrieveData</code> method for a render-a-view
 * visualization mode./*w w w.  j  ava 2s . com*/
 * 
 * @return
 */
private MethodMetadata getRetrieveDataMethod() {

    /*
     * private List<Map<String, String>> retrieveData( DatatablesCriterias
     * criterias, Pet pet, HttpServletRequest request) { ... }
     */

    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(DATATABLES_CRITERIA_TYPE));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(entity));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST));

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

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

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

    /*
     * // Cloned criteria in order to not paginate the results
     * DatatablesCriterias noPaginationCriteria = new DatatablesCriterias(
     * criterias.getSearch(), 0, null, criterias.getColumnDefs(),
     * criterias.getSortingColumnDefs(), criterias.getInternalCounter());
     */
    bodyBuilder.appendFormalLine("// Cloned criteria in order to not paginate the results");
    String format = "%s noPaginationCriteria = new %s(%s.getSearch(), 0, null, %s.getColumnDefs(), %s.getSortingColumnDefs(), %s.getInternalCounter());";
    String datatablesCriteriaType = helper.getFinalTypeName(DATATABLES_CRITERIA_TYPE);
    String criteriaParamName = CRITERIA_PARAM_NAME.getSymbolName();
    bodyBuilder.appendFormalLine(String.format(format, datatablesCriteriaType, datatablesCriteriaType,
            criteriaParamName, criteriaParamName, criteriaParamName, criteriaParamName));

    /*
     * // Do the search to obtain the data Map<String, Object>
     * baseSearchValuesMap = getPropertyMap(XXX, request);
     * setDatatablesBaseFilter(baseSearchValuesMap);
     */
    bodyBuilder.appendFormalLine("// Do the search to obtain the data");
    bodyBuilder
            .appendFormalLine(String.format("Map<String, Object> baseSearchValuesMap = getPropertyMap(%s, %s);",
                    new JavaSymbolName(entityName), REQUEST_PARAM_NAME));
    bodyBuilder.appendFormalLine("setDatatablesBaseFilter(baseSearchValuesMap);");

    /*
     * SearchResults<Visit> searchResult = datatablesUtilsBean_dtt.findByCriteria(
     * Visit.class, noPaginationCriteria,
     * baseSearchValuesMap); org.springframework.ui.Model uiModel = new
     * org.springframework.ui.ExtendedModelMap();
     */
    format = "%s searchResult = %s.findByCriteria(%s.class, noPaginationCriteria, baseSearchValuesMap);";
    String entityTypeName = helper.getFinalTypeName(entity);
    bodyBuilder.appendFormalLine(String.format(format,
            new JavaType(SEARCH_RESULTS.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
                    Arrays.asList(entity)),
            getDatatablesUtilsBeanName(), entityTypeName, DATATABLES_MANAGER_PROVIDER_NAME, entityTypeName));

    String dateFormatVarName = getCodeToAddDateTimeFormatPatterns(bodyBuilder);

    /*
     * // Use ConversionService with the obtained data return
     * datatablesUtilsBean_dtt.populateDataSet(searchResult.getResults(), "id",
     * searchResult.getTotalCount(), searchResult.getResultsCount(),
     * criterias.getColumnDefs(), null) .getRows();
     */
    bodyBuilder.appendFormalLine("// Use ConversionService with the obtained data");
    format = "return %s.populateDataSet(searchResult.getResults(), \"id\", searchResult.getTotalCount(), searchResult.getResultsCount(), %s.getColumnDefs(), %s).getRows();";
    bodyBuilder.appendFormalLine(String.format(format, getDatatablesUtilsBeanName(),
            CRITERIA_PARAM_NAME.getSymbolName(), dateFormatVarName));

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PRIVATE,
            RETRIEVE_DATA_METHOD_NAME, LIST_MAP_STRING_STRING, parameterTypes, parameterNames, bodyBuilder);

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