01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.codegen.builder.properties;
20:
21: import java.lang.reflect.Method;
22:
23: import com.jeta.forms.gui.beans.JETAPropertyDescriptor;
24: import com.jeta.forms.store.properties.TransformOptionsProperty;
25: import com.jeta.swingbuilder.codegen.builder.BasicExpression;
26: import com.jeta.swingbuilder.codegen.builder.BeanWriter;
27: import com.jeta.swingbuilder.codegen.builder.DeclarationHelper;
28: import com.jeta.swingbuilder.codegen.builder.DeclarationManager;
29: import com.jeta.swingbuilder.codegen.builder.Expression;
30: import com.jeta.swingbuilder.codegen.builder.MethodStatement;
31: import com.jeta.swingbuilder.codegen.builder.PropertyWriter;
32:
33: public class TransformPropertyWriter implements PropertyWriter {
34:
35: /**
36: * PropertyWriter implementation
37: */
38: public void writeProperty(DeclarationManager declMgr,
39: BeanWriter writer, JETAPropertyDescriptor pd, Object value) {
40: try {
41: if (value instanceof TransformOptionsProperty) {
42: TransformOptionsProperty tprop = (TransformOptionsProperty) value;
43: Object pvalue = tprop.getCurrentItem();
44: if (pvalue != null) {
45: Method write = tprop.getWriteMethod();
46: if (write != null) {
47: MethodStatement ms = new MethodStatement(writer
48: .getBeanVariable(), write.getName());
49: ms
50: .addParameter(createTransformExpression(
51: writer.getBeanType(), pvalue
52: .toString()));
53: writer.addStatement(ms);
54: } else {
55: System.out
56: .println("TransformOptionsProperty.write method is null for: "
57: + pd.getName());
58: }
59: }
60: }
61: } catch (Exception e) {
62: e.printStackTrace();
63: }
64: }
65:
66: public static Expression createTransformExpression(Class beanType,
67: String propValue) {
68: if (propValue != null && propValue.length() > 0) {
69: String cname = DeclarationHelper.trimPackage(beanType);
70: if (cname != null && cname.length() > 0) {
71: BasicExpression expr = new BasicExpression(cname + "."
72: + propValue);
73: return expr;
74: }
75: }
76: return null;
77: }
78:
79: }
|