Source Code Cross Referenced for BeanWriter.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » codegen » builder » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » abeille forms designer » com.jeta.swingbuilder.codegen.builder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 Jeff Tassin
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package com.jeta.swingbuilder.codegen.builder;
020:
021:        import java.util.Collection;
022:        import java.util.Iterator;
023:        import java.util.LinkedList;
024:
025:        import javax.swing.JLabel;
026:        import javax.swing.JPanel;
027:
028:        import com.jeta.forms.beanmgr.BeanManager;
029:        import com.jeta.forms.components.label.JETALabel;
030:        import com.jeta.forms.gui.beans.DynamicBeanInfo;
031:        import com.jeta.forms.gui.beans.DynamicPropertyDescriptor;
032:        import com.jeta.forms.gui.beans.JETABean;
033:        import com.jeta.forms.gui.beans.JETABeanFactory;
034:        import com.jeta.forms.gui.beans.JETAPropertyDescriptor;
035:        import com.jeta.forms.gui.form.GridView;
036:        import com.jeta.forms.logger.FormsLogger;
037:        import com.jeta.forms.store.memento.PropertiesMemento;
038:        import com.jeta.forms.store.properties.TransformOptionsProperty;
039:        import com.jeta.open.registry.JETARegistry;
040:
041:        public class BeanWriter {
042:            private String m_bean_variable_name;
043:            private Class m_bean_type;
044:
045:            private String m_result_variable_name;
046:            private Class m_result_type;
047:
048:            private LinkedList m_statements = new LinkedList();
049:
050:            /** @directed */
051:            public BeanWriter(DeclarationManager decl_mgr, PropertiesMemento pm) {
052:                assert (pm != null);
053:                String classname = pm.getBeanClassName();
054:
055:                if (GridView.class.getName().equals(classname))
056:                    classname = "javax.swing.JPanel";
057:                else if (JETALabel.class.getName().equals(classname))
058:                    classname = "javax.swing.JLabel";
059:
060:                try {
061:                    Class beanclass = null;
062:                    try {
063:                        BeanManager bmgr = (BeanManager) JETARegistry
064:                                .lookup(BeanManager.COMPONENT_ID);
065:                        if (bmgr != null) {
066:                            beanclass = bmgr.getBeanClass(classname);
067:                        }
068:                    } catch (Exception e) {
069:                        FormsLogger.severe(e);
070:                    }
071:
072:                    if (beanclass == null) {
073:                        beanclass = Class.forName(classname);
074:                    }
075:
076:                    VariableDeclaration ds = null;
077:                    /**
078:                     * don't declare panels or labels as member variables if they don't
079:                     * have a name
080:                     */
081:                    if (JLabel.class.isAssignableFrom(beanclass)
082:                            || JPanel.class.isAssignableFrom(beanclass)) {
083:                        String compname = pm.getComponentName();
084:                        if (compname == null)
085:                            compname = "";
086:                        else
087:                            compname = compname.trim();
088:
089:                        if (compname.length() == 0) {
090:                            ds = new LocalVariableDeclaration(decl_mgr,
091:                                    beanclass, null);
092:                            /** temporary hack */
093:                            ((MethodWriter) decl_mgr).addStatement(ds);
094:                        }
095:                    }
096:
097:                    if (ds == null) {
098:                        ds = new MemberVariableDeclaration(decl_mgr, beanclass,
099:                                pm.getComponentName());
100:                        decl_mgr.addMemberVariable(ds);
101:                    }
102:
103:                    setBeanVariable(ds.getVariable(), beanclass);
104:                    setResultVariable(ds.getVariable(), beanclass);
105:
106:                    PropertyWriterFactory fac = (PropertyWriterFactory) JETARegistry
107:                            .lookup(PropertyWriterFactory.COMPONENT_ID);
108:                    LinkedList dynamic_props = new LinkedList();
109:
110:                    Class lookup_class = beanclass;
111:                    if (GridView.class.getName().equals(pm.getBeanClassName()))
112:                        lookup_class = GridView.class;
113:
114:                    DynamicBeanInfo beaninfo = JETABeanFactory
115:                            .getBeanInfo(lookup_class);
116:                    Collection jeta_pds = beaninfo.getPropertyDescriptors();
117:                    Iterator iter = jeta_pds.iterator();
118:                    while (iter.hasNext()) {
119:                        try {
120:                            JETAPropertyDescriptor jpd = (JETAPropertyDescriptor) iter
121:                                    .next();
122:                            if (pm.containsProperty(jpd.getName())) {
123:
124:                                if (jpd instanceof  DynamicPropertyDescriptor) {
125:                                    dynamic_props.add(jpd);
126:                                } else {
127:                                    Object prop_value = pm.getPropertyValue(jpd
128:                                            .getName());
129:                                    if ("name".equals(jpd.getName())
130:                                            && "".equals(prop_value)) {
131:                                        continue;
132:                                    }
133:
134:                                    PropertyWriter pw = fac.createWriter(jpd
135:                                            .getPropertyType());
136:                                    if (pw != null) {
137:                                        pw.writeProperty(decl_mgr, this , jpd,
138:                                                prop_value);
139:                                    }
140:                                }
141:                            }
142:                        } catch (Exception e) {
143:                            FormsLogger.debug(e);
144:                        }
145:                    }
146:
147:                    /** now do the dynamic props */
148:                    iter = dynamic_props.iterator();
149:                    while (iter.hasNext()) {
150:                        DynamicPropertyDescriptor dpd = (DynamicPropertyDescriptor) iter
151:                                .next();
152:
153:                        PropertyWriter pw = fac.createWriter(dpd
154:                                .getPropertyType());
155:                        if (pw != null) {
156:                            Object prop_value = null;
157:                            if (dpd.getPropertyType() == TransformOptionsProperty.class) {
158:                                JETABean jetabean = JETABeanFactory.createBean(
159:                                        beanclass.getName(), null, true, true);
160:                                jetabean.setState(pm);
161:                                TransformOptionsProperty tprop = (TransformOptionsProperty) jetabean
162:                                        .getCustomProperty(dpd.getName());
163:                                prop_value = tprop;
164:                            } else {
165:                                prop_value = pm.getPropertyValue(dpd.getName());
166:                            }
167:                            pw.writeProperty(decl_mgr, this , dpd, prop_value);
168:                        }
169:                    }
170:                } catch (Exception e) {
171:                    e.printStackTrace();
172:                }
173:            }
174:
175:            public void addStatement(Statement stmt) {
176:                if (stmt != null)
177:                    m_statements.add(stmt);
178:            }
179:
180:            public Collection getStatements() {
181:                return m_statements;
182:            }
183:
184:            public void setBeanVariable(String varName, Class beanType) {
185:                m_bean_variable_name = varName;
186:                m_bean_type = beanType;
187:            }
188:
189:            public String getBeanVariable() {
190:                return m_bean_variable_name;
191:            }
192:
193:            public Class getBeanType() {
194:                return m_bean_type;
195:            }
196:
197:            public String getResultVariable() {
198:                return m_result_variable_name;
199:            }
200:
201:            public Class getResultType() {
202:                return m_result_type;
203:            }
204:
205:            public void setResultVariable(String varName, Class resultType) {
206:                m_result_variable_name = varName;
207:                m_result_type = resultType;
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.