1 /* 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.xml.internal.ws.spi.db; 27 28 import java.lang.reflect.Type; 29 30 //TODO SOAPVersion WebServiceFeatureList 31 import com.sun.xml.internal.bind.util.Which; 32 33 //TODO Packet AbstractMessageImpl 34 import com.sun.xml.internal.bind.marshaller.SAX2DOMEx; 35 36 //TODO DOMHeader DOMMessage SAAJMessage StatefulInstanceResolver 37 import com.sun.xml.internal.bind.unmarshaller.DOMScanner; 38 39 //TODO ExceptionBean 40 import com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper; 41 42 //TODO AbstractWrapperBeanGenerator 43 import com.sun.xml.internal.bind.v2.model.annotation.AnnotationReader; 44 import com.sun.xml.internal.bind.v2.model.annotation.RuntimeInlineAnnotationReader; 45 import com.sun.xml.internal.bind.v2.model.nav.Navigator; 46 47 //TODO WSDLGenerator 48 import static com.sun.xml.internal.bind.v2.schemagen.Util.*; 49 50 import com.sun.xml.internal.bind.api.impl.NameConverter; 51 import com.sun.xml.internal.bind.v2.model.nav.Navigator; 52 53 import com.sun.istack.internal.NotNull; 54 import com.sun.istack.internal.Nullable; 55 /** 56 * BindingHelper 57 * 58 * @author shih-chang.chen@oracle.com 59 */ 60 public class BindingHelper { 61 /** 62 * Computes a Java identifier from a local name. 63 * 64 * <p> 65 * This method faithfully implements the name mangling rule as specified in the JAXB spec. 66 * 67 * <p> 68 * In JAXB, a collision with a Java reserved word (such as "return") never happens. 69 * Accordingly, this method may return an identifier that collides with reserved words. 70 * 71 * <p> 72 * Use {@code JJavaName.isJavaIdentifier(String)} to check for such collision. 73 * 74 * @return 75 * Typically, this method returns "nameLikeThis". 76 */ 77 public static @NotNull String mangleNameToVariableName(@NotNull String localName) { 78 return NameConverter.standard.toVariableName(localName); 79 } 80 81 /** 82 * Computes a Java class name from a local name. 83 * 84 * <p> 85 * This method faithfully implements the name mangling rule as specified in the JAXB spec. 86 * 87 * @return 88 * Typically, this method returns "NameLikeThis". 89 */ 90 public static @NotNull String mangleNameToClassName(@NotNull String localName) { 91 return NameConverter.standard.toClassName(localName); 92 } 93 94 /** 95 * Computes a Java class name from a local name. 96 * 97 * <p> 98 * This method faithfully implements the name mangling rule as specified in the JAXB spec. 99 * This method works like {@link #mangleNameToClassName(String)} except that it looks 100 * for "getClass" and returns something else. 101 * 102 * @return 103 * Typically, this method returns "NameLikeThis". 104 */ 105 public static @NotNull String mangleNameToPropertyName(@NotNull String localName) { 106 return NameConverter.standard.toPropertyName(localName); 107 } 108 109 /** 110 * Gets the parameterization of the given base type. 111 * 112 * <p> 113 * For example, given the following 114 * <pre>{@code 115 * interface Foo<T> extends List<List<T>> {} 116 * interface Bar extends Foo<String> {} 117 * }</pre> 118 * This method works like this: 119 * <pre>{@code 120 * getBaseClass( Bar, List ) = List<List<String> 121 * getBaseClass( Bar, Foo ) = Foo<String> 122 * getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>> 123 * getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger> 124 * }</pre> 125 * 126 * @param type 127 * The type that derives from {@code baseType} 128 * @param baseType 129 * The class whose parameterization we are interested in. 130 * @return 131 * The use of {@code baseType} in {@code type}. 132 * or null if the type is not assignable to the base type. 133 * @since 2.0 FCS 134 */ 135 public static @Nullable Type getBaseType(@NotNull Type type, @NotNull Class baseType) { 136 return Utils.REFLECTION_NAVIGATOR.getBaseClass(type,baseType); 137 } 138 139 public static <T> Class<T> erasure(Type t) { 140 return (Class<T>) Utils.REFLECTION_NAVIGATOR.erasure(t); 141 } 142 }