View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.util.dom.reflect;
18  
19  import java.lang.reflect.Field;
20  import java.lang.reflect.Method;
21  
22  /**
23   * represents a property.
24   *
25   * In code, a property is declared using a public field or a setter/getter pair.
26   * Properties declared using fields are writable, properties declared using
27   * accessors are writable if and only if setters are declared.
28   *
29   * @svnLink $Revision: 3883 $;$Date: 2009-08-04 15:35:01 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/util/dom/reflect/Property.java $
30   *
31   * @author Adrian Moos (AMS)
32   */
33  
34  public class Property extends Member {
35  	/** this property's type. */
36  	public final Class<?> type;
37  	
38  	/** can this property not be written? */
39  	public final boolean readonly;
40  	
41  	/** creates the property information object declared by field {@code f}
42  	 * in {@code declaring.clazz}. */
43  	Property(EntityType declaring, Field f) {
44  		super(
45  			declaring,
46  			f.getName()
47  		);
48  		type = f.getType();
49  		readonly = false;
50  	}
51  
52  	/** creates the property information object describing a property
53  	 * declared in a getter/setter pair.
54  	 * @param declaring the declaring entity type
55  	 * @param getter the getter
56  	 * @param name the property's name as defined by the Java Beans standard
57  	 * @param setter the setter
58  	 */
59  	Property(EntityType declaring, Method getter, String name, Method setter) {
60  		super(
61  			declaring,
62  			name
63  		);
64  		type = getter.getReturnType();
65  		readonly = setter == null;
66  	}
67  }