com.legstar.coxb.util
Class NameUtil

java.lang.Object
  extended by com.legstar.coxb.util.NameUtil

public final class NameUtil
extends Object

Utilities that are common to the binding API and dependents. Part of this code is more or less a clone of Sun's com.sun.xml.bind.api.impl.NameUtil. It's just that dragging the entire jaxb-impl as a dependency just to get the naming right is overkill. The jaxb-impl dependency is a real pain since it is now included in JRE and brings in all forms of version conflicts.


Method Summary
static String capitalize(String s)
          Capitalizes the first character of the specified string, and de-capitalize the rest of characters.
static
<T> T
cast(Object x)
          This utility method is used to suppress the need for @SuppressWarnings when we cast objects to List < ?
static boolean isJavaIdentifier(String s)
          Checks if a given string is usable as a Java identifier.
protected static boolean isLower(char c)
          Determine if character is lowercase.
static boolean isPunct(char c)
          Determine if character is punctuation.
static String lowerFirstChar(String str)
          Return the first character as a lower case character.
static String toClassName(String s)
          Returns a JAXB compatible class name.
static String toMixedCaseName(List<String> ss, boolean startUpper)
          Concatenates the pieces into a mixed case name.
static String toPackageName(String uri)
          .
static String toVariableName(String s)
          Returns a JAXB compatible variable name.
static List<String> toWordList(String s)
          Tokenizes a string into words and capitalizes the first character of each word.
static String upperFirstChar(String str)
          Return the first character as a upper case character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

cast

public static <T> T cast(Object x)
This utility method is used to suppress the need for @SuppressWarnings when we cast objects to List < ? >.

Type Parameters:
T - the list type
Parameters:
x - the object to cast
Returns:
a list object

isPunct

public static boolean isPunct(char c)
Determine if character is punctuation.

Parameters:
c - the character
Returns:
true if punctuation

isLower

protected static boolean isLower(char c)
Determine if character is lowercase.

Parameters:
c - the character to test
Returns:
true if lower case

toVariableName

public static String toVariableName(String s)
Returns a JAXB compatible variable name.

Parameters:
s - the original string
Returns:
a java variable name

toClassName

public static String toClassName(String s)
Returns a JAXB compatible class name.

Parameters:
s - the original string
Returns:
a java class name

toWordList

public static List<String> toWordList(String s)
Tokenizes a string into words and capitalizes the first character of each word.

Parameters:
s - the original word
Returns:
an array of subwords

This method uses a change in character type as a splitter of two words. For example, "abc100ghi" will be splitted into {"Abc", "100","Ghi"}.


capitalize

public static String capitalize(String s)
Capitalizes the first character of the specified string, and de-capitalize the rest of characters.

Parameters:
s - the original word
Returns:
the capitalized word

toMixedCaseName

public static String toMixedCaseName(List<String> ss,
                                     boolean startUpper)
Concatenates the pieces into a mixed case name.

Parameters:
ss - the array of strings to concatenate
startUpper - leaves casing unchanged of true, otherwise lowercases the first sequence
Returns:
the combined mixed cas word

lowerFirstChar

public static String lowerFirstChar(String str)
Return the first character as a lower case character.

Parameters:
str - the string from which character must be extracted
Returns:
first character lower cased

upperFirstChar

public static String upperFirstChar(String str)
Return the first character as a upper case character.

Parameters:
str - the string from which character must be extracted
Returns:
first character upper cased

isJavaIdentifier

public static boolean isJavaIdentifier(String s)
Checks if a given string is usable as a Java identifier.

Parameters:
s - a character string
Returns:
true if valid java identifier

toPackageName

public static String toPackageName(String uri)
. Computes a Java package name from a namespace URI, as specified in the spec.

Parameters:
uri - the target namespace
Returns:
null if it fails to derive a package name.


Copyright © 2015 LegSem. All Rights Reserved.