001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }