Example usage for java.lang.reflect Modifier STATIC

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

Introduction

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

Prototype

int STATIC

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

Click Source Link

Document

The int value representing the static modifier.

Usage

From source file:org.codehaus.groovy.grails.web.binding.DataBindingUtils.java

private static List getBindingIncludeList(final Object object) {
    List includeList = Collections.EMPTY_LIST;
    try {//from   ww  w  .jav a 2 s. c om
        final Class<? extends Object> objectClass = object.getClass();
        if (CLASS_TO_BINDING_INCLUDE_LIST.containsKey(objectClass)) {
            includeList = CLASS_TO_BINDING_INCLUDE_LIST.get(objectClass);
        } else {
            final Field whiteListField = objectClass
                    .getDeclaredField(DefaultASTDatabindingHelper.DEFAULT_DATABINDING_WHITELIST);
            if (whiteListField != null) {
                if ((whiteListField.getModifiers() & Modifier.STATIC) != 0) {
                    final Object whiteListValue = whiteListField.get(objectClass);
                    if (whiteListValue instanceof List) {
                        includeList = (List) whiteListValue;
                    }
                }
            }
            if (!Environment.getCurrent().isReloadEnabled()) {
                CLASS_TO_BINDING_INCLUDE_LIST.put(objectClass, includeList);
            }
        }
    } catch (Exception e) {
    }
    return includeList;
}

From source file:com.comphenix.protocol.reflect.FuzzyReflection.java

/**
 * Retrieve the singleton instance of a class, from a method or field.
 * @return The singleton instance.//from w  ww .  j ava2 s .c  o m
 * @throws IllegalStateException If the class has no singleton.
 */
public Object getSingleton() {
    Method method = null;
    Field field = null;

    try {
        method = getMethod(FuzzyMethodContract.newBuilder().parameterCount(0).returnDerivedOf(source)
                .requireModifier(Modifier.STATIC).build());
    } catch (IllegalArgumentException e) {
        // Try getting the field instead
        // Note that this will throw an exception if not found
        field = getFieldByType("instance", source);
    }

    // Convert into unchecked exceptions
    if (method != null) {
        try {
            method.setAccessible(true);
            return method.invoke(null);
        } catch (Exception e) {
            throw new RuntimeException("Cannot invoke singleton method " + method, e);
        }
    }
    if (field != null) {
        try {
            field.setAccessible(true);
            return field.get(null);
        } catch (Exception e) {
            throw new IllegalArgumentException("Cannot get content of singleton field " + field, e);
        }
    }
    // We should never get to this point
    throw new IllegalStateException("Impossible.");
}

From source file:pl.burningice.plugins.image.ast.AbstractImageContainerTransformation.java

protected FieldNode getHasManyField(ClassNode node) {
    FieldNode hasManyField = node.getDeclaredField("hasMany");

    if (hasManyField != null) {
        return hasManyField;
    }/*from  w w w .  ja  v a 2  s.com*/

    hasManyField = new FieldNode("hasMany", Modifier.PRIVATE | Modifier.STATIC, new ClassNode(Map.class),
            new ClassNode(node.getClass()), new MapExpression());

    node.addField(hasManyField);
    addGetter(hasManyField, node, Modifier.PUBLIC | Modifier.STATIC);
    addSetter(hasManyField, node, Modifier.PUBLIC | Modifier.STATIC);
    return hasManyField;
}

From source file:org.apache.xml.security.utils.XalanXPathAPI.java

private synchronized static void fixupFunctionTable() {
    installed = false;//from  w ww. j  a v a2 s . c o m
    if (log.isDebugEnabled()) {
        log.debug("Registering Here function");
    }
    /**
     * Try to register our here() implementation as internal function.
     */
    try {
        Class<?>[] args = { String.class, Expression.class };
        Method installFunction = FunctionTable.class.getMethod("installFunction", args);
        if ((installFunction.getModifiers() & Modifier.STATIC) != 0) {
            Object[] params = { "here", new FuncHere() };
            installFunction.invoke(null, params);
            installed = true;
        }
    } catch (Exception ex) {
        log.debug("Error installing function using the static installFunction method", ex);
    }
    if (!installed) {
        try {
            funcTable = new FunctionTable();
            Class<?>[] args = { String.class, Class.class };
            Method installFunction = FunctionTable.class.getMethod("installFunction", args);
            Object[] params = { "here", FuncHere.class };
            installFunction.invoke(funcTable, params);
            installed = true;
        } catch (Exception ex) {
            log.debug("Error installing function using the static installFunction method", ex);
        }
    }
    if (log.isDebugEnabled()) {
        if (installed) {
            log.debug("Registered class " + FuncHere.class.getName()
                    + " for XPath function 'here()' function in internal table");
        } else {
            log.debug("Unable to register class " + FuncHere.class.getName()
                    + " for XPath function 'here()' function in internal table");
        }
    }
}

From source file:org.gvnix.addon.jpa.annotations.geo.providers.hibernatespatial.GvNIXEntityMapLayerMetadata.java

/**
 * Gets <code>findAllEntitiesByBoundingBox</code> method. <br>
 * //from w w  w.  java  2 s .c  o m
 * @return
 */
private MethodMetadata getFindAllEntitiesByBoundingBoxMethod(JavaType entity, String plural,
        List<JavaSymbolName> geoFieldNames) {
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();

    // Adding String param
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.STRING));

    // Getting method name
    JavaSymbolName methodName = new JavaSymbolName(String.format("findAll%sByBoundingBox", plural));

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

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

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

    // Create the method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    buildfindAllEntitiesByBoundingBoxMethodBody(entity, plural, bodyBuilder, geoFieldNames);

    // Return type
    JavaType responseEntityJavaType = new JavaType("java.util.List", 0, DataType.TYPE, null,
            Arrays.asList(entity));

    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC,
            methodName, responseEntityJavaType, 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.EntityBatchMetadata.java

/**
 * Gets Inner class to manage elements list for batch operations
 * /*from   ww w . j  ava2 s. co m*/
 * @return
 */
public ClassOrInterfaceTypeDetails getListInnerClass() {
    // Generate inner class name
    JavaType listInnerClassJavaType = new JavaType(destination.getSimpleTypeName().concat("List"), 0,
            DataType.TYPE, null, null);

    // Create class builder
    ClassOrInterfaceTypeDetailsBuilder classBuilder = new ClassOrInterfaceTypeDetailsBuilder(getId(),
            Modifier.STATIC | Modifier.PUBLIC, listInnerClassJavaType, PhysicalTypeCategory.CLASS);

    // Add fields
    FieldMetadata listField = getListInner_field("list", destination).build();
    FieldMetadata selectedField = getListInner_field("selected", new JavaType("Integer")).build();
    classBuilder.addField(listField);
    classBuilder.addField(selectedField);

    // Adds getter/setter for list field
    classBuilder.addMethod(getListInner_getter(listField));
    classBuilder.addMethod(getListInner_setter(listField));

    // Adds getter/setter for selected field
    classBuilder.addMethod(getListInner_getter(selectedField));
    classBuilder.addMethod(getListInner_setter(selectedField));

    // Return generated class
    return classBuilder.build();
}

From source file:org.gvnix.addon.gva.security.providers.safe.SafeSecurityProviderMetadata.java

public SafeSecurityProviderMetadata(String identifier, JavaType aspectName,
        PhysicalTypeMetadata governorPhysicalTypeMetadata) {
    super(identifier, aspectName, governorPhysicalTypeMetadata);

    // Helper itd generation
    this.helper = new ItdBuilderHelper(this, governorPhysicalTypeMetadata,
            builder.getImportRegistrationResolver());

    this.governorsPackage = governorPhysicalTypeMetadata.getType().getPackage();
    // Imports//from   w ww .  ja  v a  2s  .  c om
    helper.getFinalTypeName(
            new JavaType("org.springframework.security.authentication.encoding.PlaintextPasswordEncoder"));

    // Adding Fields
    builder.addField(getField("logger", "Logger.getLogger(SafeProvider.class.getName())",
            new JavaType("org.apache.log4j.Logger"), Modifier.PRIVATE + Modifier.STATIC, null));

    builder.addField(getField("passwordEncoder", "new PlaintextPasswordEncoder()",
            new JavaType("org.springframework.security.authentication.encoding.PasswordEncoder"),
            Modifier.PRIVATE, null));

    builder.addField(getField("saltSource", null,
            new JavaType("org.springframework.security.authentication.dao.SaltSource"), Modifier.PRIVATE,
            null));

    builder.addField(getField("applicationId", null, JAVA_TYPE_STRING, Modifier.PRIVATE, null));

    builder.addField(getField("environment", null, JAVA_TYPE_STRING, Modifier.PRIVATE, null));

    builder.addField(getField("prop", null, new JavaType(JAVA_UTIL_PROPERTIES), Modifier.PUBLIC, null));

    builder.addField(getField("loader", null, new JavaType("java.lang.ClassLoader"), Modifier.PUBLIC, null));

    builder.addField(getField("stream", null, new JavaType("java.io.InputStream"), Modifier.PUBLIC, null));

    builder.addField(getField("mapRoles", "true", JavaType.BOOLEAN_PRIMITIVE, Modifier.PRIVATE, null));

    builder.addField(getField("active", null, JavaType.BOOLEAN_PRIMITIVE, Modifier.PRIVATE, null));

    builder.addField(
            getField("filtrarPorAplicacion", null, JavaType.BOOLEAN_PRIMITIVE, Modifier.PRIVATE, null));

    // Adding Field annotations
    List<AnnotationMetadataBuilder> autenticationAnnotations = new ArrayList<AnnotationMetadataBuilder>();

    // Add @Autowired annotation
    AnnotationMetadataBuilder autowiredAnnotation = new AnnotationMetadataBuilder(
            new JavaType("org.springframework.beans.factory.annotation.Autowired"));
    autenticationAnnotations.add(autowiredAnnotation);

    builder.addField(getField("safeAutenticacionClient", null,
            new JavaType("es.gva.dgm.ayf.war.definitions.v2u00.AutenticacionArangiPortType"), Modifier.PRIVATE,
            autenticationAnnotations));

    builder.addField(getField("safeAutorizacionClient", null,
            new JavaType("es.gva.dgm.ayf.war.definitions.v2u00.AutorizacionPortType"), Modifier.PRIVATE,
            autenticationAnnotations));

    // Creating getters and setters
    builder.addMethod(getGetterMethod("saltSource",
            new JavaType("org.springframework.security.authentication.dao.SaltSource")));
    builder.addMethod(getSetterMethod("saltSource",
            new JavaType("org.springframework.security.authentication.dao.SaltSource")));
    builder.addMethod(getGetterMethod("passwordEncoder",
            new JavaType("org.springframework.security.authentication.encoding.PasswordEncoder")));
    builder.addMethod(getSetterMethod("passwordEncoder",
            new JavaType("org.springframework.security.authentication.encoding.PasswordEncoder")));
    builder.addMethod(getGetterMethod("applicationId", JAVA_TYPE_STRING));
    builder.addMethod(getSetterMethod("applicationId", JAVA_TYPE_STRING));
    builder.addMethod(getGetterMethod("environment", JAVA_TYPE_STRING));
    builder.addMethod(getSetterMethod("environment", JAVA_TYPE_STRING));
    builder.addMethod(getGetterMethod("mapRoles", JavaType.BOOLEAN_PRIMITIVE));
    builder.addMethod(getSetterMethod("mapRoles", JavaType.BOOLEAN_PRIMITIVE));
    builder.addMethod(getGetterMethod("active", JavaType.BOOLEAN_PRIMITIVE));
    builder.addMethod(getSetterMethod("active", JavaType.BOOLEAN_PRIMITIVE));
    builder.addMethod(getGetterMethod("filtrarPorAplicacion", JavaType.BOOLEAN_PRIMITIVE));
    builder.addMethod(getSetterMethod("filtrarPorAplicacion", JavaType.BOOLEAN_PRIMITIVE));

    // Creating methods
    builder.addMethod(getAdditionalAuthenticationChecksMethod());
    builder.addMethod(getRetrieveUserMethod());
    builder.addMethod(getConvertWSInfoToUserMethod());
    builder.addMethod(getConvertWSInfoToUserTodasAplicacionesMethod());
    builder.addMethod(getConvertToApplicationRolMethod());

    // Create a representation of the desired output ITD
    itdTypeDetails = builder.build();
}

From source file:org.springframework.richclient.util.ClassUtils.java

public static Method getStaticMethod(String name, Class locatorClass, Class[] args) {
    try {//from   w  w w . j a v a 2 s . co m
        logger.debug("Attempting to get method '" + name + "' on class " + locatorClass + " with arguments '"
                + StylerUtils.style(args) + "'");
        Method method = locatorClass.getDeclaredMethod(name, args);
        if ((method.getModifiers() & Modifier.STATIC) != 0)
            return method;

        return null;
    } catch (NoSuchMethodException e) {
        return null;
    }
}

From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java

private static boolean isDefault(Method method) {
    // Default methods are public non-abstract instance methods declared in an interface.
    return ((method.getModifiers()
            & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == Modifier.PUBLIC)
            && method.getDeclaringClass().isInterface();
}

From source file:ClassTree.java

/**
 * Returns a description of the fields of a class.
 * @param the class to be described// w ww  .  j a  v  a2 s . c  o m
 * @return a string containing all field types and names
 */
public static String getFieldDescription(Class<?> c) {
    // use reflection to find types and names of fields
    StringBuilder r = new StringBuilder();
    Field[] fields = c.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field f = fields[i];
        if ((f.getModifiers() & Modifier.STATIC) != 0)
            r.append("static ");
        r.append(f.getType().getName());
        r.append(" ");
        r.append(f.getName());
        r.append("\n");
    }
    return r.toString();
}