001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import java.lang.reflect.Field;
018    
019    /**
020     * @author Shuyang Zhou
021     */
022    public class ReferenceEntry {
023    
024            public ReferenceEntry(Field field) {
025                    this(null, field);
026            }
027    
028            public ReferenceEntry(Object object, Field field) {
029                    _object = object;
030                    _field = field;
031    
032                    if (!_field.isAccessible()) {
033                            _field.setAccessible(true);
034                    }
035            }
036    
037            public Field getField() {
038                    return _field;
039            }
040    
041            public Object getObject() {
042                    return _object;
043            }
044    
045            public void setValue(Object value)
046                    throws IllegalAccessException, IllegalArgumentException {
047    
048                    _field.set(_object, value);
049            }
050    
051            @Override
052            public String toString() {
053                    return _object.toString().concat(StringPool.POUND).concat(
054                            _field.toString());
055            }
056    
057            private Field _field;
058            private Object _object;
059    
060    }