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

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

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

mercurial