Example usage for java.lang.reflect Field get

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

Introduction

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

Prototype

@CallerSensitive
@ForceInline 
public Object get(Object obj) throws IllegalArgumentException, IllegalAccessException 

Source Link

Document

Returns the value of the field represented by this Field , on the specified object.

Usage

From source file:com.alibaba.druid.pool.bonecp.TestLRU.java

public static MockConnection unwrap(Connection conn) throws Exception {
    if (conn instanceof ConnectionHandle) {
        ConnectionHandle handle = (ConnectionHandle) conn;
        return (MockConnection) handle.getInternalConnection();
    }//from w  w  w.  j a v  a  2 s  .  c o  m
    if (conn instanceof NewProxyConnection) {
        NewProxyConnection handle = (NewProxyConnection) conn;

        Field field = NewProxyConnection.class.getDeclaredField("inner");
        field.setAccessible(true);
        return (MockConnection) field.get(handle);
    }

    return conn.unwrap(MockConnection.class);
}

From source file:Main.java

@SuppressLint("UseSparseArrays")
public static ArrayList<String> extractor(Notification notification) {
    ArrayList<String> notifText = new ArrayList<String>();
    RemoteViews views = notification.contentView;
    @SuppressWarnings("rawtypes")
    Class secretClass = views.getClass();

    try {/*w  w  w .j a v  a2 s  .c  om*/

        Field outerFields[] = secretClass.getDeclaredFields();
        for (int i = 0; i < outerFields.length; i++) {

            if (!outerFields[i].getName().equals("mActions"))
                continue;

            outerFields[i].setAccessible(true);

            @SuppressWarnings("unchecked")
            ArrayList<Object> actions = (ArrayList<Object>) outerFields[i].get(views);
            for (Object action : actions) {

                Field innerFields[] = action.getClass().getDeclaredFields();

                Object value = null;
                Integer type = null;
                @SuppressWarnings("unused")
                Integer viewId = null;
                for (Field field : innerFields) {

                    field.setAccessible(true);
                    if (field.getName().equals("value")) {
                        value = field.get(action);
                    } else if (field.getName().equals("type")) {
                        type = field.getInt(action);
                    } else if (field.getName().equals("viewId")) {
                        viewId = field.getInt(action);
                    }
                }

                if (type != null && (type == 9 || type == 10) && value != null) {
                    // System.out.println("Type: " + Integer.toString(type)
                    // + " Value: " + value.toString());
                    if (!notifText.contains(value.toString()))
                        notifText.add(value.toString());
                }

            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return notifText;
}

From source file:com.seajas.search.utilities.spring.security.model.ExtendedCrowdUserDetails.java

/**
 * Illegally extract the required SOAPPrincipal.
 *
 * @param details//from  www . j a v  a2 s  .c  o  m
 * @return SOAPPrincipal
 */
private static SOAPPrincipal extractPrincipal(final CrowdUserDetails details) {
    UserWithAttributes attributes = details.getRemotePrincipal();

    try {
        Field principalField = attributes.getClass().getDeclaredField("principal");

        principalField.setAccessible(true);

        return (SOAPPrincipal) principalField.get(attributes);
    } catch (NoSuchFieldException e) {
        throw new IllegalArgumentException("Didn't find user details which holds a SOAPPrincipal", e);
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException("Didn't find user details which holds a SOAPPrincipal", e);
    }
}

From source file:api_proto3.TestElf.java

@SuppressWarnings("unchecked")
public static HashMap<Object, HikariPool> getMultiPool(HikariDataSource ds) {
    try {//from  ww w. j a  v  a  2s . c  om
        Field field = ds.getClass().getDeclaredField("multiPool");
        field.setAccessible(true);
        return (HashMap<Object, HikariPool>) field.get(ds);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static int getStatusBarH(Context context) {
    Class<?> c;/*from w  ww .j  a v a 2 s.com*/
    Object obj;
    Field field;
    int statusBarHeight = 0;
    try {
        c = Class.forName("com.android.internal.R$dimen");
        obj = c.newInstance();
        field = c.getField("status_bar_height");
        int x = Integer.parseInt(field.get(obj).toString());
        statusBarHeight = context.getResources().getDimensionPixelSize(x);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    return statusBarHeight;
}

From source file:com.antsdb.saltedfish.util.CursorUtil.java

public static void toRecord(Heap heap, CursorMeta meta, long pRecord, Object obj) throws Exception {
    if (obj instanceof Record) {
        Record rec = (Record) obj;//from   w w  w. j a  v  a  2 s .c o  m
        byte[] key = rec.getKey();
        Record.setKey(heap, pRecord, key);
        for (int field = 0; field < meta.getColumns().size(); field++) {
            Object value = rec.get(field);
            long pValue = FishObject.allocSet(heap, value);
            Record.set(pRecord, field, pValue);
        }
    } else {
        int field = 0;
        for (FieldMeta i : meta.getColumns()) {
            Field f;
            f = obj.getClass().getField(i.getName());
            Object value = f.get(obj);
            long pValue = FishObject.allocSet(heap, value);
            Record.set(pRecord, field, pValue);
            field++;
        }
    }
}

From source file:jfix.util.Reflections.java

/**
 * Returns true if given possible referrer is referencing given reference
 * object in one or more of the given referring fields.
 *///from   ww w  . jav  a  2 s.c o  m
public static boolean isReferrer(Object possibleReferrer, Set<Field> referringFields, Object reference) {
    try {
        for (Field field : referringFields) {
            Object fieldValue = field.get(possibleReferrer);
            if (fieldValue != null && (fieldValue == reference
                    || (field.getType().isArray() && ArrayUtils.contains((Object[]) fieldValue, reference)))) {
                return true;
            }
        }
        return false;
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:Main.java

public static int getStatusBarHeight(Context context) {
    Class<?> c = null;//from w w w. j  ava2  s .co m
    Object obj = null;
    Field field = null;

    int x = 0, statusBarHeight = 0;

    try {
        c = Class.forName("com.android.internal.R$dimen");
        obj = c.newInstance();
        field = c.getField("status_bar_height");
        x = Integer.parseInt(field.get(obj).toString());
        statusBarHeight = context.getResources().getDimensionPixelSize(x);
    } catch (Exception e1) {
        e1.printStackTrace();
    }

    return statusBarHeight;
}

From source file:gov.nih.nci.cabig.caaers.web.search.CommandToSQL.java

public static String invokeField(Object query, String fieldName) throws Exception {
    Field field = query.getClass().getField(fieldName);
    Object aliasValue = field.get(query);
    return aliasValue.toString();
}

From source file:com.infinira.aerospike.dataaccess.util.Utils.java

@SuppressWarnings("unchecked")
public static <V> V get(Object object, String fieldName) {
    Assert.notNull(object, "Object cannot be null.");
    Assert.notNull(fieldName, "Fieldname cannot be null.");
    Class<?> clazz = object.getClass();
    while (clazz != null) {
        try {//from  ww  w  .  java2  s. com
            Field field = clazz.getDeclaredField(fieldName);
            field.setAccessible(true);
            return (V) field.get(object);
        } catch (NoSuchFieldException e) {
            clazz = clazz.getSuperclass();
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    return null;
}