Source Code Cross Referenced for DataProviderBeanInfoWriter.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » websvcmgr » codegen » 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 » IDE Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.websvcmgr.codegen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.visualweb.websvcmgr.codegen;
043:
044:        import java.io.Writer;
045:        import java.util.Date;
046:        import org.netbeans.modules.websvc.manager.util.ManagerUtil;
047:
048:        public class DataProviderBeanInfoWriter extends java.io.PrintWriter {
049:
050:            // Hardcode the iconFileName here
051:            public static final String DATA_PROVIDER_ICON_FILE_NAME = "methodicon.png";
052:            public static final String DATA_PROVIDER_ICON_FILE_NAME2 = "table_dp_badge.png";
053:
054:            private static final String[][] DEFAULT_PROPERTIES = {
055:                    { "dataClassInstance", "prop_dataClassInstance",
056:                            "\"getDataClassInstance\"" },
057:                    { "dataMethod", "prop_dataMethod", "\"getDataMethod\"" },
058:                    { "dataMethodArguments", "propDataMethodArguments",
059:                            "\"getDataMethodArguments\"" },
060:                    { "resultObject", "prop_resultObject",
061:                            "\"getResultObject\"" },
062:                    { "resultObjects", "prop_resultObjects",
063:                            "\"getResultObjects\"" } };
064:
065:            private DataProviderInfo dataProviderInfo;
066:
067:            public DataProviderBeanInfoWriter(Writer writer,
068:                    DataProviderInfo dataProviderInfo) {
069:                super (writer);
070:                this .dataProviderInfo = dataProviderInfo;
071:            }
072:
073:            public void writeClass() {
074:                // package
075:                println("package " + dataProviderInfo.getPackageName() + ";");
076:                println();
077:
078:                // comments
079:                println("/**");
080:                println(" * Source code created on " + new Date());
081:                println(" */");
082:                println();
083:
084:                // Import
085:                println("import java.awt.Image;");
086:                println("import javax.swing.ImageIcon;");
087:                println("import java.beans.BeanDescriptor;");
088:                println("import java.beans.PropertyDescriptor;");
089:                println("import java.beans.SimpleBeanInfo;");
090:                println();
091:
092:                // Start class
093:                String beanInfoClassName = dataProviderInfo.getClassName()
094:                        + "BeanInfo";
095:                println("public class " + beanInfoClassName
096:                        + " extends SimpleBeanInfo {");
097:                println();
098:
099:                // Private variables
100:                String beanClassVariable = "beanClass";
101:                String iconFileNameVariable = "iconFileName";
102:                String iconFileNameVariable2 = "iconFileName2";
103:                String beanDescriptorVariable = "beanDescriptor";
104:                String propDescriptorsVariable = "propDescriptors";
105:                println("    private Class " + beanClassVariable + " = "
106:                        + dataProviderInfo.getClassName() + ".class;");
107:                println("    private PropertyDescriptor[] "
108:                        + propDescriptorsVariable + " = null; ");
109:                println("    private String " + iconFileNameVariable + " = \""
110:                        + DATA_PROVIDER_ICON_FILE_NAME + "\";");
111:                println("    private String " + iconFileNameVariable2 + " = \""
112:                        + DATA_PROVIDER_ICON_FILE_NAME2 + "\";");
113:                println("    private BeanDescriptor " + beanDescriptorVariable
114:                        + " = null;");
115:                println();
116:
117:                // Method - getIcon()
118:                println("    public Image getIcon(int iconKind) {");
119:                println("        ImageIcon imgIcon1 = new ImageIcon(getClass().getResource( "
120:                        + iconFileNameVariable + " )); ");
121:                println("        ImageIcon imgIcon2 = new ImageIcon(getClass().getResource( "
122:                        + iconFileNameVariable2 + " )); ");
123:                println("        return mergeImages( imgIcon1.getImage(), imgIcon2.getImage() );");
124:                println("    }");
125:                println();
126:
127:                println("    public PropertyDescriptor[] getPropertyDescriptors() {");
128:                println("        if (" + propDescriptorsVariable
129:                        + " != null) {");
130:                println("            return " + propDescriptorsVariable + ";");
131:                println("        }");
132:                println("        try {");
133:
134:                String indent = "            ";
135:                for (int i = 0; i < DEFAULT_PROPERTIES.length; i++) {
136:                    String[] p = DEFAULT_PROPERTIES[i];
137:                    genPropertyDescriptor(indent, p[1], p[0], p[2], "null",
138:                            true, true);
139:                }
140:                String clientClass = dataProviderInfo
141:                        .getClientWrapperClassName();
142:                String clientProp = ManagerUtil
143:                        .makeValidJavaBeanName(ManagerUtil
144:                                .decapitalize(clientClass));
145:                String clientVar = "prop_" + clientProp;
146:                String clientGetter = "\"get" + clientClass + "\"";
147:                String clientSetter = "\"set" + clientClass + "\"";
148:                genPropertyDescriptor(indent, clientVar, clientProp,
149:                        clientGetter, clientSetter, false, true);
150:
151:                for (DataProviderParameter p : dataProviderInfo.getMethod()
152:                        .getParameters()) {
153:                    String name = p.getName();
154:                    String propVar = "prop_" + name;
155:                    String nameCaps = ManagerUtil.upperCaseFirstChar(name);
156:                    String getter = "\"get" + nameCaps + "\"";
157:                    String setter = "\"set" + nameCaps + "\"";
158:
159:                    genPropertyDescriptor(indent, propVar, name, getter,
160:                            setter, false, false);
161:                }
162:
163:                println("            " + propDescriptorsVariable
164:                        + " = new PropertyDescriptor[] {");
165:                for (int i = 0; i < DEFAULT_PROPERTIES.length; i++) {
166:                    println("                " + DEFAULT_PROPERTIES[i][1] + ",");
167:                }
168:                for (DataProviderParameter p : dataProviderInfo.getMethod()
169:                        .getParameters()) {
170:                    println("                prop_" + p.getName() + ",");
171:                }
172:
173:                println("                " + clientVar);
174:                println("            };");
175:
176:                println("            return " + propDescriptorsVariable + ";");
177:                println("        }catch (java.beans.IntrospectionException e) {");
178:                println("            e.printStackTrace();");
179:                println("            return null;");
180:                println("        }");
181:                println("    }");
182:                println();
183:
184:                // private method for merging two images into one
185:                println("    private Image mergeImages (Image image1, Image image2) {");
186:                println("        int w = image1.getWidth(null);");
187:                println("        int h = image1.getHeight(null);");
188:                println("        int x = image1.getWidth(null) - image2.getWidth(null);");
189:                println("        int y = image1.getHeight(null) - image2.getHeight(null);");
190:                println();
191:                println("        java.awt.image.ColorModel model = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment ().");
192:                println("                                          getDefaultScreenDevice ().getDefaultConfiguration ().");
193:                println("                                          getColorModel (java.awt.Transparency.BITMASK);");
194:                println("        java.awt.image.BufferedImage buffImage = new java.awt.image.BufferedImage (model,");
195:                println("             model.createCompatibleWritableRaster (w, h), model.isAlphaPremultiplied (), null);");
196:                println();
197:                println("        java.awt.Graphics g = buffImage.createGraphics ();");
198:                println("        g.drawImage (image1, 0, 0, null);");
199:                println("        g.drawImage (image2, x, y, null);");
200:                println("        g.dispose();");
201:                println();
202:                println("        return buffImage;");
203:                println("    }");
204:                println();
205:
206:                // Method - getBeanDescriptor()
207:                println("    public BeanDescriptor getBeanDescriptor() {");
208:                println("        if( " + beanDescriptorVariable
209:                        + " == null ) {");
210:                println("           " + beanDescriptorVariable
211:                        + " = new BeanDescriptor( " + beanClassVariable + " );");
212:                println("           " + beanDescriptorVariable
213:                        + ".setValue( \"trayComponent\", Boolean.TRUE );");
214:                println("        }");
215:                println("        return " + beanDescriptorVariable + ";");
216:                println("    }");
217:                println("}");
218:            }
219:
220:            private void genPropertyDescriptor(String indent, String propVar,
221:                    String prop, String getter, String setter, boolean hidden,
222:                    boolean useCustomEditor) {
223:                println(indent + "PropertyDescriptor " + propVar
224:                        + " = new PropertyDescriptor(\"" + prop
225:                        + "\",beanClass," + getter + "," + setter + ");");
226:
227:                println(indent + propVar + ".setExpert(false);");
228:
229:                if (hidden) {
230:                    println(indent + propVar + ".setHidden(true);");
231:                } else {
232:                    println(indent + propVar + ".setHidden(false);");
233:                }
234:
235:                println(indent + propVar + ".setPreferred(false);");
236:
237:                if (useCustomEditor) {
238:                    println(indent
239:                            + propVar
240:                            + ".setPropertyEditorClass(com.sun.rave.propertyeditors.SelectOneDomainEditor.class);");
241:                    println(indent
242:                            + propVar
243:                            + ".setValue(com.sun.rave.designtime.Constants.PropertyDescriptor.CATEGORY,com.sun.rave.designtime.base.CategoryDescriptors.DATA);");
244:                    println(indent
245:                            + propVar
246:                            + ".setValue(\"com.sun.rave.propertyeditors.DOMAIN_CLASS\", com.sun.rave.propertyeditors.domains.InstanceVariableDomain.class);");
247:                }
248:            }
249:
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.