001: package com.silvermindsoftware.hitch.meta;
002:
003: /**
004: * Copyright 2007 Brandon Goodin
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import com.silvermindsoftware.hitch.ReadOnly;
020:
021: import java.lang.reflect.Field;
022: import java.lang.reflect.Method;
023:
024: public class ComponentMeta {
025:
026: private Class modelPropertyType;
027: private Class modelType;
028: private String modelPropertyName;
029: private String modelId;
030: private Field componentField;
031: private Field modelField;
032: private Method modelGetter;
033: private Method modelSetter;
034:
035: private Class componentHandler;
036: private String[] handlerValues;
037:
038: private boolean autoBound;
039: private ReadOnly readOnly;
040:
041: public ComponentMeta(String propertyName, String modelId) {
042: this .modelPropertyName = propertyName;
043: this .modelId = modelId;
044: }
045:
046: public ComponentMeta(Class modelType, String modelPropertyName,
047: String modelId, Field componentField, Field modelField,
048: Method modelGetter, Method modelSetter,
049: Class componentHandler, String[] handlerValues,
050: boolean autoBound, ReadOnly readOnly,
051: Class modelPropertyType) {
052:
053: this .modelType = modelType;
054: this .modelPropertyName = modelPropertyName;
055: this .modelId = modelId;
056: this .componentField = componentField;
057: this .componentField.setAccessible(true);
058: this .modelField = modelField;
059: if (modelField != null)
060: this .modelField.setAccessible(true);
061: this .modelGetter = modelGetter;
062: this .modelSetter = modelSetter;
063: this .componentHandler = componentHandler;
064: this .handlerValues = handlerValues;
065: this .autoBound = autoBound;
066: this .readOnly = readOnly;
067: this .modelPropertyType = modelPropertyType;
068:
069: }
070:
071: public Class getModelType() {
072: return modelType;
073: }
074:
075: public String getModelPropertyName() {
076: return modelPropertyName;
077: }
078:
079: public String getModelId() {
080: return modelId;
081: }
082:
083: public Field getComponentField() {
084: return componentField;
085: }
086:
087: public Field getModelField() {
088: return modelField;
089: }
090:
091: public boolean isModelGetter() {
092: return modelGetter != null;
093: }
094:
095: public Method getModelGetter() {
096: return modelGetter;
097: }
098:
099: public boolean isModelSetter() {
100: return modelSetter != null;
101: }
102:
103: public Method getModelSetter() {
104: return modelSetter;
105: }
106:
107: public Class getComponentHandler() {
108: return componentHandler;
109: }
110:
111: public String[] getHandlerValues() {
112: return handlerValues;
113: }
114:
115: public boolean isAutoBound() {
116: return autoBound;
117: }
118:
119: public ReadOnly getReadOnly() {
120: return readOnly;
121: }
122:
123: public Class getModelPropertyType() {
124: return modelPropertyType;
125: }
126:
127: public String toString() {
128: return modelPropertyName + modelId;
129: }
130:
131: public boolean equals(Object o) {
132: if (this == o)
133: return true;
134: if (o == null || getClass() != o.getClass())
135: return false;
136:
137: ComponentMeta that = (ComponentMeta) o;
138:
139: if (modelId != null ? !modelId.equals(that.modelId)
140: : that.modelId != null)
141: return false;
142: if (modelPropertyName != null ? !modelPropertyName
143: .equals(that.modelPropertyName)
144: : that.modelPropertyName != null)
145: return false;
146:
147: return true;
148: }
149:
150: public int hashCode() {
151: int result;
152: result = (modelPropertyName != null ? modelPropertyName
153: .hashCode() : 0);
154: result = 31 * result
155: + (modelId != null ? modelId.hashCode() : 0);
156: return result;
157: }
158: }
|