com.sun.tools.ws.processor.generator.Names Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaxws-tools Show documentation
Show all versions of jaxws-tools Show documentation
Open source Reference Implementation of JSR-224: Java API for XML Web Services
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.tools.ws.processor.generator;
import com.sun.tools.ws.processor.model.Fault;
import com.sun.tools.ws.processor.model.ModelProperties;
import com.sun.tools.ws.processor.model.Port;
import com.sun.tools.ws.processor.model.Service;
import com.sun.tools.ws.processor.model.java.JavaInterface;
import com.sun.tools.ws.processor.model.java.JavaStructureMember;
import com.sun.tools.ws.util.ClassNameInfo;
import com.sun.xml.ws.util.StringUtils;
import com.sun.istack.Nullable;
import com.sun.istack.NotNull;
import javax.xml.namespace.QName;
import java.util.HashMap;
import java.util.Map;
/**
* Names provides utility methods used by other wscompile classes
* for dealing with identifiers.
*
* @author WS Development Team
*/
public class Names implements GeneratorConstants{
public static String getPortName(Port port) {
String javaPortName =
(String) port.getProperty(ModelProperties.PROPERTY_JAVA_PORT_NAME);
if (javaPortName != null) {
return javaPortName;
} else {
QName portName =
(QName) port.getProperty(
ModelProperties.PROPERTY_WSDL_PORT_NAME);
if (portName != null) {
return portName.getLocalPart();
} else {
String name = stripQualifier(port.getJavaInterface().getName());
return ClassNameInfo.replaceInnerClassSym(name);
}
}
}
public static String stripQualifier(String name) {
return ClassNameInfo.getName(name);
}
public static String getPackageName(String className) {
String packageName = ClassNameInfo.getQualifier(className);
return packageName != null ? packageName : "";
}
public static String customJavaTypeClassName(JavaInterface intf) {
return intf.getName();
}
public static String customExceptionClassName(Fault fault) {
return fault.getJavaException().getName();
}
public static String getExceptionClassMemberName(){
return FAULT_CLASS_MEMBER_NAME;
}
public static boolean isJavaReservedWord(String name) {
return reservedWords.get(name) != null;
}
/**
* See if its a java keyword name, if so then mangle the name
*/
public static @NotNull String getJavaReserverVarialbeName(@NotNull String name){
return (reservedWords.get(name) == null)?name:reservedWords.get(name);
}
/* here we check on wether return values datatype is
boolean. If its boolean, instead of a get method
its set a is to comply with JavaBeans
Pattern spec */
public static String getJavaMemberReadMethod(JavaStructureMember member) {
String return_value;
if (member.getType().getRealName().equals("boolean")) {
return_value = IS + StringUtils.capitalize(member.getName());
} else {
return_value = GET + StringUtils.capitalize(member.getName());
}
return (return_value);
}
public static String getResponseName(String messageName) {
return messageName + RESPONSE;
}
private static final Map reservedWords;
static {
reservedWords = new HashMap();
reservedWords.put("abstract", "_abstract");
reservedWords.put("assert", "_assert");
reservedWords.put("boolean", "_boolean");
reservedWords.put("break", "_break");
reservedWords.put("byte", "_byte");
reservedWords.put("case", "_case");
reservedWords.put("catch", "_catch");
reservedWords.put("char", "_char");
reservedWords.put("class", "_class");
reservedWords.put("const", "_const");
reservedWords.put("continue", "_continue");
reservedWords.put("default", "_default");
reservedWords.put("do", "_do");
reservedWords.put("double", "_double");
reservedWords.put("else", "_else");
reservedWords.put("extends", "_extends");
reservedWords.put("false", "_false");
reservedWords.put("final", "_final");
reservedWords.put("finally", "_finally");
reservedWords.put("float", "_float");
reservedWords.put("for", "_for");
reservedWords.put("goto", "_goto");
reservedWords.put("if", "_if");
reservedWords.put("implements", "_implements");
reservedWords.put("import", "_import");
reservedWords.put("instanceof", "_instanceof");
reservedWords.put("int", "_int");
reservedWords.put("interface", "_interface");
reservedWords.put("long", "_long");
reservedWords.put("native", "_native");
reservedWords.put("new", "_new");
reservedWords.put("null", "_null");
reservedWords.put("package", "_package");
reservedWords.put("private", "_private");
reservedWords.put("protected", "_protected");
reservedWords.put("public", "_public");
reservedWords.put("return", "_return");
reservedWords.put("short", "_short");
reservedWords.put("static", "_static");
reservedWords.put("strictfp", "_strictfp");
reservedWords.put("super", "_super");
reservedWords.put("switch", "_switch");
reservedWords.put("synchronized", "_synchronized");
reservedWords.put("this", "_this");
reservedWords.put("throw", "_throw");
reservedWords.put("throws", "_throws");
reservedWords.put("transient", "_transient");
reservedWords.put("true", "_true");
reservedWords.put("try", "_try");
reservedWords.put("void", "_void");
reservedWords.put("volatile", "_volatile");
reservedWords.put("while", "_while");
reservedWords.put("enum", "_enum");
}
}