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 Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.ws.processor.generator;
038:
039: import com.sun.tools.ws.processor.model.Fault;
040: import com.sun.tools.ws.processor.model.ModelProperties;
041: import com.sun.tools.ws.processor.model.Port;
042: import com.sun.tools.ws.processor.model.Service;
043: import com.sun.tools.ws.processor.model.java.JavaInterface;
044: import com.sun.tools.ws.processor.model.java.JavaStructureMember;
045: import com.sun.tools.ws.util.ClassNameInfo;
046: import com.sun.xml.ws.util.StringUtils;
047: import com.sun.istack.Nullable;
048: import com.sun.istack.NotNull;
049:
050: import javax.xml.namespace.QName;
051: import java.util.HashMap;
052: import java.util.Map;
053:
054: /**
055: * Names provides utility methods used by other wscompile classes
056: * for dealing with identifiers.
057: *
058: * @author WS Development Team
059: */
060: public class Names implements GeneratorConstants {
061:
062: public static String getPortName(Port port) {
063: String javaPortName = (String) port
064: .getProperty(ModelProperties.PROPERTY_JAVA_PORT_NAME);
065: if (javaPortName != null) {
066: return javaPortName;
067: } else {
068: QName portName = (QName) port
069: .getProperty(ModelProperties.PROPERTY_WSDL_PORT_NAME);
070: if (portName != null) {
071: return portName.getLocalPart();
072: } else {
073: String name = stripQualifier(port.getJavaInterface()
074: .getName());
075: return ClassNameInfo.replaceInnerClassSym(name);
076: }
077: }
078: }
079:
080: public static String stripQualifier(String name) {
081: return ClassNameInfo.getName(name);
082: }
083:
084: public static String getPackageName(String className) {
085: String packageName = ClassNameInfo.getQualifier(className);
086: return packageName != null ? packageName : "";
087: }
088:
089: public static String customJavaTypeClassName(JavaInterface intf) {
090: return intf.getName();
091: }
092:
093: public static String customExceptionClassName(Fault fault) {
094: return fault.getJavaException().getName();
095: }
096:
097: public static String getExceptionClassMemberName() {
098: return FAULT_CLASS_MEMBER_NAME;
099: }
100:
101: public static boolean isJavaReservedWord(String name) {
102: return reservedWords.get(name) != null;
103: }
104:
105: /**
106: * See if its a java keyword name, if so then mangle the name
107: */
108: public static @NotNull
109: String getJavaReserverVarialbeName(@NotNull
110: String name) {
111: return (reservedWords.get(name) == null) ? name : reservedWords
112: .get(name);
113: }
114:
115: /* here we check on wether return values datatype is
116: boolean. If its boolean, instead of a get method
117: its set a is<MethodName> to comply with JavaBeans
118: Pattern spec */
119: public static String getJavaMemberReadMethod(
120: JavaStructureMember member) {
121: String return_value;
122: if (member.getType().getRealName().equals("boolean")) {
123: return_value = IS
124: + StringUtils.capitalize(member.getName());
125: } else {
126: return_value = GET
127: + StringUtils.capitalize(member.getName());
128: }
129: return (return_value);
130: }
131:
132: public static String getResponseName(String messageName) {
133: return messageName + RESPONSE;
134: }
135:
136: private static final Map<String, String> reservedWords;
137:
138: static {
139: reservedWords = new HashMap<String, String>();
140: reservedWords.put("abstract", "_abstract");
141: reservedWords.put("assert", "_assert");
142: reservedWords.put("boolean", "_boolean");
143: reservedWords.put("break", "_break");
144: reservedWords.put("byte", "_byte");
145: reservedWords.put("case", "_case");
146: reservedWords.put("catch", "_catch");
147: reservedWords.put("char", "_char");
148: reservedWords.put("class", "_class");
149: reservedWords.put("const", "_const");
150: reservedWords.put("continue", "_continue");
151: reservedWords.put("default", "_default");
152: reservedWords.put("do", "_do");
153: reservedWords.put("double", "_double");
154: reservedWords.put("else", "_else");
155: reservedWords.put("extends", "_extends");
156: reservedWords.put("false", "_false");
157: reservedWords.put("final", "_final");
158: reservedWords.put("finally", "_finally");
159: reservedWords.put("float", "_float");
160: reservedWords.put("for", "_for");
161: reservedWords.put("goto", "_goto");
162: reservedWords.put("if", "_if");
163: reservedWords.put("implements", "_implements");
164: reservedWords.put("import", "_import");
165: reservedWords.put("instanceof", "_instanceof");
166: reservedWords.put("int", "_int");
167: reservedWords.put("interface", "_interface");
168: reservedWords.put("long", "_long");
169: reservedWords.put("native", "_native");
170: reservedWords.put("new", "_new");
171: reservedWords.put("null", "_null");
172: reservedWords.put("package", "_package");
173: reservedWords.put("private", "_private");
174: reservedWords.put("protected", "_protected");
175: reservedWords.put("public", "_public");
176: reservedWords.put("return", "_return");
177: reservedWords.put("short", "_short");
178: reservedWords.put("static", "_static");
179: reservedWords.put("strictfp", "_strictfp");
180: reservedWords.put("super", "_super");
181: reservedWords.put("switch", "_switch");
182: reservedWords.put("synchronized", "_synchronized");
183: reservedWords.put("this", "_this");
184: reservedWords.put("throw", "_throw");
185: reservedWords.put("throws", "_throws");
186: reservedWords.put("transient", "_transient");
187: reservedWords.put("true", "_true");
188: reservedWords.put("try", "_try");
189: reservedWords.put("void", "_void");
190: reservedWords.put("volatile", "_volatile");
191: reservedWords.put("while", "_while");
192: reservedWords.put("enum", "_enum");
193: }
194: }
|