< prev index next >

src/java.xml.ws/share/classes/com/sun/xml/internal/ws/spi/db/BindingHelper.java

Print this page




  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 <tt>JJavaName.isJavaIdentifier(String)</tt> 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     }


  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><xmp>
 115      * interface Foo<T> extends List<List<T>> {}
 116      * interface Bar extends Foo<String> {}
 117      * </xmp></pre>
 118      * This method works like this:
 119      * <pre><xmp>
 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      * </xmp></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 }


  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     }


  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 }
< prev index next >