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.datatables.addon.DatatablesMetadata.java

/**
 * Create metadata for beanWrapper field.
 * // w  w  w.  j av  a 2s.  co m
 * @return a FieldMetadata object
 */
public FieldMetadata getBeanWrapperField() {
    if (beanWrapper == null) {
        JavaSymbolName curName = new JavaSymbolName("beanWrapper_dtt");
        // Check if field exist
        FieldMetadata currentField = governorTypeDetails.getDeclaredField(curName);
        if (currentField != null && !isBeanWrapperField(currentField)) {
            // No compatible field: look for new name
            currentField = null;
            JavaSymbolName newName = new JavaSymbolName("beanWrapper_dt");
            currentField = governorTypeDetails.getDeclaredField(newName);
            while (currentField != null && !isConversionServiceField(currentField)) {
                newName = new JavaSymbolName(newName.getSymbolName().concat("_"));
                currentField = governorTypeDetails.getDeclaredField(newName);
            }
            curName = newName;
        }
        if (currentField != null) {
            beanWrapper = currentField;
        } else {
            // create field
            List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(1);
            // Using the FieldMetadataBuilder to create the field
            // definition.
            final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(getId(), Modifier.PUBLIC,
                    annotations, curName, // Field
                    BEAN_WRAPPER); // Field type
            beanWrapper = fieldBuilder.build(); // Build and return a
                                                // FieldMetadata
                                                // instance
        }
    }
    return beanWrapper;
}

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

/**
 * Returns export method for a specific format for a render-a-view
 * visualization mode.//  ww w  .  j  a v a 2 s.  c  o  m
 * <p />
 * This method handles datatables AJAX request for export data to a format
 * specified in the @{code exportType} parameter.
 * 
 * @param exportType the export type: csv, xml, pdf, etc.
 * @param exportTypeJavaType the @{code JavaType} of the export type.
 * @return
 */
private MethodMetadata getExportFormatMethod(String exportType, JavaType exportTypeJavaType) {

    String exportTypeUpperCase = StringUtils.upperCase(exportType);
    String exportTypeCapitalized = StringUtils.capitalize(exportType);

    /*
     * @RequestMapping(value = "/exportcsv", produces = "text/csv") public
     * void PetController.exportCsv(
     *
     * @DatatablesParams DatatablesCriterias criterias,
     *
     * @ModelAttribute Pet pet, HttpServletRequest request,
     * HttpServletResponse response) throws ServletException, IOException,
     * ExportException { ... }
     */
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(new AnnotatedJavaType(DATATABLES_CRITERIA_TYPE,
            new AnnotationMetadataBuilder(DATATABLES_PARAMS).build()));
    parameterTypes.add(new AnnotatedJavaType(entity, new AnnotationMetadataBuilder(MODEL_ATTRIBUTE).build()));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_RESPONSE));

    // Building method name
    JavaSymbolName methodName = new JavaSymbolName("export".concat(exportTypeCapitalized));

    // 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;
    }

    // Define method annotations
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    AnnotationMetadataBuilder methodAnnotation = new AnnotationMetadataBuilder();
    methodAnnotation.setAnnotationType(REQUEST_MAPPING);
    methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_VAL_NAME,
            "/export".concat(exportType));
    methodAnnotation.addStringAttribute(DatatablesConstants.RQST_MAP_ANN_PROD_NAME, "text/".concat(exportType));
    annotations.add(methodAnnotation);

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

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

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

    /*
     * export(criterias, pet, ExportType.CSV, new CsvExport(), request,
     * response);
     */
    String format = "export(%s, %s, %s.".concat(exportTypeUpperCase).concat(", new %s(), %s, %s);");
    bodyBuilder.appendFormalLine(String.format(format, CRITERIA_PARAM_NAME.getSymbolName(),
            StringUtils.uncapitalize(entityName), helper.getFinalTypeName(DATATABLES_EXPORT_TYPE),
            helper.getFinalTypeName(exportTypeJavaType), REQUEST_PARAM_NAME.getSymbolName(),
            RESPONSE_PARAM_NAME.getSymbolName()));

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

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

From source file:gov.nih.nci.security.dao.AuthorizationDAOImpl.java

public Object secureUpdate(String userName, Object originalObject, Object mutatedObject) throws CSException {
    //Object o = null;
    if (StringUtilities.isBlank(userName)) {
        throw new CSException("No user name have been supplied!");
    }//from  w  ww .j a v a 2  s  .  c o m
    if (originalObject == null || mutatedObject == null) {
        return originalObject;
    }
    try {

        Class cl = originalObject.getClass();
        log.debug(cl.getName());
        ObjectAccessMap accessMap = this.getObjectAccessMap(cl.getName(), userName, "UPDATE");

        //o = cl.newInstance();
        Method methods[] = cl.getDeclaredMethods();

        for (int i = 0; i < methods.length; i++) {
            Method m = methods[i];

            String name = m.getName();
            log.debug("Method is: " + name);
            //log.debug("Name from outer block"+name);
            //log.debug("Para type"+m.getParameterTypes());
            if (name.startsWith("set") && (m.getModifiers() == Modifier.PUBLIC)) {
                String att = name.substring(3, name.length());
                log.debug("Attribute is: " + att);
                String methodName = "get" + att;
                //log.debug(methodName);
                Method m2 = cl.getMethod(methodName, (Class[]) null);
                //log.debug("Method Name m2"+m2.getName());
                //log.debug(m2.invoke(obj,null));
                if (!accessMap.hasAccess(att)) {
                    log.debug("No Access to update attribute: " + att);
                    Object origValue = m2.invoke(originalObject, (Object[]) null);
                    if (origValue != null) {
                        log.debug("Original value is: " + origValue.toString());
                    }
                    m.invoke(mutatedObject, new Object[] { origValue });
                } else {
                    log.debug("Access permitted to update attribute: " + att);
                }
            }
        }

    } catch (Exception ex) {
        log.error("Error Securing object", ex);
        if (log.isDebugEnabled())
            log.debug("Authorization||" + userName + "|secureUpdate|Failure|Error in Secure Update|"
                    + ex.getMessage());

        throw new CSException("Failed to secure update the object:" + ex.getMessage(), ex);
    }

    return mutatedObject;

}

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

/**
 * Returns <code>export</code> method for a render-a-view visualization
 * mode.//from  ww  w . j  av a 2  s .c o  m
 * <p />
 * This is a private method that handles datatables AJAX request for a
 * specific format.
 * 
 * @return
 */
private MethodMetadata getExportMethod() {

    /*
     * private void export(DatatablesCriterias criterias, Pet pet,
     * ExportType exportType, DatatablesExport datatablesExport,
     * HttpServletRequest request, HttpServletResponse response) throws
     * ExportException { ... }
     */
    // 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(DATATABLES_EXPORT_TYPE));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(DATATABLES_EXPORT));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_REQUEST));
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(HTTP_SERVLET_RESPONSE));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(EXPORT_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 throws types (none in this case)
    List<JavaType> throwsTypes = new ArrayList<JavaType>();
    throwsTypes.add(DATATABLES_EXPORT_EXCEPTION);

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

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

    /*
     * // Does the export process as is explained in
     * http://dandelion.github.
     * io/datatables/tutorials/export/controller-based-exports.html // 1.
     * Retrieve the data List<Map<String, String>> data =
     * retrieveData(criterias, pet, request);
     */
    bodyBuilder.appendFormalLine(
            "// Does the export process as is explained in http://dandelion.github.io/datatables/tutorials/export/controller-based-exports.html");
    bodyBuilder.appendFormalLine("// 1. Retrieve the data");
    String format = "%s data = retrieveData(%s, %s, %s);";
    bodyBuilder.appendFormalLine(String.format(format, helper.getFinalTypeName(LIST_MAP_STRING_STRING),
            CRITERIA_PARAM_NAME.getSymbolName(), new JavaSymbolName(StringUtils.uncapitalize(entityName)),
            REQUEST_PARAM_NAME.getSymbolName()));

    /*
     * // 2. Build an instance of "ExportConf". ExportConf exportConf = new
     * ExportConf.Builder(exportType).header(true)
     * .exportClass(datatablesExport).autoSize(true)
     * .fileName(pet.getClass().getSimpleName()).build();
     */
    bodyBuilder.appendFormalLine("// 2. Build an instance of \"ExportConf\"");
    format = "%s exportConf = new %s.Builder(%s).header(true).exportClass(%s).autoSize(true).fileName(%s.getClass().getSimpleName()).build();";
    bodyBuilder.appendFormalLine(String.format(format, helper.getFinalTypeName(DATATABLES_EXPORT_CONF),
            helper.getFinalTypeName(DATATABLES_EXPORT_CONF), DATATABLES_EXPORT_TYPE_NAME.getSymbolName(),
            DATATABLES_EXPORT_NAME.getSymbolName(), StringUtils.uncapitalize(entityName)));

    /*
     * // 3. Build an instance of "HtmlTable" HtmlTable table =
     * datatablesUtilsBean_dtt.makeHtmlTable(data, criterias, exportConf, request);
     */
    bodyBuilder.appendFormalLine("// 3. Build an instance of \"HtmlTable\"");
    format = "%s table = %s.makeHtmlTable(data, %s, exportConf, %s);";
    bodyBuilder.appendFormalLine(
            String.format(format, helper.getFinalTypeName(DATATABLES_HTML_TABLE), getDatatablesUtilsBeanName(),
                    CRITERIA_PARAM_NAME.getSymbolName(), REQUEST_PARAM_NAME.getSymbolName()));

    /*
     * // 4. Render the generated export file
     * ExportUtils.renderExport(table, exportConf, response);
     */
    bodyBuilder.appendFormalLine("// 4. Render the generated export file");
    format = "%s.renderExport(table, exportConf, %s);";
    bodyBuilder.appendFormalLine(String.format(format, helper.getFinalTypeName(DATATABLES_EXPORT_UTILS),
            RESPONSE_PARAM_NAME.getSymbolName()));

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

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