Class TransformSchema
- java.lang.Object
-
- org.codehaus.mojo.jaxb2.schemageneration.postprocessing.schemaenhancement.TransformSchema
-
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.- Namespace prefix. Each XML element within a namespace uses the supplied
prefix. (As a reference, in the XML element
<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 atoPrefix
element to change the namespace prefix of a particular XML URI to simplify understanding the schema. - Filename. By default, the Schemagen tool creates files called "schema1.xsd",
"schema2.xsd" etc. Since the XSD imports one another, simply changing the filename will frequently
break the schema structure - you will need to change all import statements in all generated XSD files
to match the new file names. The Jaxb2 Maven plugin can do all this housekeeping automatically, if you
create a transformSchema element containing a
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.
Example TransformSchemas
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>
- Since:
- 1.4
- Author:
- Lennart Jörelid
- Namespace prefix. Each XML element within a namespace uses the supplied
prefix. (As a reference, in the XML element
-
-
Field Summary
Fields Modifier and Type Field Description static String
EMPTY_NAMESPACE
The empty XML Namespace.
-
Constructor Summary
Constructors Constructor Description TransformSchema()
Default constructor.TransformSchema(String uri, String toPrefix, String toFile)
Compound constructor, creating a TransformSchema instruction wrapping the supplied data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 ashttp://www.jguru.se/some/namespace
.String
toString()
-
-
-
Field Detail
-
EMPTY_NAMESPACE
public static final String EMPTY_NAMESPACE
The empty XML Namespace.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TransformSchema
public TransformSchema()
Default constructor.
-
TransformSchema
public TransformSchema(String uri, String toPrefix, String toFile)
Compound constructor, creating a TransformSchema instruction wrapping the supplied data.- Parameters:
uri
- The URI of this Schema, such ashttp://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.
-
-
Method Detail
-
getUri
public String getUri()
- Returns:
- The URI of this Schema, such as
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"
orxmlns:foo="http://www.acme.com/xml/schema/foo"
.
-
getToPrefix
public String getToPrefix()
- Returns:
- The namespace prefix of this Schema. Each schema element is related to its namespace using the prefix.
For an XML element
<foo:bar/>
, the prefix is "foo" (and the element name is "bar").
-
getToFile
public String getToFile()
- Returns:
- the name of the target file if/when renamed.
-
setUri
public void setUri(String uri)
Assigns the URI of this Schema, such ashttp://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"
orxmlns:foo="http://www.acme.com/xml/schema/foo"
.- Parameters:
uri
- The non-empty uri of this Schema.
-
setToPrefix
public void setToPrefix(String toPrefix)
Assigns the namespace prefix of this Schema. Each schema element is related to its namespace using the prefix. For an XML element<foo:bar/>
, the prefix is "foo" (and the element name is "bar").- Parameters:
toPrefix
- The non-empty prefix to assign.
-
setToFile
public void setToFile(String toFile)
Assigns the the name of the target file if/when renamed.- Parameters:
toFile
- The non-empty filename to assign.
-
-