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