public class TypeUtils extends Object
{practicalxml}:type
attribute (the actual namespace is
defined in ConversionConstants
).
The values for this attribute take two forms: those representing simple
types defined by XML Schema, indicated by the prefix "xsd:", and those
representing arbitrary Java types, indicated by the prefix "java:". In
the latter case, the post-prefix portion contains the value returned by
Class.getName()
.
Modifier and Type | Field and Description |
---|---|
static String |
JAVA_TYPE_PREFIX
Prefix for
xsi:type values for elements holding Java
objects as serialized by BeanConverter . |
static String |
XSD_BASE64
Type value indicating Base64 encoding.
|
static String |
XSD_HEXBINARY
Type value indicating hex encoding.
|
static String |
XSD_TYPE_PREFIX
Prefix for
xsi:type values for elements holding primitive
values as defined by XML Schema. |
Constructor and Description |
---|
TypeUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
class2type(Class<?> klass)
Returns the
{practicalxml}:type value for the passed
Java class. |
static Class<?> |
getType(Element elem,
boolean throwIfFail)
Returns the Java class corresponding to the passed element's
{practicalxml}:type attribute. |
static String |
getTypeValue(Element elem)
Returns the value of the passed element's
{practicalxml}:type
attribute, null if the attribute is not set or contains
an empty string. |
static void |
setType(Element elem,
Class<?> klass)
Sets the
{practicalxml}:type attribute to a value
appropriate for the passed Java class. |
static void |
validateType(Element elem,
Class<?> klass)
Validates that the stated type of the element is assignable to the
passed class.
|
public static final String XSD_TYPE_PREFIX
xsi:type
values for elements holding primitive
values as defined by XML Schema. Note that we define a specific prefix
that may or may not correspond to a namespace defined in the instance
doc; we do not do namespace resolution on the value. Instance documents
produced by tools other than BeanConverter
must use the
same prefix.public static final String JAVA_TYPE_PREFIX
xsi:type
values for elements holding Java
objects as serialized by BeanConverter
. Again, this is
an explicit value, and does not correspond to any namespace.public static final String XSD_BASE64
public static final String XSD_HEXBINARY
public static String class2type(Class<?> klass)
{practicalxml}:type
value for the passed
Java class.public static void setType(Element elem, Class<?> klass)
{practicalxml}:type
attribute to a value
appropriate for the passed Java class. Does nothing if passed
null
public static String getTypeValue(Element elem)
{practicalxml}:type
attribute, null
if the attribute is not set or contains
an empty string.
Most callers should use getType(org.w3c.dom.Element, boolean)
rather than this method.
public static Class<?> getType(Element elem, boolean throwIfFail)
{practicalxml}:type
attribute. Optionally returns
null
or throws if unable to convert the attribute.ConversionException
- if unable to determine Java type for
any reason, when throwIfFail
is set.public static void validateType(Element elem, Class<?> klass)
ConversionException
- if unable to resolve element's type or if
an object of that type is not assignable to the passed class.