public class TransformSchema extends Object
Data holder for schema transformation operations, to permit customization of the
schema namespace prefix and file name of generated schema. As the schemagen
tool has no mechanics to control namespace prefix and file name of generated schema,
the Jaxb2-Maven-plugin must supply a post-processing step to work around this situation.
Each TransformSchema
object holds data pertaining to changes for one namespace
URI - either namespace prefix used within the generated XSD or resulting filename for
the schema definition.
<foo:bar/>
, the namespace prefix
is "foo" and the element name is "bar"). The Schemagen tool by default only generates namespace
prefixes on the form "ns1", "ns2" etc., which means that the generated schema will contain elements
on the form <xs:extension base="ns1:nazgulEntity">
.
Use a toPrefix
element to change the namespace prefix of a particular XML URI to
simplify understanding the schema.toFile
element to change the filename for a
particular XML URI. Changing the file names frequently improves overview and usability of the generated schema
files.The URI element is mandatory for each TransformSchema element. The first example illustrates how to use the TransformSchema element to change the prefix and file name of 3 XML URIs. This is the recommended use of a TransformSchema - change both prefix and filename to something meaningful for each URI:
<transformSchemas> <transformSchema> <uri>http://some/namespace</uri> <toPrefix>some</toPrefix> <toFile>some_schema.xsd</toFile> </transformSchema> <transformSchema> <uri>http://another/namespace</uri> <toPrefix>another</toPrefix> <toFile>another_schema.xsd</toFile> </transformSchema> <transformSchema> <uri>http://yet/another/namespace</uri> <toPrefix>yetAnother</toPrefix> <toFile>yet_another_schema.xsd</toFile> </transformSchema> </transformSchemas>
The URI element is mandatory for each TransformSchema element, along with at least one of the other two elements in the TransformSchema. This implies that partial configuration for TransformSchema can be used, although this is not recommended since the readability and usability of the automatically generated namespace prefixes and file names are poor. The second example illustrates how to use the TransformSchema element to change either prefix or file name for 2 XML URIs:
<transformSchemas> <transformSchema> <uri>http://another/namespace</uri> <toPrefix>another</toPrefix> </transformSchema> <transformSchema> <uri>http://yet/another/namespace</uri> <toFile>yet_another_schema.xsd</toFile> </transformSchema> </transformSchemas>
Modifier and Type | Field and Description |
---|---|
static String |
EMPTY_NAMESPACE
The empty XML Namespace.
|
Constructor and Description |
---|
TransformSchema()
Default constructor.
|
TransformSchema(String uri,
String toPrefix,
String toFile)
Compound constructor, creating a TransformSchema instruction wrapping the supplied data.
|
Modifier and Type | Method and Description |
---|---|
String |
getToFile() |
String |
getToPrefix() |
String |
getUri() |
void |
setToFile(String toFile)
Assigns the the name of the target file if/when renamed.
|
void |
setToPrefix(String toPrefix)
Assigns the namespace prefix of this Schema.
|
void |
setUri(String uri)
Assigns the URI of this Schema, such as
http://www.jguru.se/some/namespace . |
String |
toString() |
public static final String EMPTY_NAMESPACE
public TransformSchema()
public TransformSchema(String uri, String toPrefix, String toFile)
uri
- The URI of this Schema, such as
http://www.jguru.se/some/namespace
. Cannot be null or empty.toPrefix
- The new namespace prefix for this Schema. Optional.toFile
- The new name of the generated schema file.public String getUri()
http://www.jguru.se/some/namespace
.
The namespace URI is mapped to its prefix in the schema element, i.e:
xmlns:xs="http://www.w3.org/2001/XMLSchema"
or
xmlns:foo="http://www.acme.com/xml/schema/foo"
.public String getToPrefix()
<foo:bar/>
, the prefix is "foo" (and the element name is "bar").public String getToFile()
public void setUri(String uri)
http://www.jguru.se/some/namespace
.
The namespace URI is mapped to its prefix in the schema element, i.e:
xmlns:xs="http://www.w3.org/2001/XMLSchema"
or
xmlns:foo="http://www.acme.com/xml/schema/foo"
.uri
- The non-empty uri of this Schema.public void setToPrefix(String toPrefix)
<foo:bar/>
, the prefix is "foo"
(and the element name is "bar").toPrefix
- The non-empty prefix to assign.public void setToFile(String toFile)
toFile
- The non-empty filename to assign.Copyright © 2005–2015 MojoHaus. All rights reserved.