Example usage for java.lang Class getField

List of usage examples for java.lang Class getField

Introduction

In this page you can find the example usage for java.lang Class getField.

Prototype

@CallerSensitive
public Field getField(String name) throws NoSuchFieldException, SecurityException 

Source Link

Document

Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object.

Usage

From source file:doext.easemob.activity.ChatActivity.java

/**
 * ?gridview?view/*  w w  w  .  j  a va  2  s .com*/
 * 
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, DoResourcesHelper.getIdentifier("expression_gridview", "layout", this),
            null);
    ExpandGridView gv = (ExpandGridView) view
            .findViewById(DoResourcesHelper.getIdentifier("gridview", "id", this));
    List<String> list = new ArrayList<String>();
    if (i == 1) {
        List<String> list1 = reslist.subList(0, 20);
        list.addAll(list1);
    } else if (i == 2) {
        list.addAll(reslist.subList(20, reslist.size()));
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // ????
                // ?????
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // ?
                        // ????SmileUtils
                        Class clz = Class.forName("doext.easemob.util.SmileUtils");
                        Field field = clz.getField(filename);
                        mEditTextContent
                                .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null)));
                    } else { // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// ??
                            if (selectionStart > 0) {
                                String body = mEditTextContent.getText().toString();
                                String tempStr = body.substring(0, selectionStart);
                                int i = tempStr.lastIndexOf("[");// ???
                                if (i != -1) {
                                    CharSequence cs = tempStr.substring(i, selectionStart);
                                    if (SmileUtils.containsKey(cs.toString()))
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {
                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

                    }
                }
            } catch (Exception e) {
            }

        }
    });
    return view;
}

From source file:com.givon.anhao.activity.ChatActivity.java

/**
 * ?gridview?view//from w  w w .  ja  va2 s.  c o m
 * 
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, R.layout.expression_gridview, null);
    ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
    List<String> list = new ArrayList<String>();
    if (i == 1) {
        List<String> list1 = reslist.subList(0, 20);
        list.addAll(list1);
    } else if (i == 2) {
        list.addAll(reslist.subList(20, reslist.size()));
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // ????
                // ?????
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // ?
                        // ????SmileUtils
                        Class clz = Class.forName("com.givon.anhao.utils.SmileUtils");
                        Field field = clz.getField(filename);
                        mEditTextContent
                                .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null)));
                    } else { // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// ??
                            if (selectionStart > 0) {
                                String body = mEditTextContent.getText().toString();
                                String tempStr = body.substring(0, selectionStart);
                                int i = tempStr.lastIndexOf("[");// ???
                                if (i != -1) {
                                    CharSequence cs = tempStr.substring(i, selectionStart);
                                    if (SmileUtils.containsKey(cs.toString()))
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {
                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

                    }
                }
            } catch (Exception e) {
            }

        }
    });
    return view;
}

From source file:com.ccxt.whl.activity.ChatActivity.java

/**
 * ?gridview?view//from w w  w.j a  va 2  s.  co m
 * 
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, R.layout.expression_gridview, null);
    ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
    List<String> list = new ArrayList<String>();
    if (i == 1) {
        List<String> list1 = reslist.subList(0, 20);
        list.addAll(list1);
    } else if (i == 2) {
        list.addAll(reslist.subList(20, reslist.size()));
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // ????
                // ?????
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // ?
                        // ????SmileUtils
                        Class clz = Class.forName("com.ccxt.whl.utils.SmileUtils");
                        Field field = clz.getField(filename);
                        mEditTextContent
                                .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null)));
                    } else { // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// ??
                            if (selectionStart > 0) {
                                String body = mEditTextContent.getText().toString();
                                String tempStr = body.substring(0, selectionStart);
                                int i = tempStr.lastIndexOf("[");// ???
                                if (i != -1) {
                                    CharSequence cs = tempStr.substring(i, selectionStart);
                                    if (SmileUtils.containsKey(cs.toString()))
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {
                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

                    }
                }
            } catch (Exception e) {
            }

        }
    });
    return view;
}

From source file:org.openx.data.jsonserde.json.JSONObject.java

/**
 * Construct a JSONObject from an Object, using reflection to find the
 * public members. The resulting JSONObject's keys will be the strings
 * from the names array, and the values will be the field values associated
 * with those keys in the object. If a key is not found or not visible,
 * then it will not be copied into the new JSONObject.
 * @param object An object that has fields that should be used to make a
 * JSONObject.//w ww  .  j  a va 2  s  .  co m
 * @param names An array of strings, the names of the fields to be obtained
 * from the object.
 */
public JSONObject(Object object, String names[]) {
    this();
    Class c = object.getClass();
    for (int i = 0; i < names.length; i += 1) {
        String name = names[i];
        try {
            putOpt(name.toLowerCase(), c.getField(name).get(object));
        } catch (Exception ignore) {
        }
    }
}

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java

private Map<Short, ThriftFieldMetadata> getTBaseFields(Class<? extends TBase> tbase) throws TException {
    try {//ww w  . j a v a2s.co m
        // First read if the ThriftFieldMetadata was not already readed
        Map<Class<?>, Map<Short, ThriftFieldMetadata>> thriftFields = threadSafeTFields.get();

        if (thriftFields == null) {
            thriftFields = new HashMap<>();
        }

        Map<Short, ThriftFieldMetadata> thriftStructFields = thriftFields.get(tbase);

        // Finded return it
        if (thriftStructFields != null) {
            return thriftStructFields;
        }

        // Load it
        thriftStructFields = new HashMap<>();
        Field metafaField = tbase.getField("metaDataMap");
        Map<?, FieldMetaData> fields = (Map<?, org.apache.thrift.meta_data.FieldMetaData>) metafaField
                .get(tbase);
        // list all fields
        for (Map.Entry<?, FieldMetaData> entry : fields.entrySet()) {
            TFieldIdEnum field = (TFieldIdEnum) entry.getKey();

            ThriftFieldMetadata tfieldMetadata = new ThriftFieldMetadata();

            // An enum type is deserialized as an I32
            byte type = entry.getValue().valueMetaData.type;
            if (TType.ENUM == type) {
                type = TType.I32;
            }

            TBSONSecuredWrapper.ThriftSecuredField securedField = tbsonSecuredWrapper.getField(tbase,
                    field.getThriftFieldId());

            tfieldMetadata.tfield = new TField(field.getFieldName(), type, field.getThriftFieldId());
            tfieldMetadata.fieldMetaData = entry.getValue();
            tfieldMetadata.tbaseClass = tbase;
            tfieldMetadata.securedFieldMetaData = securedField;
            thriftStructFields.put(field.getThriftFieldId(), tfieldMetadata);
        }

        //store it
        thriftFields.put(tbase, thriftStructFields);
        threadSafeTFields.set(thriftFields);
        return thriftStructFields;
    } catch (Exception exp) {
        throw new TException(exp);
    }
}

From source file:org.apache.unomi.persistence.elasticsearch.ElasticSearchPersistenceServiceImpl.java

private <T extends Item> String getItemType(Class<T> clazz) {
    try {/*from ww w .  j  a  va 2  s.  c o  m*/
        return (String) clazz.getField("ITEM_TYPE").get(null);
    } catch (NoSuchFieldException e) {
        logger.error("Class " + clazz.getName() + " doesn't define a publicly accessible ITEM_TYPE field", e);
    } catch (IllegalAccessException e) {
        logger.error("Error loading itemType=" + clazz.getName(), e);
    }
    return null;
}

From source file:com.interestfriend.activity.ChatActivity.java

/**
 * gridviewview/*  w w  w .  ja va  2s .  c om*/
 * 
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, R.layout.expression_gridview, null);
    ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
    List<String> list = new ArrayList<String>();
    List<String> list1 = null;
    if (i == 1) {
        list1 = reslist.subList(0, 20);
        list.addAll(list1);
    } else if (i == 2) {
        list1 = reslist.subList(21, 41);
        list.addAll(list1);
    } else if (i == 3) {
        list1 = reslist.subList(41, 61);
        list.addAll(list1);
    } else if (i == 4) {
        list1 = reslist.subList(61, 81);
        list.addAll(list1);
    } else if (i == 5) {
        list1 = reslist.subList(81, 101);
        list.addAll(list1);
    } else if (i == 6) {
        list1 = reslist.subList(101, 121);
        list.addAll(list1);
    } else if (i == 7) {
        list1 = reslist.subList(121, 141);
        list.addAll(list1);
    } else if (i == 8) {
        list1 = reslist.subList(141, 160);
        list.addAll(list1);
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // 
                // 
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // 
                        // SmileUtils
                        Class clz = Class.forName("com.interestfriend.utils.SmileUtils");
                        Field field = clz.getField(filename);
                        mEditTextContent
                                .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null)));
                    } else { // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// 
                            if (selectionStart > 0) {
                                String body = mEditTextContent.getText().toString();
                                String tempStr = body.substring(0, selectionStart);
                                int i = tempStr.lastIndexOf("[");// 
                                if (i != -1) {
                                    CharSequence cs = tempStr.substring(i, selectionStart);
                                    if (SmileUtils.containsKey(cs.toString()))
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {
                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

                    }
                }
            } catch (Exception e) {
            }

        }
    });
    return view;
}

From source file:it.cnr.icar.eric.common.BindingUtility.java

public String getObjectTypeId(String rimClassName) throws JAXRException {
    String objectTypeId = null;//from   ww  w.  j  a v  a 2  s. c  o  m

    try {
        Class<? extends BindingUtility> clazz = this.getClass();
        Field field = clazz.getField("CANONICAL_OBJECT_TYPE_ID_" + rimClassName);
        Object obj = field.get(this);
        objectTypeId = (String) obj;
    } catch (NoSuchFieldException e) {
        throw new JAXRException(e);
    } catch (SecurityException e) {
        throw new JAXRException(e);
    } catch (IllegalAccessException e) {
        throw new JAXRException(e);
    }

    return objectTypeId;
}

From source file:com.ieeton.user.activity.ChatActivity.java

/**
 * ?gridview?view/*  w w  w . j  a  v  a  2  s  .  co  m*/
 * 
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, R.layout.expression_gridview, null);
    ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
    List<String> list = new ArrayList<String>();
    if (i == 1) {
        List<String> list1 = reslist.subList(0, 20);
        list.addAll(list1);
    } else if (i == 2) {
        list.addAll(reslist.subList(20, reslist.size()));
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // ????
                // ?????
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // ?
                        // ????SmileUtils
                        Class clz = Class.forName("com.ieeton.user.utils.SmileUtils");
                        Field field = clz.getField(filename);
                        mEditTextContent
                                .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null)));
                    } else { // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// ??
                            if (selectionStart > 0) {
                                String body = mEditTextContent.getText().toString();
                                String tempStr = body.substring(0, selectionStart);
                                int i = tempStr.lastIndexOf("[");// ???
                                if (i != -1) {
                                    CharSequence cs = tempStr.substring(i, selectionStart);
                                    if (SmileUtils.containsKey(cs.toString()))
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {
                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

                    }
                }
            } catch (Exception e) {
            }

        }
    });
    return view;
}

From source file:com.erhuoapp.erhuo.activity.ChatActivity.java

/**
 * ?gridview?view/*from  w ww  . j  av a 2s . com*/
 * 
 * @param i
 * @return
 */
private View getGridChildView(int i) {
    View view = View.inflate(this, R.layout.expression_gridview, null);
    ExpandGridView gv = (ExpandGridView) view.findViewById(R.id.gridview);
    List<String> list = new ArrayList<String>();
    if (i == 1) {
        List<String> list1 = reslist.subList(0, 20);
        list.addAll(list1);
    } else if (i == 2) {
        list.addAll(reslist.subList(20, reslist.size()));
    }
    list.add("delete_expression");
    final ExpressionAdapter expressionAdapter = new ExpressionAdapter(this, 1, list);
    gv.setAdapter(expressionAdapter);
    gv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String filename = expressionAdapter.getItem(position);
            try {
                // ????
                // ?????
                if (buttonSetModeKeyboard.getVisibility() != View.VISIBLE) {

                    if (filename != "delete_expression") { // ?
                        // ????SmileUtils
                        Class clz = Class.forName("com.erhuoapp.erhuo.im.utils.SmileUtils");
                        Field field = clz.getField(filename);
                        mEditTextContent
                                .append(SmileUtils.getSmiledText(ChatActivity.this, (String) field.get(null)));
                    } else { // 
                        if (!TextUtils.isEmpty(mEditTextContent.getText())) {

                            int selectionStart = mEditTextContent.getSelectionStart();// ??
                            if (selectionStart > 0) {
                                String body = mEditTextContent.getText().toString();
                                String tempStr = body.substring(0, selectionStart);
                                int i = tempStr.lastIndexOf("[");// ???
                                if (i != -1) {
                                    CharSequence cs = tempStr.substring(i, selectionStart);
                                    if (SmileUtils.containsKey(cs.toString()))
                                        mEditTextContent.getEditableText().delete(i, selectionStart);
                                    else
                                        mEditTextContent.getEditableText().delete(selectionStart - 1,
                                                selectionStart);
                                } else {
                                    mEditTextContent.getEditableText().delete(selectionStart - 1,
                                            selectionStart);
                                }
                            }
                        }

                    }
                }
            } catch (Exception e) {
            }

        }
    });
    return view;
}