Example usage for java.lang.reflect Modifier isStatic

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

Introduction

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

Prototype

public static boolean isStatic(int mod) 

Source Link

Document

Return true if the integer argument includes the static modifier, false otherwise.

Usage

From source file:com.siberhus.ngai.core.CrudHelper.java

/**
 * //  w  w w . ja  v a 2s  .  co m
 * @param entityClass
 * @return
 */
private synchronized final static EntityInfo getEntityInfo(Class<?> entityClass) {

    EntityInfo entityInfo = ENTITY_INFO_CACHE.get(entityClass);
    if (entityInfo != null) {
        return entityInfo;
    }
    entityInfo = new EntityInfo();
    Entity entityAnnot = (Entity) entityClass.getAnnotation(Entity.class);
    if (!"".equals(entityAnnot.name())) {
        entityInfo.setEntityName(entityAnnot.name());
    } else {
        entityInfo.setEntityName(entityClass.getSimpleName());
    }
    Collection<Field> entityFields = ReflectUtil.getFields(entityClass);
    for (Field field : entityFields) {
        if (Modifier.isStatic(field.getModifiers())) {
            continue;
        }
        if (field.getName().equals("id")) {
            continue;
        }
        if (!field.isAccessible()) {
            field.setAccessible(true);
        }
        entityInfo.getFieldSet().add(field);
    }
    ENTITY_INFO_CACHE.put(entityClass, entityInfo);
    return entityInfo;
}

From source file:com.kixeye.chassis.bootstrap.AppInitMethod.java

private void validate() {
    if (!Modifier.isStatic(method.getModifiers())) {
        throw new BootstrapException("@Init annotated methods must be static parameters.");
    }//w w  w  .j  ava 2s  .c  o  m
    if (method.getParameterTypes().length < 1 || method.getParameterTypes().length > 2) {
        throw new BootstrapException(
                "@Init annotated methods must have a signature like: void static method(org.apache.commons.configuration.Configuration) or void static method(org.apache.commons.configuration.Configuration, com.kixeye.chassis.bootstrap.configuration.ConfigurationProvider).");
    }
    if (!Configuration.class.isAssignableFrom(method.getParameterTypes()[0])) {
        throw new BootstrapException(
                "@Init annotated methods must have a signature like: void static method(org.apache.commons.configuration.Configuration) or void static method(org.apache.commons.configuration.Configuration, com.kixeye.chassis.bootstrap.configuration.ConfigurationProvider).");
    }
    if (method.getParameterTypes().length == 2
            && !ConfigurationProvider.class.isAssignableFrom(method.getParameterTypes()[1])) {
        throw new BootstrapException(
                "@Init annotated methods must have a signature like: void static method(org.apache.commons.configuration.Configuration) or void static method(org.apache.commons.configuration.Configuration, com.kixeye.chassis.bootstrap.configuration.ConfigurationProvider).");
    }
}

From source file:springobjectmapper.ReflectionHelper.java

private static boolean isEntityField(Field field) {
    return !field.isSynthetic() && !Modifier.isStatic(field.getModifiers())
            && !Modifier.isTransient(field.getModifiers());
}

From source file:com.lexicalscope.fluentreflection.FluentFieldImpl.java

@Override
public boolean isStatic() {
    return Modifier.isStatic(field.getModifiers());
}

From source file:com.baasbox.configuration.PropertiesConfigurationHelper.java

/***
 *
 * Returns a json representation of the Enumerator
 * The Enumerator must implements the IProperties interface
 * @param en    the Enumerator to serialize. It must implements the IProperties interface
 * @return       the representation of the Enumerator 
 *//*from  w ww.ja  va  2 s.c  om*/
@SuppressWarnings("unchecked")
public static String dumpConfigurationAsJson(String section) {
    Class en = CONFIGURATION_SECTIONS.get(section);
    try {
        JsonFactory jfactory = new JsonFactory();
        StringWriter sw = new StringWriter();
        String enumDescription = "";
        JsonGenerator gen = jfactory.createJsonGenerator(sw);

        Method getEnumDescription = en.getMethod("getEnumDescription");
        if (getEnumDescription != null && getEnumDescription.getReturnType() == String.class
                && Modifier.isStatic(getEnumDescription.getModifiers()))
            enumDescription = (String) getEnumDescription.invoke(null);
        gen.writeStartObject(); //{
        gen.writeStringField("section", section); //    "configuration":"EnumName"
        gen.writeStringField("description", enumDescription); //   ,"description": "EnumDescription"
        gen.writeFieldName("sub sections"); //  ,"sections":
        gen.writeStartObject(); //      {
        String lastSection = "";
        EnumSet values = EnumSet.allOf(en);
        for (Object v : values) {
            String key = (String) (en.getMethod("getKey")).invoke(v);
            boolean isVisible = (Boolean) (en.getMethod("isVisible")).invoke(v);
            String valueAsString;
            if (isVisible)
                valueAsString = (String) (en.getMethod("getValueAsString")).invoke(v);
            else
                valueAsString = "--HIDDEN--";
            boolean isEditable = (Boolean) (en.getMethod("isEditable")).invoke(v);
            String valueDescription = (String) (en.getMethod("getValueDescription")).invoke(v);
            Class type = (Class) en.getMethod("getType").invoke(v);
            String subsection = key.substring(0, key.indexOf('.'));
            if (!lastSection.equals(subsection)) {
                if (gen.getOutputContext().inArray())
                    gen.writeEndArray();
                gen.writeFieldName(subsection); //         "sectionName":
                gen.writeStartArray(); //            [
                lastSection = subsection;
            }
            boolean isOverridden = (Boolean) (en.getMethod("isOverridden")).invoke(v);
            gen.writeStartObject(); //               {
            gen.writeStringField(key, valueAsString); //                     "key": "value"   
            gen.writeStringField("description", valueDescription); //                  ,"description":"description"
            gen.writeStringField("type", type.getSimpleName()); //                  ,"type":"type"
            gen.writeBooleanField("editable", isEditable); //                  ,"editable":"true|false"
            gen.writeBooleanField("visible", isVisible); //                  ,"visible":"true|false"
            gen.writeBooleanField("overridden", isOverridden); //                  ,"overridden":"true|false"
            gen.writeEndObject(); //               }
        }
        if (gen.getOutputContext().inArray())
            gen.writeEndArray(); //            ]
        gen.writeEndObject(); //      }
        gen.writeEndObject(); //}
        gen.close();
        return sw.toString();
    } catch (Exception e) {
        BaasBoxLogger.error("Cannot generate a json for " + en.getSimpleName()
                + " Enum. Is it an Enum that implements the IProperties interface?", e);
    }
    return "{}";
}

From source file:com.greenline.hrs.admin.web.war.conf.InjectBeanPostProcessor.java

private void injectPropertyToBean(final Object bean) {
    ReflectionUtils.doWithFields(bean.getClass(), new ReflectionUtils.FieldCallback() {

        @Override/*from w  w w .j a v a  2  s  .c o  m*/
        public void doWith(Field field) throws IllegalAccessException {
            InjectingProperty annotation = field.getAnnotation(InjectingProperty.class);
            if (annotation != null) {
                Object strValue = propertyConfigurer.getProperty(annotation.value());
                if (null != strValue) {
                    Object value = typeConverter.convertIfNecessary(strValue, field.getType());
                    ReflectionUtils.makeAccessible(field);
                    if (Modifier.isStatic(field.getModifiers())) {
                        field.set(null, value);
                    } else {
                        field.set(bean, value);
                    }
                }
            }
        }
    });
}

From source file:eu.stratosphere.api.common.operators.util.UserCodeObjectWrapper.java

public UserCodeObjectWrapper(T userCodeObject) {
    Preconditions.checkArgument(userCodeObject instanceof Serializable,
            "User code object is not serializable: " + userCodeObject.getClass());
    this.userCodeObject = userCodeObject;
    // Remove unserializable objects from the user code object as well as from outer objects
    Object current = userCodeObject;
    try {/*  www.j av a  2s. co m*/
        while (null != current) {
            Object newCurrent = null;
            for (Field f : current.getClass().getDeclaredFields()) {
                f.setAccessible(true);

                if (f.getName().contains("$outer")) {
                    newCurrent = f.get(current);

                }

                if (!Modifier.isStatic(f.getModifiers()) && f.get(current) != null
                        && !(f.get(current) instanceof Serializable)) {
                    throw new RuntimeException("User code object " + userCodeObject
                            + " contains non-serializable field " + f.getName() + " = " + f.get(current));
                }
            }
            current = newCurrent;
        }
    } catch (IllegalAccessException e) {
        // this cannot occur since we call setAccessible(true)
        e.printStackTrace();
    }

}

From source file:org.ext4spring.parameter.DefaultParameterBeanService.java

private List<Field> getSupportedFields(Class<?> clazz) {
    List<Field> supportedFields = new ArrayList<Field>();
    for (Field field : clazz.getDeclaredFields()) {
        int modifiers = field.getModifiers();
        if (!Modifier.isStatic(modifiers)) { //!Modifier.isFinal(modifiers) && 
            supportedFields.add(field);//from w ww  .  j a  v  a  2 s .co m
        }
    }
    return supportedFields;
}

From source file:com.agileapes.couteau.context.spring.event.impl.GenericTranslationScheme.java

static boolean isGetter(Method method) {
    return Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())
            && method.getParameterTypes().length == 0 && !method.getReturnType().equals(void.class)
            && (method.getName().matches("get[A-Z].*")
                    || (method.getName().matches("is[A-Z].*") && method.getReturnType().equals(boolean.class)));
}

From source file:org.opentele.server.core.util.CustomGroovyBeanJSONMarshaller.java

public void marshalObject(Object o, JSON json) throws ConverterException {
    JSONWriter writer = json.getWriter();
    try {/*ww  w.j a v  a  2  s. c o  m*/
        writer.object();
        for (PropertyDescriptor property : BeanUtils.getPropertyDescriptors(o.getClass())) {
            String name = property.getName();
            Method readMethod = property.getReadMethod();
            if (readMethod != null && !(name.equals("metaClass")) && !(name.equals("class"))) {
                Object value = readMethod.invoke(o, (Object[]) null);
                writer.key(name);
                json.convertAnother(value);
            }
        }
        for (Field field : o.getClass().getDeclaredFields()) {
            int modifiers = field.getModifiers();
            if (Modifier.isPublic(modifiers)
                    && !(Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers))) {
                writer.key(field.getName());
                json.convertAnother(field.get(o));
            }
        }
        writer.endObject();
    } catch (ConverterException ce) {
        throw ce;
    } catch (Exception e) {
        throw new ConverterException("Error converting Bean with class " + o.getClass().getName(), e);
    }
}