aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.internal.ws.processor.generator; aoqi@0: aoqi@0: import com.sun.istack.internal.NotNull; aoqi@0: import com.sun.tools.internal.ws.processor.model.Fault; aoqi@0: import com.sun.tools.internal.ws.processor.model.ModelProperties; aoqi@0: import com.sun.tools.internal.ws.processor.model.Port; aoqi@0: import com.sun.tools.internal.ws.processor.model.java.JavaInterface; aoqi@0: import com.sun.tools.internal.ws.processor.model.java.JavaStructureMember; aoqi@0: import com.sun.tools.internal.ws.processor.modeler.ModelerConstants; aoqi@0: import com.sun.tools.internal.ws.util.ClassNameInfo; aoqi@0: import com.sun.xml.internal.ws.util.StringUtils; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import java.util.HashMap; aoqi@0: import java.util.Map; aoqi@0: aoqi@0: /** aoqi@0: * Names provides utility methods used by other wscompile classes aoqi@0: * for dealing with identifiers. aoqi@0: * aoqi@0: * @author WS Development Team aoqi@0: */ aoqi@0: public final class Names { aoqi@0: aoqi@0: private Names() { aoqi@0: } aoqi@0: aoqi@0: public static String getPortName(Port port) { aoqi@0: String javaPortName = aoqi@0: (String) port.getProperty(ModelProperties.PROPERTY_JAVA_PORT_NAME); aoqi@0: if (javaPortName != null) { aoqi@0: return javaPortName; aoqi@0: } else { aoqi@0: QName portName = aoqi@0: (QName) port.getProperty( aoqi@0: ModelProperties.PROPERTY_WSDL_PORT_NAME); aoqi@0: if (portName != null) { aoqi@0: return portName.getLocalPart(); aoqi@0: } else { aoqi@0: String name = stripQualifier(port.getJavaInterface().getName()); aoqi@0: return ClassNameInfo.replaceInnerClassSym(name); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: public static String stripQualifier(String name) { aoqi@0: return ClassNameInfo.getName(name); aoqi@0: } aoqi@0: aoqi@0: public static String getPackageName(String className) { aoqi@0: String packageName = ClassNameInfo.getQualifier(className); aoqi@0: return packageName != null ? packageName : ""; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: public static String customJavaTypeClassName(JavaInterface intf) { aoqi@0: return intf.getName(); aoqi@0: } aoqi@0: aoqi@0: public static String customExceptionClassName(Fault fault) { aoqi@0: return fault.getJavaException().getName(); aoqi@0: } aoqi@0: aoqi@0: public static String getExceptionClassMemberName(){ aoqi@0: return GeneratorConstants.FAULT_CLASS_MEMBER_NAME.getValue(); aoqi@0: } aoqi@0: aoqi@0: public static boolean isJavaReservedWord(String name) { aoqi@0: return RESERVED_WORDS.get(name) != null; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * See if its a java keyword name, if so then mangle the name aoqi@0: */ aoqi@0: public static @NotNull String getJavaReserverVarialbeName(@NotNull String name){ aoqi@0: return (RESERVED_WORDS.get(name) == null) ? name : RESERVED_WORDS.get(name); aoqi@0: } aoqi@0: aoqi@0: /* here we check on wether return values datatype is aoqi@0: boolean. If its boolean, instead of a get method aoqi@0: its set a is to comply with JavaBeans aoqi@0: Pattern spec */ aoqi@0: public static String getJavaMemberReadMethod(JavaStructureMember member) { aoqi@0: String return_value; aoqi@0: if (member.getType().getRealName().equals(ModelerConstants.BOOLEAN_CLASSNAME.getValue())) { aoqi@0: return_value = GeneratorConstants.IS.getValue() + StringUtils.capitalize(member.getName()); aoqi@0: } else { aoqi@0: return_value = GeneratorConstants.GET.getValue() + StringUtils.capitalize(member.getName()); aoqi@0: } aoqi@0: return (return_value); aoqi@0: } aoqi@0: aoqi@0: public static String getResponseName(String messageName) { aoqi@0: return messageName + GeneratorConstants.RESPONSE.getValue(); aoqi@0: } aoqi@0: aoqi@0: private static final Map RESERVED_WORDS = new HashMap(53); aoqi@0: aoqi@0: static { aoqi@0: RESERVED_WORDS.put("abstract", "_abstract"); aoqi@0: RESERVED_WORDS.put("assert", "_assert"); aoqi@0: RESERVED_WORDS.put("boolean", "_boolean"); aoqi@0: RESERVED_WORDS.put("break", "_break"); aoqi@0: RESERVED_WORDS.put("byte", "_byte"); aoqi@0: RESERVED_WORDS.put("case", "_case"); aoqi@0: RESERVED_WORDS.put("catch", "_catch"); aoqi@0: RESERVED_WORDS.put("char", "_char"); aoqi@0: RESERVED_WORDS.put("class", "_class"); aoqi@0: RESERVED_WORDS.put("const", "_const"); aoqi@0: RESERVED_WORDS.put("continue", "_continue"); aoqi@0: RESERVED_WORDS.put("default", "_default"); aoqi@0: RESERVED_WORDS.put("do", "_do"); aoqi@0: RESERVED_WORDS.put("double", "_double"); aoqi@0: RESERVED_WORDS.put("else", "_else"); aoqi@0: RESERVED_WORDS.put("extends", "_extends"); aoqi@0: RESERVED_WORDS.put("false", "_false"); aoqi@0: RESERVED_WORDS.put("final", "_final"); aoqi@0: RESERVED_WORDS.put("finally", "_finally"); aoqi@0: RESERVED_WORDS.put("float", "_float"); aoqi@0: RESERVED_WORDS.put("for", "_for"); aoqi@0: RESERVED_WORDS.put("goto", "_goto"); aoqi@0: RESERVED_WORDS.put("if", "_if"); aoqi@0: RESERVED_WORDS.put("implements", "_implements"); aoqi@0: RESERVED_WORDS.put("import", "_import"); aoqi@0: RESERVED_WORDS.put("instanceof", "_instanceof"); aoqi@0: RESERVED_WORDS.put("int", "_int"); aoqi@0: RESERVED_WORDS.put("interface", "_interface"); aoqi@0: RESERVED_WORDS.put("long", "_long"); aoqi@0: RESERVED_WORDS.put("native", "_native"); aoqi@0: RESERVED_WORDS.put("new", "_new"); aoqi@0: RESERVED_WORDS.put("null", "_null"); aoqi@0: RESERVED_WORDS.put("package", "_package"); aoqi@0: RESERVED_WORDS.put("private", "_private"); aoqi@0: RESERVED_WORDS.put("protected", "_protected"); aoqi@0: RESERVED_WORDS.put("public", "_public"); aoqi@0: RESERVED_WORDS.put("return", "_return"); aoqi@0: RESERVED_WORDS.put("short", "_short"); aoqi@0: RESERVED_WORDS.put("static", "_static"); aoqi@0: RESERVED_WORDS.put("strictfp", "_strictfp"); aoqi@0: RESERVED_WORDS.put("super", "_super"); aoqi@0: RESERVED_WORDS.put("switch", "_switch"); aoqi@0: RESERVED_WORDS.put("synchronized", "_synchronized"); aoqi@0: RESERVED_WORDS.put("this", "_this"); aoqi@0: RESERVED_WORDS.put("throw", "_throw"); aoqi@0: RESERVED_WORDS.put("throws", "_throws"); aoqi@0: RESERVED_WORDS.put("transient", "_transient"); aoqi@0: RESERVED_WORDS.put("true", "_true"); aoqi@0: RESERVED_WORDS.put("try", "_try"); aoqi@0: RESERVED_WORDS.put("void", "_void"); aoqi@0: RESERVED_WORDS.put("volatile", "_volatile"); aoqi@0: RESERVED_WORDS.put("while", "_while"); aoqi@0: RESERVED_WORDS.put("enum", "_enum"); aoqi@0: } aoqi@0: }