src/share/jaxws_classes/com/sun/tools/internal/ws/processor/generator/Names.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
equal deleted inserted replaced
-1:000000000000 0:373ffda63c9a
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.internal.ws.processor.generator;
27
28 import com.sun.istack.internal.NotNull;
29 import com.sun.tools.internal.ws.processor.model.Fault;
30 import com.sun.tools.internal.ws.processor.model.ModelProperties;
31 import com.sun.tools.internal.ws.processor.model.Port;
32 import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
33 import com.sun.tools.internal.ws.processor.model.java.JavaStructureMember;
34 import com.sun.tools.internal.ws.processor.modeler.ModelerConstants;
35 import com.sun.tools.internal.ws.util.ClassNameInfo;
36 import com.sun.xml.internal.ws.util.StringUtils;
37
38 import javax.xml.namespace.QName;
39 import java.util.HashMap;
40 import java.util.Map;
41
42 /**
43 * Names provides utility methods used by other wscompile classes
44 * for dealing with identifiers.
45 *
46 * @author WS Development Team
47 */
48 public final class Names {
49
50 private Names() {
51 }
52
53 public static String getPortName(Port port) {
54 String javaPortName =
55 (String) port.getProperty(ModelProperties.PROPERTY_JAVA_PORT_NAME);
56 if (javaPortName != null) {
57 return javaPortName;
58 } else {
59 QName portName =
60 (QName) port.getProperty(
61 ModelProperties.PROPERTY_WSDL_PORT_NAME);
62 if (portName != null) {
63 return portName.getLocalPart();
64 } else {
65 String name = stripQualifier(port.getJavaInterface().getName());
66 return ClassNameInfo.replaceInnerClassSym(name);
67 }
68 }
69 }
70
71
72 public static String stripQualifier(String name) {
73 return ClassNameInfo.getName(name);
74 }
75
76 public static String getPackageName(String className) {
77 String packageName = ClassNameInfo.getQualifier(className);
78 return packageName != null ? packageName : "";
79 }
80
81
82 public static String customJavaTypeClassName(JavaInterface intf) {
83 return intf.getName();
84 }
85
86 public static String customExceptionClassName(Fault fault) {
87 return fault.getJavaException().getName();
88 }
89
90 public static String getExceptionClassMemberName(){
91 return GeneratorConstants.FAULT_CLASS_MEMBER_NAME.getValue();
92 }
93
94 public static boolean isJavaReservedWord(String name) {
95 return RESERVED_WORDS.get(name) != null;
96 }
97
98 /**
99 * See if its a java keyword name, if so then mangle the name
100 */
101 public static @NotNull String getJavaReserverVarialbeName(@NotNull String name){
102 return (RESERVED_WORDS.get(name) == null) ? name : RESERVED_WORDS.get(name);
103 }
104
105 /* here we check on wether return values datatype is
106 boolean. If its boolean, instead of a get method
107 its set a is<MethodName> to comply with JavaBeans
108 Pattern spec */
109 public static String getJavaMemberReadMethod(JavaStructureMember member) {
110 String return_value;
111 if (member.getType().getRealName().equals(ModelerConstants.BOOLEAN_CLASSNAME.getValue())) {
112 return_value = GeneratorConstants.IS.getValue() + StringUtils.capitalize(member.getName());
113 } else {
114 return_value = GeneratorConstants.GET.getValue() + StringUtils.capitalize(member.getName());
115 }
116 return (return_value);
117 }
118
119 public static String getResponseName(String messageName) {
120 return messageName + GeneratorConstants.RESPONSE.getValue();
121 }
122
123 private static final Map<String, String> RESERVED_WORDS = new HashMap<String, String>(53);
124
125 static {
126 RESERVED_WORDS.put("abstract", "_abstract");
127 RESERVED_WORDS.put("assert", "_assert");
128 RESERVED_WORDS.put("boolean", "_boolean");
129 RESERVED_WORDS.put("break", "_break");
130 RESERVED_WORDS.put("byte", "_byte");
131 RESERVED_WORDS.put("case", "_case");
132 RESERVED_WORDS.put("catch", "_catch");
133 RESERVED_WORDS.put("char", "_char");
134 RESERVED_WORDS.put("class", "_class");
135 RESERVED_WORDS.put("const", "_const");
136 RESERVED_WORDS.put("continue", "_continue");
137 RESERVED_WORDS.put("default", "_default");
138 RESERVED_WORDS.put("do", "_do");
139 RESERVED_WORDS.put("double", "_double");
140 RESERVED_WORDS.put("else", "_else");
141 RESERVED_WORDS.put("extends", "_extends");
142 RESERVED_WORDS.put("false", "_false");
143 RESERVED_WORDS.put("final", "_final");
144 RESERVED_WORDS.put("finally", "_finally");
145 RESERVED_WORDS.put("float", "_float");
146 RESERVED_WORDS.put("for", "_for");
147 RESERVED_WORDS.put("goto", "_goto");
148 RESERVED_WORDS.put("if", "_if");
149 RESERVED_WORDS.put("implements", "_implements");
150 RESERVED_WORDS.put("import", "_import");
151 RESERVED_WORDS.put("instanceof", "_instanceof");
152 RESERVED_WORDS.put("int", "_int");
153 RESERVED_WORDS.put("interface", "_interface");
154 RESERVED_WORDS.put("long", "_long");
155 RESERVED_WORDS.put("native", "_native");
156 RESERVED_WORDS.put("new", "_new");
157 RESERVED_WORDS.put("null", "_null");
158 RESERVED_WORDS.put("package", "_package");
159 RESERVED_WORDS.put("private", "_private");
160 RESERVED_WORDS.put("protected", "_protected");
161 RESERVED_WORDS.put("public", "_public");
162 RESERVED_WORDS.put("return", "_return");
163 RESERVED_WORDS.put("short", "_short");
164 RESERVED_WORDS.put("static", "_static");
165 RESERVED_WORDS.put("strictfp", "_strictfp");
166 RESERVED_WORDS.put("super", "_super");
167 RESERVED_WORDS.put("switch", "_switch");
168 RESERVED_WORDS.put("synchronized", "_synchronized");
169 RESERVED_WORDS.put("this", "_this");
170 RESERVED_WORDS.put("throw", "_throw");
171 RESERVED_WORDS.put("throws", "_throws");
172 RESERVED_WORDS.put("transient", "_transient");
173 RESERVED_WORDS.put("true", "_true");
174 RESERVED_WORDS.put("try", "_try");
175 RESERVED_WORDS.put("void", "_void");
176 RESERVED_WORDS.put("volatile", "_volatile");
177 RESERVED_WORDS.put("while", "_while");
178 RESERVED_WORDS.put("enum", "_enum");
179 }
180 }

mercurial