001: package org.conform;
002:
003: import org.apache.commons.logging.LogFactory;
004:
005: /**
006: * @author hengels
007: * @version $Revision: 812 $
008: */
009: public class DefaultPropertyData extends AbstractPropertyData {
010: private static org.apache.commons.logging.Log LOG = LogFactory
011: .getLog(Data.class);
012:
013: BeanMeta beanMeta;
014: Data relationData;
015:
016: public DefaultPropertyData(DefaultBeanData beanData,
017: PropertyMeta property) {
018: super (beanData, property);
019: this .beanMeta = beanData.getBeanMeta();
020: }
021:
022: public Object doGetValue() {
023: return ((DefaultBeanData) beanData).doGetValue(propertyMeta);
024: }
025:
026: public void doSetValue(Object value) {
027: ((DefaultBeanData) beanData).doSetValue(propertyMeta, value);
028: }
029:
030: public Data getRelationData() {
031: if (relationData == null) {
032: if (propertyMeta.getRelationType() == PropertyMeta.ONE_TO_MANY_RELATION)
033: relationData = new DefaultTableData(propertyMeta
034: .getRelationBean());
035: else if (propertyMeta.getRelationType() == PropertyMeta.ONE_TO_ONE_RELATION)
036: relationData = new DefaultBeanData(propertyMeta
037: .getRelationBean());
038: else
039: LOG.warn("na so was property.getRelationType() = "
040: + propertyMeta.getRelationType());
041:
042: relationData
043: .addValidationListener(new ValidationListener() {
044: public void addIssues(ValidationEvent event) {
045: fireAddIssue(event);
046: }
047:
048: public void removeIssues(ValidationEvent event) {
049: fireRemoveIssue(event);
050: }
051:
052: public void clearIssues(Meta meta) {
053: }
054: });
055: }
056: return relationData;
057: }
058:
059: /*
060: Object bean;
061: private Method setter;
062: private Method getter;
063:
064: protected void doSetValue(Object value) {
065: if (setter == null)
066: reflect();
067:
068: try {
069: setter.invoke(bean, value);
070: }
071: catch (Exception e) {
072: throw new RuntimeException(e);
073: }
074: }
075:
076: protected Object doGetValue() {
077: if (getter == null)
078: reflect();
079:
080: try {
081: return getter.invoke(bean);
082: }
083: catch (Exception e) {
084: throw new RuntimeException(e);
085: }
086: }
087:
088: private void reflect() {
089: String name = propertyMeta.getName();
090: char chars[] = new char[name.length() + 3];
091: name.getChars(0, name.length(), chars, 3);
092: chars[3] = Character.toUpperCase(chars[3]);
093: chars[2] = 't';
094: chars[1] = 'e';
095: try {
096: chars[0] = 's';
097: setter = beanMeta.getType().getMethod(new String(chars));
098: }
099: catch (NoSuchMethodException e) {
100: e.printStackTrace();
101: }
102: try {
103: chars[0] = 'g';
104: getter = beanMeta.getType().getMethod(new String(chars));
105: }
106: catch (NoSuchMethodException e) {
107: e.printStackTrace();
108: }
109: }
110: */
111: }
|