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

/**
 * Gets <code>additionalAuthenticationChecks</code> method. <br>
 * //www.  j a va  2 s . c o m
 * @return
 */
private MethodMetadata getConvertToApplicationRolMethod() {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType.convertFromJavaTypes(JAVA_TYPE_STRING);

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

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

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

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

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PRIVATE,
            APPLICATION_ROL_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.addon.jpa.addon.audit.providers.envers.EnversRevisionLogEntityMetadataBuilder.java

private FieldMetadata getUserField() {
    if (userField == null) {
        List<AnnotationMetadataBuilder> annotations = null;
        if (context.getUserTypeIsEntity()) {
            annotations = new ArrayList<AnnotationMetadataBuilder>(1);
            annotations//from w ww.  j  a  v  a  2s  .  co m
                    .add(new AnnotationMetadataBuilder(AnnotationMetadataBuilder.JPA_MANY_TO_ONE_ANNOTATION));

        }
        userField = helper.getField(USER_FIELD, Modifier.PRIVATE, context.getUserType(), annotations,
                GET_FIELD_EXISTS_ACTION.RETURN_EXISTING_IF_ANNOTATION_MATCH);
    }
    return userField;
}

From source file:org.jenkinsci.plugins.ghprb.GhprbTestUtil.java

public static List<String> checkClassForGetters(Class<?> clazz) {
    Field[] fields = clazz.getDeclaredFields();
    List<Field> xmlFields = new ArrayList<Field>();
    List<String> errors = new ArrayList<String>();

    for (Field field : fields) {
        int modifiers = field.getModifiers();
        if (modifiers == (Modifier.PRIVATE) || modifiers == (Modifier.PRIVATE | Modifier.FINAL)) {
            xmlFields.add(field);/*  w w  w . jav  a 2 s. co  m*/
        }
    }

    for (Field field : xmlFields) {
        String getter = "get" + StringUtils.capitalize(field.getName());
        try {
            Method method = clazz.getDeclaredMethod(getter);
            int modifier = method.getModifiers();
            if (!Modifier.isPublic(modifier)) {
                errors.add(getter + " is not a public method");
            }
        } catch (Exception e) {
            String wrongGetter = "is" + StringUtils.capitalize(field.getName());
            try {
                clazz.getDeclaredMethod(wrongGetter);
                errors.add("Setter is using the wrong name, is " + wrongGetter + " and should be " + getter);
            } catch (Exception err) {
                errors.add("Missing " + getter);
            }
        }
    }
    return errors;
}

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

private FieldMetadata getTimestampField() {
    if (timestampField == null) {
        List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        annotations.add(new AnnotationMetadataBuilder(REVISION_TIMESTAMP));
        timestampField = helper.getField(TIMESTAMP_FIELD, Modifier.PRIVATE, JavaType.LONG_OBJECT, annotations,
                GET_FIELD_EXISTS_ACTION.RETURN_EXISTING_IF_ANNOTATION_MATCH);
    }/* w  w  w  .  j  a  va2  s  .co  m*/
    return timestampField;
}

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

/**
 * @param helper/* ww  w .  ja v  a  2s .  com*/
 * @return
 */
private FieldMetadata getIdField() {
    if (idField == null) {
        List<AnnotationMetadataBuilder> annotations = helper.toAnnotationMetadata(JpaJavaType.ID,
                JpaJavaType.GENERATED_VALUE, REVISION_NUMBER);
        idField = helper.getField(ID_FIELD, Modifier.PRIVATE, JavaType.LONG_OBJECT, annotations,
                GET_FIELD_EXISTS_ACTION.RETURN_EXISTING_IF_ANNOTATION_MATCH);
    }
    return idField;
}

From source file:com.industrieit.ohr.OHRJavassister.java

private static void setBaseMixinsPre(CtClass cc, boolean includeChecks)
        throws CannotCompileException, IOException, NotFoundException {
    //add fields//from w  ww .  j  a va  2s .c  o  m

    //add basePtr
    //CtField cf = new CtField(CtClass.longType, "crapField", cc);
    //cf.setModifiers(Modifier.PRIVATE | Modifier.VOLATILE);
    //cc.addField(cf);

    //add basePtr
    CtField f = new CtField(CtClass.longType, "basePtr", cc);
    f.setModifiers(Modifier.PRIVATE | Modifier.VOLATILE);
    cc.addField(f);

    //add instmarker
    CtField fm = new CtField(CtClass.intType, "instmarker", cc);
    fm.setModifiers(Modifier.PRIVATE | Modifier.VOLATILE);
    cc.addField(fm);

    CtClass cu = getDefault().get("sun.misc.Unsafe");
    CtField f2 = new CtField(cu, "u", cc);
    f2.setModifiers(Modifier.STATIC | Modifier.PRIVATE);
    cc.addField(f2);

    //add check method
    String checkmeth = "public void doOHRCheck() { if (u.getInt(basePtr+4)!=instmarker) throw new com.industrieit.ohr.StaleHandleException(\"bad instmarker\"); }";
    //PL.pl(checkmeth);
    CtMethod cm = CtNewMethod.make(checkmeth, cc);
    cc.addMethod(cm);

    String str = IOUtils.toString(OHRJavassister.class.getResourceAsStream("/ohr/base/basemethodspre.txt"));

    String checkplace = "";
    if (includeChecks) {
        checkplace = "doOHRCheck();";
    }
    //place in prechecks if desired
    str = str.replace("<<READCHECK>>", checkplace);
    str = str.replace("<<WRITECHECK>>", checkplace);

    StringTokenizer st = new StringTokenizer(str, "~~~");

    while (st.hasMoreElements()) {
        String meth = st.nextToken();
        //PL.pl("adding method: " + meth);
        CtMethod wmethod = CtNewMethod.make(meth, cc);
        cc.addMethod(wmethod);
    }
}

From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java

protected FieldMetadataBuilder getGvNIXPatternField() {
    return new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL,
            new JavaSymbolName("PATTERN_PARAM_NAME"), JavaType.STRING, "\"" + GVNIXPATTERN + "\"");
}

From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java

protected FieldMetadata getDefinedPatternField() {
    String definedPatternIds = "";
    for (String definedPattern : patterns) {
        if (definedPatternIds.length() > 0) {
            definedPatternIds = definedPatternIds.concat(", ");
        }/*from w w  w  .j a v  a 2  s  .c o m*/
        definedPatternIds = definedPatternIds.concat("\"").concat(definedPattern.split("=")[0]).concat("\"");
    }

    FieldMetadataBuilder fmb = null;

    JavaSymbolName fieldName = new JavaSymbolName("definedPatterns");
    JavaType stringArray = new JavaType(JavaType.STRING.getFullyQualifiedTypeName(), 1, DataType.TYPE, null,
            null);

    FieldMetadata field = fieldExists(fieldName, stringArray);
    if (field != null) {
        String initializer = field.getFieldInitializer();
        initializer = initializer.replace("{", "").replace("}", "").replace(" ", "").replace("\"", "");
        for (String pattern : initializer.split(",")) {
            if (!definedPatternIds.contains(pattern)) {
                if (definedPatternIds.length() > 0) {
                    definedPatternIds = definedPatternIds.concat(", ");
                }
                definedPatternIds = definedPatternIds.concat("\"").concat(pattern).concat("\"");
            }
        }
        fmb = new FieldMetadataBuilder(field);
        fmb.setFieldInitializer("{ ".concat(definedPatternIds).concat(" }"));
    }

    if (fmb == null) {
        fmb = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, fieldName,
                stringArray, "{ ".concat(definedPatternIds).concat(" }"));
    }

    field = fmb.build();
    controllerFields.add(field);
    return field;
}

From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadata.java

protected void addStaticFields() {
    FieldMetadataBuilder field = new FieldMetadataBuilder(getId(),
            Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL, new JavaSymbolName("INDEX_PARAM_NAME"),
            JavaType.STRING, "\"index\"");
    builder.addField(field);/*from w  w  w .j a v  a  2  s. com*/

    field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL,
            new JavaSymbolName("FORM_PARAM_NAME"), JavaType.STRING, "\"gvnixform\"");
    builder.addField(field);

    field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL,
            new JavaSymbolName("REFERER_PARAM_NAME"), JavaType.STRING, "\"Referer\"");
    builder.addField(field);
}

From source file:org.gvnix.occ.roo.addon.addon.OCCChecksumMetadata.java

/**
 * Locates the checksum field.//from  w ww  .  ja  v  a 2s  .  c  o m
 * 
 * @return the checksum (may return null)
 */
public FieldMetadata getChecksumField() {

    // Try to locate an existing field with @javax.persistence.Version
    List<FieldMetadata> found = MemberFindingUtils.getFieldsWithAnnotation(governorTypeDetails,
            new JavaType("javax.persistence.Version"));
    if (found.size() > 0) {
        Validate.isTrue(found.size() == 1,
                "More than 1 field was annotated with @javax.persistence.Version in '"
                        + governorTypeDetails.getName().getFullyQualifiedTypeName() + "'");
        FieldMetadata field = found.get(0);

        Validate.isTrue(field.getFieldType().equals(new JavaType(String.class.getName())),
                "Field '" + field.getFieldName().getSymbolName() + "' must be java.lang.String");
        Validate.isTrue(
                MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                        new JavaType("javax.persistence.Transient")) != null,
                "Field '" + field.getFieldName().getSymbolName() + "' must have @Transient annotation");

        if (!field.getFieldName().getSymbolName().equals(fieldName)) {
            LOGGER.warning(governorTypeDetails.getName().getFullyQualifiedTypeName()
                    + ": The @Version field name (" + field.getFieldName().getSymbolName()
                    + ") does not match with @GvNIXEntityOCCChecksum.fieldName (" + fieldName + ")");
        }

        return field;
    }

    // Ensure there isn't already a field called like fieldName; if so,
    // compute a
    // unique name (it's not really a fatal situation at the end of the day)
    StringBuilder fieldNameBuilder = new StringBuilder();
    JavaSymbolName checksumField = null;
    // Compute the required field name
    while (true) {
        checksumField = new JavaSymbolName(fieldNameBuilder.toString().concat(this.fieldName));
        if (MemberFindingUtils.getField(governorTypeDetails, checksumField) == null) {
            // Found a usable field name
            break;
        }

        fieldNameBuilder.append('_');
    }

    // We're creating one
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    AnnotationMetadataBuilder idAnnotation = new AnnotationMetadataBuilder(
            new JavaType("javax.persistence.Version"), new ArrayList<AnnotationAttributeValue<?>>());
    annotations.add(idAnnotation);

    idAnnotation = new AnnotationMetadataBuilder(new JavaType("javax.persistence.Transient"),
            new ArrayList<AnnotationAttributeValue<?>>());
    annotations.add(idAnnotation);

    FieldMetadata field = new FieldMetadataBuilder(getId(), Modifier.PRIVATE, annotations, checksumField,
            JavaType.STRING).build();

    return field;
}