Source Code Cross Referenced for JavaType.java in  » Web-Services-apache-cxf-2.0.1 » tools-common » org » apache » cxf » tools » common » model » 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 » Web Services apache cxf 2.0.1 » tools common » org.apache.cxf.tools.common.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */package org.apache.cxf.tools.common.model;
019:
020:        import java.io.IOException;
021:        import java.io.Writer;
022:        import java.lang.reflect.Constructor;
023:        import java.util.HashMap;
024:        import java.util.Map;
025:        import javax.xml.namespace.QName;
026:
027:        public class JavaType {
028:
029:            public static enum Style {
030:                IN, OUT, INOUT
031:            }
032:
033:            private static Map<String, String> typeMapping = new HashMap<String, String>();
034:
035:            static {
036:                typeMapping.put("boolean", "false");
037:                typeMapping.put("int", "0");
038:                typeMapping.put("long", "0");
039:                typeMapping.put("short", "Short.parseShort(\"0\")");
040:                typeMapping.put("byte", "Byte.parseByte(\"0\")");
041:                typeMapping.put("float", "0.0f");
042:                typeMapping.put("double", "0.0");
043:                typeMapping.put("char", "0");
044:                typeMapping.put("java.lang.String", "\"\"");
045:
046:                typeMapping.put("javax.xml.namespace.QName",
047:                        "new javax.xml.namespace.QName(\"\", \"\")");
048:                typeMapping.put("java.net.URI", "new java.net.URI(\"\")");
049:
050:                typeMapping.put("java.math.BigInteger",
051:                        "new java.math.BigInteger(\"0\")");
052:                typeMapping.put("java.math.BigDecimal",
053:                        "new java.math.BigDecimal(\"0\")");
054:                typeMapping.put("javax.xml.datatype.XMLGregorianCalendar",
055:                        "null");
056:                // javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar()
057:                typeMapping.put("javax.xml.datatype.Duration", "null");
058:                // javax.xml.datatype.DatatypeFactory.newInstance().newDuration(\"P1Y35DT60M60.500S\")
059:            }
060:
061:            protected String name;
062:            protected String type;
063:            protected String className;
064:            protected String targetNamespace;
065:            protected Style style;
066:            protected boolean isHeader;
067:            private QName qname;
068:            private JavaInterface owner;
069:            private DefaultValueWriter dvw;
070:
071:            public JavaType() {
072:            }
073:
074:            public JavaType(String n, String t, String tns) {
075:                this .name = n;
076:                this .type = t;
077:                this .targetNamespace = tns;
078:                this .className = t;
079:            }
080:
081:            public void setDefaultValueWriter(DefaultValueWriter w) {
082:                dvw = w;
083:            }
084:
085:            public DefaultValueWriter getDefaultValueWriter() {
086:                return dvw;
087:            }
088:
089:            public void setQName(QName qn) {
090:                this .qname = qn;
091:            }
092:
093:            public QName getQName() {
094:                return this .qname;
095:            }
096:
097:            public void setClassName(String clzName) {
098:                this .className = clzName;
099:            }
100:
101:            public String getClassName() {
102:                return this .className;
103:            }
104:
105:            public void writeDefaultValue(Writer writer, String indent,
106:                    String opName, String varName) throws IOException {
107:                if (dvw != null) {
108:                    dvw.writeDefaultValue(writer, indent, opName, varName);
109:                } else {
110:                    writer.write(className);
111:                    writer.write(' ');
112:                    writer.write(varName);
113:                    writer.write(" = ");
114:                    writer.write(getDefaultTypeValue());
115:                    writer.write(";");
116:                }
117:            }
118:
119:            protected String getDefaultTypeValue() {
120:                if (this .className.trim().endsWith("[]")) {
121:                    return "new "
122:                            + this .className.substring(0, this .className
123:                                    .length() - 2) + "[0]";
124:                }
125:                if (typeMapping.containsKey(this .className.trim())) {
126:                    return typeMapping.get(this .className);
127:                }
128:
129:                try {
130:                    if (hasDefaultConstructor(Class.forName(this .className))) {
131:                        return "new " + this .className + "()";
132:                    }
133:                } catch (ClassNotFoundException e) {
134:                    // DONE
135:                }
136:                return "null";
137:            }
138:
139:            private boolean hasDefaultConstructor(Class clz) {
140:                Constructor[] cons = clz.getConstructors();
141:                if (cons.length == 0) {
142:                    return false;
143:                } else {
144:                    for (int i = 0; i < cons.length; i++) {
145:                        if (cons[i].getParameterTypes().length == 0) {
146:                            return true;
147:                        }
148:                    }
149:                }
150:                return false;
151:            }
152:
153:            public void setTargetNamespace(String tns) {
154:                this .targetNamespace = tns;
155:            }
156:
157:            public String getTargetNamespace() {
158:                return this .targetNamespace;
159:            }
160:
161:            public String getRawName() {
162:                return this .name;
163:            }
164:
165:            public String getName() {
166:                return this .name;
167:            }
168:
169:            public void setName(String s) {
170:                name = s;
171:            }
172:
173:            public String getType() {
174:                return type;
175:            }
176:
177:            public void setType(String t) {
178:                type = t;
179:            }
180:
181:            //
182:            // getter and setter for in, out inout style
183:            //
184:            public JavaType.Style getStyle() {
185:                return this .style;
186:            }
187:
188:            public void setStyle(Style s) {
189:                this .style = s;
190:            }
191:
192:            public boolean isIN() {
193:                return this .style == Style.IN;
194:            }
195:
196:            public boolean isOUT() {
197:                return this .style == Style.OUT;
198:            }
199:
200:            public boolean isINOUT() {
201:                return this .style == Style.INOUT;
202:            }
203:
204:            public void setHeader(boolean header) {
205:                this .isHeader = header;
206:            }
207:
208:            public boolean isHeader() {
209:                return this .isHeader;
210:            }
211:
212:            public String toString() {
213:                final StringBuffer sb = new StringBuffer();
214:                sb.append("\nName: ");
215:                sb.append(this .name);
216:                sb.append("\nType: ");
217:                sb.append(this .type);
218:                sb.append("\nClassName: ");
219:                sb.append(this .className);
220:                sb.append("\nTargetNamespace: ");
221:                sb.append(this .targetNamespace);
222:                sb.append("\nStyle: ");
223:                sb.append(style);
224:                return sb.toString();
225:            }
226:
227:            public JavaInterface getOwner() {
228:                return this .owner;
229:            }
230:
231:            public void setOwner(JavaInterface intf) {
232:                this.owner = intf;
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.