|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.enhydra.zeus.util.NamingUtils
NamingUtils
is a Zeus utility class that provides methods
which deal with the naming issues involved in data binding. Specifically,
this class will deal with deriving Java class names, deriving Java
variable names, deriving XML element names, and validating legal Java
identifiers.
Field Summary | |
static java.lang.String |
DEFAULT_MAPPING
The default alternative representation for illegal characters. |
static java.lang.String |
XML_PREFIX
Prefix to append to names that clash with Java reserved words. |
Method Summary | |
static java.lang.String |
getCharMapping(java.lang.Character key)
Returns the value that the given key is mapped to. |
static java.lang.String |
getJavaClassName(java.lang.String xmlName)
Returns the conventional Java class name from an XML name. |
static java.lang.String |
getJavaCollectionVariableName(java.lang.String className)
Returns the Java variable name from a Java class name assuming that the variable will be a collection based variable (i.e. |
static java.lang.String |
getJavaName(java.lang.String xmlName)
Returns a conventional Java name from an XML name. |
static java.lang.String |
getJavaType(java.lang.String xmlType)
This will handle conversion from an XML type to a Java type. |
static java.lang.String |
getJavaVariableName(java.lang.String xmlName)
Returns the conventional Java variable name from an XML name. |
static java.lang.String |
getXMLElementNameFromAccessor(java.lang.String accessor)
Returns the XML name from a typical accessor method. |
static boolean |
isLegalJavaClassName(java.lang.String className)
This will indicate whether the supplied name is a legal Java class name. |
static boolean |
isLegalJavaPackageName(java.lang.String packageName)
This will indicate whether the supplied name is a legal Java package name. |
static java.lang.String |
removePackage(java.lang.String className)
This will take a fully qualified Java class, and return just the name of the class, without any package qualifier. |
static void |
setCharMapping(java.lang.Character key,
java.lang.String value)
Maps the given key to the given value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String XML_PREFIX
public static final java.lang.String DEFAULT_MAPPING
Method Detail |
public static boolean isLegalJavaClassName(java.lang.String className)
This will indicate whether the supplied name is a legal Java class name.
className
- the Java class name to checkboolean
- whether the supplied class is a legal
Java class name.public static boolean isLegalJavaPackageName(java.lang.String packageName)
This will indicate whether the supplied name is a legal Java package name.
packageName
- the Java class name to checkboolean
- whether the supplied package is a legal
Java package name.public static java.lang.String getCharMapping(java.lang.Character key)
Returns the value that the given key is mapped to. This value will replace any occurence of the key when a name contains illegal characters for a Java identifier.
key
- the key mapped to the value to return.String
- the value the given key is mapped to.public static void setCharMapping(java.lang.Character key, java.lang.String value)
Maps the given key to the given value. This value will replace any occurence of the key when a name contains illegal characters for a Java identifier.
key
- the key to map the given value to.value
- the value to map the given key to.public static java.lang.String getJavaName(java.lang.String xmlName)
Returns a conventional Java name from an XML name. Any illegal characters are replaced. Collision with reserved words is not checked, as this is not used directly in class generation.
For example, calling getJavaName("my-element")
would
return "myElement" as the Java class name.
xmlName
- the XML name to convert to a Java name.String
- the converted Java name.public static java.lang.String getJavaVariableName(java.lang.String xmlName)
Returns the conventional Java variable name from an XML name. The
initial character is uncapitalized, and any illegal characters are
replaced. If there is a collision with a Java reserved word, the name
is prefixed with
.
XML_PREFIX
For example, calling getJavaVariableName("XmlName")
would return "xmlName" as the Java variable name.
xmlName
- the XML name to convert to a variable name.String
- the converted Java variable name.public static java.lang.String getJavaCollectionVariableName(java.lang.String className)
Returns the Java variable name from a Java class name assuming that the variable will be a collection based variable (i.e. ending with "List" as in "myVariableList"). The initial character is uncapitalized, and any illegal characters are replaced. There is no check for a collision with a Java reserved word because the assumption is that the variable has some word appended to it that identifies the fact that the variable denotes a collection.
For example, calling
getJavaCollectionVariableName("MyClass")
would return
"myClass" as the Java variable name.
className
- the class name to convert to a collection based
variable name.String
- the converted Java variable name.public static java.lang.String getJavaClassName(java.lang.String xmlName)
Returns the conventional Java class name from an XML name. The initial character is capitalized, and any illegal characters are replaced. There is no check for a collision with a Java reserved word because all Java reserved words have their initial character lower case.
For example, calling getJavaClassName("my-element")
would
return "MyElement" as the Java class name.
xmlName
- the XML name to convert to a Java class name.String
- the converted Java name.public static java.lang.String getJavaType(java.lang.String xmlType)
This will handle conversion from an XML type to a Java type. It first attempts to perform an XML Schema type to Java type conversion. For example, if the XML type is "string", it would convert this to the Java type "String". If that is unsuccessful, it returns the type unchanged, assuming that it is a proper Java class name.
xmlType
- the XML type to convert to a Java type.String
- the converted Java type.public static java.lang.String getXMLElementNameFromAccessor(java.lang.String accessor)
Returns the XML name from a typical accessor method. The naming convention for such a method is "get<variable-name>". The first three characters are discarded, and the initial character is uncapitalized.
For example, calling
getXMLElementNameFromAccessor("getMyVariable")
would
return "myVariable" as the XML name. This method would also work
with typical mutator methods.
accessor
- the name of the accessor method to derive the XML name
from.String
- the converted XML name.public static java.lang.String removePackage(java.lang.String className)
This will take a fully qualified Java class, and return just the name
of the class, without any package qualifier. For example, invoking
removePackage("java.util.List");
would return
"List".
className
- the Java class name to remove the package from.String
- the Java class, without package.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |