View Javadoc

1   package com.silvermindsoftware.hitch.meta;
2   
3   /**
4    * Copyright 2007 Brandon Goodin
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import com.silvermindsoftware.hitch.ReadOnly;
20  
21  import java.lang.reflect.Field;
22  import java.lang.reflect.Method;
23  
24  /**
25   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/swing/src/main/java/com/silvermindsoftware/hitch/meta/ComponentMeta.java $
26   */
27  public class ComponentMeta {
28  
29  	private Class modelPropertyType;
30  	private Class modelType;
31  	private String modelPropertyName;
32  	private String modelId;
33  	private Field componentField;
34  	private Field modelField;
35  	private Method modelGetter;
36  	private Method modelSetter;
37  
38  	private Class componentHandler;
39  	private String[] handlerValues;
40  
41  	private boolean autoBound;
42  	private ReadOnly readOnly;
43  
44  	public ComponentMeta(String propertyName, String modelId) {
45  		this.modelPropertyName = propertyName;
46  		this.modelId = modelId;
47  	}
48  
49  	public ComponentMeta(
50  			Class modelType, String modelPropertyName, String modelId,
51  			Field componentField, Field modelField,
52  			Method modelGetter, Method modelSetter,
53  			Class componentHandler, String[] handlerValues,
54  			boolean autoBound, ReadOnly readOnly, Class modelPropertyType) {
55  
56  		this.modelType = modelType;
57  		this.modelPropertyName = modelPropertyName;
58  		this.modelId = modelId;
59  		this.componentField = componentField;
60  		this.componentField.setAccessible(true);
61  		this.modelField = modelField;
62  		if(modelField != null)
63  			this.modelField.setAccessible(true);
64  		this.modelGetter = modelGetter;
65  		this.modelSetter = modelSetter;
66  		this.componentHandler = componentHandler;
67  		this.handlerValues = handlerValues;
68  		this.autoBound = autoBound;
69  		this.readOnly = readOnly;
70  		this.modelPropertyType = modelPropertyType;
71  
72  	}
73  
74  	public Class getModelType() {
75  		return modelType;
76  	}
77  
78  	public String getModelPropertyName() {
79  		return modelPropertyName;
80  	}
81  
82  	public String getModelId() {
83  		return modelId;
84  	}
85  
86  	public Field getComponentField() {
87  		return componentField;
88  	}
89  
90  	public Field getModelField() {
91  		return modelField;
92  	}
93  
94  	public boolean isModelGetter() {
95  		return modelGetter != null;
96  	}
97  
98  	public Method getModelGetter() {
99  		return modelGetter;
100 	}
101 
102 	public boolean isModelSetter() {
103 		return modelSetter != null;
104 	}
105 
106 	public Method getModelSetter() {
107 		return modelSetter;
108 	}
109 
110 	public Class getComponentHandler() {
111 		return componentHandler;
112 	}
113 
114 	public String[] getHandlerValues() {
115 		return handlerValues;
116 	}
117 
118 	public boolean isAutoBound() {
119 		return autoBound;
120 	}
121 
122 	public ReadOnly getReadOnly() {
123 		return readOnly;
124 	}
125 
126 	public Class getModelPropertyType() {
127 		return modelPropertyType;
128 	}
129 
130 	public String toString() {
131 		return modelPropertyName + modelId;
132 	}
133 
134 	public boolean equals(Object o) {
135 		if (this == o) return true;
136 		if (o == null || getClass() != o.getClass()) return false;
137 
138 		ComponentMeta that = (ComponentMeta) o;
139 
140 		if (modelId != null ? !modelId.equals(that.modelId) : that.modelId != null) return false;
141 		if (modelPropertyName != null ? !modelPropertyName.equals(that.modelPropertyName) : that.modelPropertyName != null)
142 			return false;
143 
144 		return true;
145 	}
146 
147 	public int hashCode() {
148 		int result;
149 		result = (modelPropertyName != null ? modelPropertyName.hashCode() : 0);
150 		result = 31 * result + (modelId != null ? modelId.hashCode() : 0);
151 		return result;
152 	}
153 }