Example usage for java.lang.reflect Field getModifiers

List of usage examples for java.lang.reflect Field getModifiers

Introduction

In this page you can find the example usage for java.lang.reflect Field getModifiers.

Prototype

public int getModifiers() 

Source Link

Document

Returns the Java language modifiers for the field represented by this Field object, as an integer.

Usage

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Return the value of the given field in the given object.
 *///  w w  w  . jav  a 2 s .  c  om
public static double getDouble(Object target, Field field) {
    if (target == null || field == null)
        return 0D;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getDouble(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("get-field", target, field));
    }
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Return the value of the given field in the given object.
 *//*from   w w  w  .  java2s .  c om*/
public static float getFloat(Object target, Field field) {
    if (target == null || field == null)
        return 0F;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getFloat(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("get-field", target, field));
    }
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Return the value of the given field in the given object.
 *//*from www .j av a  2  s. c  o m*/
public static long getLong(Object target, Field field) {
    if (target == null || field == null)
        return 0L;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getLong(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("get-field", target, field));
    }
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Return the value of the given field in the given object.
 *//* w  w  w .j  a  v a 2  s.  c o  m*/
public static Object get(Object target, Field field) {
    if (target == null || field == null)
        return null;
    makeAccessible(field, field.getModifiers());
    try {
        return field.get(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("get-field", target, field));
    }
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Return the value of the given field in the given object.
 *///from  w  w w .j a v a2 s  .  c o m
public static boolean getBoolean(Object target, Field field) {
    if (target == null || field == null)
        return false;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getBoolean(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("get-field", target, field));
    }
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Return the value of the given field in the given object.
 *///from w w w  .j a  va 2  s.co m
public static byte getByte(Object target, Field field) {
    if (target == null || field == null)
        return (byte) 0;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getByte(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("get-field", target, field));
    }
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Return the value of the given field in the given object.
 *//* w ww .j av a  2s .com*/
public static char getChar(Object target, Field field) {
    if (target == null || field == null)
        return (char) 0;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getChar(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("get-field", target, field));
    }
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Return the value of the given field in the given object.
 *///from   w ww  . ja v  a  2s.c  o m
public static short getShort(Object target, Field field) {
    if (target == null || field == null)
        return (short) 0;
    makeAccessible(field, field.getModifiers());
    try {
        return field.getShort(target);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("get-field", target, field));
    }
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Set the value of the given field in the given object.
 *///www .  j  a v  a2  s . c om
public static void set(Object target, Field field, int value) {
    if (target == null || field == null)
        return;
    makeAccessible(field, field.getModifiers());
    try {
        field.setInt(target, value);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("set-field", new Object[] { target, field, value, "int" }));
    }
}

From source file:org.apache.openjpa.enhance.Reflection.java

/**
 * Set the value of the given field in the given object.
 *///w  w w.ja  v a  2s.  c  o  m
public static void set(Object target, Field field, byte value) {
    if (target == null || field == null)
        return;
    makeAccessible(field, field.getModifiers());
    try {
        field.setByte(target, value);
    } catch (Throwable t) {
        throw wrapReflectionException(t, _loc.get("set-field", new Object[] { target, field, value, "byte" }));
    }
}