KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > jaxrpc > WrapperClientBeanInfoWriter


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.jaxrpc;
21
22 import com.sun.xml.rpc.processor.model.java.JavaException;
23 import com.sun.xml.rpc.processor.model.java.JavaMethod;
24 import com.sun.xml.rpc.processor.model.java.JavaParameter;
25 import java.io.OutputStreamWriter JavaDoc;
26 import java.io.PrintWriter JavaDoc;
27 import java.io.Writer JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Set JavaDoc;
31
32 /**
33  * A simple writer to write the Bean Info Class.
34  * @author Winston Prakash
35  */

36 public class WrapperClientBeanInfoWriter extends java.io.PrintWriter JavaDoc {
37
38     private String JavaDoc className;
39     private String JavaDoc superClassName;
40     private String JavaDoc packageName;
41     
42     private Set JavaDoc constructorStatements = new HashSet JavaDoc();
43     
44     public static String JavaDoc WEBSERVICE_ICON_FILENAME = "webservice.png";
45     
46     int indent = 0;
47     
48     /** Creates a new instance of JavaWriter */
49     public WrapperClientBeanInfoWriter(Writer JavaDoc writer){
50         super(writer);
51         setSuperClass("SimpleBeanInfo");
52     }
53     
54     /** Set package name */
55     public void setPackage(String JavaDoc pkgName){
56         packageName = pkgName;
57     }
58     
59     /** Set the name of the class */
60     public void setName(String JavaDoc name){
61         className = name;
62     }
63     
64     /** Set the name of the super class this class would extends */
65     public void setSuperClass(String JavaDoc superClass){
66         superClassName = superClass;
67     }
68     
69     public void writeBeanInfo(){
70         // Write the Package name
71
println("package " + packageName + ";");
72         println();
73         
74         println("import java.awt.Image;");
75         println("import java.beans.BeanDescriptor;");
76         println("import java.beans.PropertyDescriptor;");
77         println("import java.beans.SimpleBeanInfo;");
78         println();
79         
80         // Write the class signature
81
print("public class " + className + "BeanInfo");
82         if(superClassName != null) print(" extends " + superClassName + " ");
83         println(" {");
84         println();
85         
86         
87         println(" private Class beanClass = " + className + ".class;");
88         println(" private String iconFileName = \"" + this.WEBSERVICE_ICON_FILENAME + "\";");
89         println(" private BeanDescriptor beanDescriptor = null;");
90         println(" private PropertyDescriptor[] propDescriptors = null;");
91         
92         println();
93         
94         println(" public BeanDescriptor getBeanDescriptor() {");
95         println(" if (beanDescriptor == null) {");
96         println(" beanDescriptor = new BeanDescriptor(beanClass);");
97         println(" beanDescriptor.setValue(\"trayComponent\", Boolean.TRUE);");
98         println(" }");
99         println(" return beanDescriptor;");
100         println(" }");
101         
102         println();
103         
104         println(" public PropertyDescriptor[] getPropertyDescriptors() {");
105         println(" if (propDescriptors == null) {");
106         println(" propDescriptors = new PropertyDescriptor[] {");
107         println(" ");
108         println(" };");
109         println(" }");
110         println(" return propDescriptors;");
111         println(" }");
112         
113         println();
114         
115         println(" public Image getIcon(int iconKind) {");
116         println(" return loadImage(iconFileName);");
117         println(" }");
118         
119         println("}");
120     }
121     
122     /**
123      * @param args the command line arguments
124      */

125     public static void main(String JavaDoc[] args) {
126         try{
127             WrapperClientBeanInfoWriter beanWriter = new WrapperClientBeanInfoWriter(new OutputStreamWriter JavaDoc(System.out));
128             beanWriter.setPackage("untitled");
129             beanWriter.setName("WebserviceProxyClient");
130             beanWriter.writeBeanInfo();
131             beanWriter.flush();
132             beanWriter.close();
133         }catch(Exception JavaDoc exc){
134             exc.printStackTrace();
135         }
136     }
137     
138 }
139
Popular Tags