The instance can be specified explicitly, in which case it is generated at compile time. It can also be specified implicitly using a ResourceBundle key. The actual instance is then at run time by looking up the (possibly localized) pattern in the ResourceBundle and instantiating the Formatter.
Configuration examples:
<!-- Explicit format specificaton of a SimpleDateFormat instance --> <element name="staticDate" type="jm:rbFormatted"> <xs:annotation> <xs:appinfo> <jm:resourceBundeFormatted base="xs:dateTime" type="date" pattern="yyyy-MM-dd HH:mm:ss"/> </xs:appinfo> </xs:annotation> </element> <!-- Implicit format specification of a DecimalFormat instance --> <element name="localizedDecimalNumber" type="jm:rbFormatted> <xs:annotation> <xs:appinfo> <jm:rbFormatted base="xs:double" type="decimal" key="localized.decimal.number.pattern"/> </xs:appinfo> </xs:annotation> </element>The jm:rbFormatted child of xs:appinfo supports the following attributes:
Name | Description | ||||||
---|---|---|---|---|---|---|---|
base | Specifies the base type. Defaults to xs:string. | ||||||
defaultPattern | Used in conjunction with the key attribute: If no Pattern is found in the ResourceBundle, then the specified pattern is used to create a Formatter. | ||||||
formatClass | Specificies the subclass of java.text.Format being used. This class must support a static method getInstance(String pattern). An alternative is using the type attribute, which provides shortcuts. The formatClass and type attributes are mutually exclusive. | ||||||
key | Specifying this attribute implies the generation of the Formatter at run time. It is mutually exclusive with the attributes pattern and newFormatter. To create a Formatter, the Marshallers or Unmarshallers method getResourceBundle() will be invoked. If no ResourceBundle is returned or if the key is not defined in the ResourceBundle, then a SAXException is thrown. You may use the attribute defaultPattern to prevent the exception.. | ||||||
newFormatter | If you want to specify a different way how a Formatter should be obtained, then you may use this method. This attribute is mutually exclusive with the attributes pattern and key. | ||||||
pattern | Specifying this attribute implies the generation of the Formatter at compile time, hence it is mutually exclusive with the attributes key and newFormatter. The Formatter will typically be generated by invoking formatClass.getInstance(pattern). | ||||||
type | Specificies the subclass of java.text.Format being used. Valid
values are:
|
All attributes may also be as atomic child elements. This is particularly useful in the case of the newFormatter attribute.
For further details see
The types jm:blob
and jm:clob
are quite
similar to xs:base64Binary
and xs:string
,
respectively. The only difference is that they are handled differently
when being written to an SQL database:
Schema type | Java type | Writing | Reading |
---|---|---|---|
xs:base64Binary | byte[] | PreparedStatement.setBytes(int,byte[]) |
ResultSet.getBytes(int) |
jm:blob | byte[] | PreparedStatement.setBinaryStream(int,InputStream,int) |
ResultSet.getBinaryStream(int) |
xs:string | String | PreparedStatement.setString(int,String) |
ResultSet.getString(int) |
jm:blob | String | PreparedStatement.setCharacterStream(int,Reader,int) |
ResultSet.getCharacterStream(int) |
For more details, see the JavaDocs of BlobType and ClobType.
The type xs:any
is treated as an element with arbitrary
content. No classes are generated for such elements, but the default
types JMAnyElement
and JMContentHandler
are used as elements and SAX content handlers, respectively.
JaxMe includes a number of builtin types. However, it is possible to extend the list with your own, predefined types. For example:
<xs:schema xmlns:jm="http://ispsoft.de/namespaces/jaxme/schema" xmlns:my="http://company.com/namespaces/my"> <xs:annotation> <xs:appinfo> <jm:declare type="my:clobType" class="de.ispsoft.jaxme.generator.types.OraClobType$URLEncoded"/> <jm:declare type="my:blobType" class="de.ispsoft.jaxme.generator.types.OraBlobType"/> </xs:appinfo> </xs:annotation> </xs:schema>
The example would declare that the type named clobType in the namespace http://company.com/namespaces/my is assigned to the class de.ispsoft.jaxme.generator.types.OraClobType$URLEncoded. Likewise, the type blobType in the same namespace is assigned to de.ispsoft.jaxme.generator.types.OraClobType.