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.gva.security.providers.safe.SafeSecurityProviderExtLoadWSS4JMetadata.java

/**
 * Generates handleMessage method with SoapMessage argument
 *//* w  ww  .  j  a  va 2  s .  co m*/
private MethodMetadata getHandleMessageMethod() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType
            .convertFromJavaTypes(SOAP_MESSAGE_PARAM_ARRAY_TYPE);

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(HANDLE_MESSAGE_METHOD, 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>();

    // Create reference to override annotation
    AnnotationMetadataBuilder overrideAnnotation = new AnnotationMetadataBuilder();
    overrideAnnotation.setAnnotationType(new JavaType("java.lang.Override"));

    // Define method throws types
    List<JavaType> throwsTypes = new ArrayList<JavaType>();
    throwsTypes.add(FAULT_EXCEPTION);

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

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

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

    // Add javadoc
    List<AbstractComment> listComments = new ArrayList<AbstractComment>();
    CommentStructure comStruct = new CommentStructure();
    JavadocComment jvDocCom = new JavadocComment();
    StringBuilder strB = new StringBuilder("Add property Id_trazabilidad");
    strB.append(" head to SOAP message \n\n@param mc SoapMessage where add");
    strB.append(" traceability head");
    jvDocCom.setComment(strB.toString());
    listComments.add(jvDocCom);
    comStruct.setBeginComments(listComments);
    methodBuilder.setCommentStructure(comStruct);

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

From source file:com.viadee.acceptancetests.roo.addon.AcceptanceTestsOperations.java

private void insertStoryIntoStoryGroup(String story, String storyGroup) throws IOException {
    JavaType fullyQualifiedTestName = new JavaType(
            _acceptanceTestsUtils.acceptancetestsPackageName() + "." + storyGroup + "Stories");
    String storyGroupIdentifier = PhysicalTypeIdentifier.createIdentifier(fullyQualifiedTestName,
            Path.SRC_TEST_JAVA);//w  ww  .  j a  v  a  2s .c  o  m

    PhysicalTypeMetadata storyGroupMetadata = (PhysicalTypeMetadata) _metadataService.get(storyGroupIdentifier);
    if (storyGroupMetadata == null) {
        List<MethodMetadata> methods = new ArrayList<MethodMetadata>();

        methods.add(newTestMethod(storyGroupIdentifier, story));

        List<AnnotationMetadata> annotations = annotations(
                new JavaType("com.viadee.acceptancetests.roo.addon.RooAcceptanceTestGroup"));
        ClassOrInterfaceTypeDetails details = new DefaultClassOrInterfaceTypeDetails(storyGroupIdentifier,
                fullyQualifiedTestName, Modifier.PUBLIC, PhysicalTypeCategory.CLASS, null, null, methods, null,
                null, null, annotations, null);
        _classpathOperations.generateClassFile(details);
    } else {
        MutableClassOrInterfaceTypeDetails storyGroupDetails = (MutableClassOrInterfaceTypeDetails) storyGroupMetadata
                .getPhysicalTypeDetails();

        List<? extends MethodMetadata> methods = storyGroupDetails.getDeclaredMethods();
        for (MethodMetadata methodMetadata : methods) {
            if (methodMetadata.getMethodName().getSymbolName().equals(methodNameFromStory(story))) {
                throw new IllegalStateException(String.format(
                        "There already is an acceptance test with the story \"%s\" in the group \"%s\"",
                        methodNameFromStory(story), storyGroup));
            }
        }

        storyGroupDetails.addMethod(newTestMethod(storyGroupIdentifier, story));
    }
}

From source file:org.gvnix.flex.FlexScaffoldMetadata.java

private MethodMetadata getListPagedMethod() {
    JavaSymbolName methodName = new JavaSymbolName("listPaged");

    MethodMetadata method = methodExists(methodName);
    if (method != null) {
        return method;
    }/* www  . ja v  a 2  s.co  m*/

    List<JavaType> typeParams = new ArrayList<JavaType>();
    typeParams.add(this.entity);
    JavaType returnType = new JavaType("java.util.List", 0, DataType.TYPE, null, typeParams);

    List<AnnotatedJavaType> paramTypes = new ArrayList<AnnotatedJavaType>();
    paramTypes.add(new AnnotatedJavaType(new JavaType("Integer"), new ArrayList<AnnotationMetadata>()));
    paramTypes.add(new AnnotatedJavaType(new JavaType("Integer"), new ArrayList<AnnotationMetadata>()));

    List<JavaSymbolName> paramNames = new ArrayList<JavaSymbolName>();
    paramNames.add(new JavaSymbolName("page"));
    paramNames.add(new JavaSymbolName("size"));

    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("if (page != null || size != null) {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("int sizeNo = size == null ? 10 : size.intValue();");
    bodyBuilder.appendFormalLine("return "
            + this.entity.getNameIncludingTypeParameters(false, this.builder.getImportRegistrationResolver())
            + "."
            + new JpaCrudAnnotationValues(this.entityMetadata).getFindEntriesMethod()
                    .concat(this.entityMetadata.getEntityName()).concat("Entries")
            + "(page == null ? 0 : (page.intValue() - 1) * sizeNo, sizeNo);");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("} else {");
    bodyBuilder.indent();
    bodyBuilder.appendFormalLine("return list();");
    bodyBuilder.indentRemove();
    bodyBuilder.appendFormalLine("}");

    return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, returnType, paramTypes, paramNames,
            bodyBuilder).build();
}

From source file:io.stallion.reflection.PropertyUtils.java

public static Boolean isReadable(Object obj, String name) {
    String cacheKey = obj.getClass().getCanonicalName() + "|" + name;
    if (lookupCache.containsKey(cacheKey)) {
        return (Boolean) lookupCache.get(cacheKey);
    }/*from w  w w.jav a2s .  c o  m*/

    String postFix = name.toUpperCase();
    if (name.length() > 1) {
        postFix = name.substring(0, 1).toUpperCase() + name.substring(1);
    }
    Method method = null;
    try {
        method = obj.getClass().getMethod("get" + postFix, (Class<?>[]) null);
    } catch (NoSuchMethodException e) {

    }
    if (method == null) {
        try {
            method = obj.getClass().getMethod("is" + postFix, (Class<?>[]) null);
        } catch (NoSuchMethodException e) {

        }
    }
    if (method == null) {
        lookupCache.put(cacheKey, false);
        return false;
    }
    if (method.getModifiers() == Modifier.PUBLIC) {
        lookupCache.put(cacheKey, true);
        return true;
    }
    lookupCache.put(cacheKey, false);
    return false;
}

From source file:org.gvnix.addon.loupefield.addon.LoupefieldMetadata.java

/**
 * Gets <code>showOnlyList</code> method. <br>
 * //  w  w w . j  a va 2s. c  om
 * @return
 */
private MethodMetadata getShowOnlyListMethod(JavaType entity) {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(
            new JavaType("org.springframework.ui.Model"),
            new JavaType("javax.servlet.http.HttpServletRequest"));

    AnnotationMetadataBuilder pathMetadataBuilder = new AnnotationMetadataBuilder(SpringJavaType.REQUEST_PARAM);
    pathMetadataBuilder.addStringAttribute(VALUE_LABEL, "path");

    parameterTypes.add(new AnnotatedJavaType(JavaType.STRING, pathMetadataBuilder.build()));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(SHOW_ONLY_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 annotations
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();

    AnnotationMetadataBuilder requestMappingMetadataBuilder = new AnnotationMetadataBuilder(
            SpringJavaType.REQUEST_MAPPING);

    requestMappingMetadataBuilder.addStringAttribute("params", "selector");
    requestMappingMetadataBuilder.addStringAttribute("produces", "text/html");

    annotations.add(requestMappingMetadataBuilder);

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

    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(new JavaSymbolName("uiModel"));
    parameterNames.add(new JavaSymbolName("request"));
    parameterNames.add(new JavaSymbolName("listPath"));

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

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

/**
 * @return the getOnCreate method definition
 *//*  w  w w.  ja v  a  2  s  .c o  m*/
private MethodMetadata getOnCreateMethod() {
    // method name
    JavaSymbolName methodName = ON_CREATE_METHOD;

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

    // 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>();
    annotations.add(new AnnotationMetadataBuilder(JPA_PRE_PRESIST));

    // 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(entityParamName);

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

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

From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java

protected BlockStatement getOrCreateMethodBody(ClassNode classNode, MethodNode setupMethod, String name) {
    BlockStatement methodBody;//from  ww w . j ava2  s  .  c o  m
    if (setupMethod.getDeclaringClass().getName().equals(TestCase.class.getName())) {
        methodBody = new BlockStatement();
        setupMethod = new MethodNode(name, Modifier.PUBLIC, setupMethod.getReturnType(), ZERO_PARAMETERS, null,
                methodBody);
        classNode.addMethod(setupMethod);
    } else {
        final Statement setupMethodBody = setupMethod.getCode();
        if (!(setupMethodBody instanceof BlockStatement)) {
            methodBody = new BlockStatement();
            if (setupMethodBody != null) {
                if (!(setupMethodBody instanceof ReturnStatement)) {
                    methodBody.addStatement(setupMethodBody);
                }
            }
            setupMethod.setCode(methodBody);
        } else {
            methodBody = (BlockStatement) setupMethodBody;
        }
    }
    return methodBody;
}

From source file:org.gvnix.support.ItdBuilderHelper.java

/**
 * Prepares a field-getter method.//from   w w  w .  j  a  v  a 2  s.c o  m
 * <p/>
 * First, try to locate it on governor. Otherwise create it.
 * 
 * @param filedName
 * @param methodName
 * @param fieldType
 * @param aAnnotations (optional) annotation list
 * @return
 */
public MethodMetadata getGetterMethod(JavaSymbolName filedName, JavaSymbolName methodName, JavaType fieldType,
        List<AnnotationMetadataBuilder> aAnnotations) {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();

    // 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>();
    if (aAnnotations != null) {
        annotations.addAll(aAnnotations);
    }

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

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

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

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

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

From source file:org.gvnix.addon.geo.addon.GvNIXMapViewerMetadata.java

/**
 * Gets <code>showMap</code> method. <br>
 * //from  w  ww. ja  v  a2  s .  com
 * @return
 */
private MethodMetadata getShowMapMethod(String path) {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(new AnnotatedJavaType(SpringJavaType.MODEL));
    parameterTypes.add(new AnnotatedJavaType(new JavaType("javax.servlet.http.HttpServletRequest")));

    // Check if a method with the same signature already exists in the
    // target type
    final MethodMetadata method = methodExists(SHOW_MAP_METHOD, 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 requestMappingMetadataBuilder = new AnnotationMetadataBuilder(
            SpringJavaType.REQUEST_MAPPING);

    requestMappingMetadataBuilder.addEnumAttribute("method", SpringJavaType.REQUEST_METHOD, "GET");
    requestMappingMetadataBuilder.addStringAttribute("produces", "text/html");
    annotations.add(requestMappingMetadataBuilder);

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

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

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

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, SHOW_MAP_METHOD,
            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.web.screen.roo.addon.RelatedPatternMetadata.java

/**
 * @see org.springframework.roo.addon.web.mvc.controller.scaffold.mvc.getCreateFormMethod
 * @param patternName/*from www .j a  v  a 2 s .  c om*/
 * @return
 */
protected MethodMetadata getCreateFormMethod(String patternName) {

    Validate.notNull(masterEntity, "Master entity required to generate createForm");
    Validate.notNull(masterEntityJavaDetails, "Master entity metadata required to generate createForm");

    JavaSymbolName methodName = new JavaSymbolName("createForm" + patternName);

    // Create method params: annotation, type and name

    List<AnnotatedJavaType> paramTypes = new ArrayList<AnnotatedJavaType>();
    List<JavaSymbolName> paramNames = new ArrayList<JavaSymbolName>();

    // @RequestParam(value = "gvnixpattern", required = true) String
    // gvnixpattern
    Entry<JavaSymbolName, AnnotatedJavaType> gvnixpatternParam = getPatternRequestParam(true);
    paramNames.add(gvnixpatternParam.getKey());
    paramTypes.add(gvnixpatternParam.getValue());

    // @RequestParam(value = "gvnixreference", required = true)
    // MasterEntityIdType gvnixreference
    Entry<JavaSymbolName, AnnotatedJavaType> gvnixreferenceParam = getReferenceRequestParam();
    paramNames.add(gvnixreferenceParam.getKey());
    paramTypes.add(gvnixreferenceParam.getValue());

    // Model uiModel
    Entry<JavaSymbolName, AnnotatedJavaType> modelParam = getModelRequestParam();
    paramNames.add(modelParam.getKey());
    paramTypes.add(modelParam.getValue());

    // Create method annotation

    List<AnnotationMetadataBuilder> methodAnnotations = new ArrayList<AnnotationMetadataBuilder>();

    // @RequestMapping(params = { "form",
    // "gvnixpattern=AplicacionListados2", "gvnixreference" }, method =
    // RequestMethod.GET)
    methodAnnotations.add(getRequestMapping(patternName, RequestMethod.GET));

    // If method exists (in java file, by example) no create it in AspectJ
    // file
    if (methodExists(methodName, paramTypes) != null) {
        return null;
    }

    // Create method body

    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();

    String entityName = entity.getSimpleTypeName();

    appendMasterRelationToEntity(bodyBuilder);

    /*
     * uiModel.addAttribute("entityName", entityname);
     * addDateTimeFormatPatterns(uiModel); // Only if date types exists
     * return "entitynames/create";
     */

    // Add attribute with identical name as required by Roo create page
    bodyBuilder.appendFormalLine(
            "uiModel.addAttribute(\"" + uncapitalize(entityName) + "\", " + entityName.toLowerCase() + ");");
    if (!entityDateTypes.isEmpty()) {

        bodyBuilder.appendFormalLine("addDateTimeFormatPatterns(uiModel);");
    }

    bodyBuilder.appendFormalLine(
            RETURN_QUOTE + webScaffoldMetadata.getAnnotationValues().getPath() + "/create\";");

    // TODO Remove dependencies or add it from entity pattern ?

    MethodMetadataBuilder method = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
            JavaType.STRING, paramTypes, paramNames, bodyBuilder);
    method.setAnnotations(methodAnnotations);

    return method.build();
}