-
public interface SchemaCompiler
Schema-to-Java compiler.The caller can parse multiple schema documents, JAXB external binding files (or potentially WSDL and JSR-109.next mapping files in the future).
All the errors found during this process will be sent to the registered
ErrorListener
.Once all the documents are parsed, call the
bind()
method to get the compiledJAXBModel
object.Tips: namespace URI
->
package customizationThe caller can feed the following synthesized schema to achive the namespace URI
->
Java package customization:
Feed this synthesized schema document for each namespace URI you need to map.<schema targetNamespace="xml.namespace.uri" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" jaxb:version="3.0"> <annotation><appinfo> <jaxb:schemaBindings> <jaxb:package name="java.package.name"/> </jaxb:schemaBindings> </appinfo></annotation> </schema>
- Author:
- Kohsuke Kawaguchi ([email protected])
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description S2JJAXBModel
bind()
Obtains the compiled schema object model.void
forcePackageName(String packageName)
Forces all the JAXB-generated classes to go into the specific package.Options
getOptions()
Deprecated.This method is not really "deprecated" (in the sense of being removed from future versions), but the JAXB team is not committed to evolveOptions
class in the compatible fashion.ContentHandler
getParserHandler(String systemId)
Parses schemas or external bindings through SAX events by feeding events into SAXContentHandler
.void
parseSchema(String systemId, XMLStreamReader reader)
Parses a schema or an external binding file from the given source.void
parseSchema(String systemId, Element element)
Parses a schema or an external binding file from the specified DOM element.void
parseSchema(InputSource source)
Parses a schema or an external binding file from an external source.void
resetSchema()
Clears all the schema files parsed so far.void
setClassNameAllocator(ClassNameAllocator allocator)
Sets theClassNameAllocator
to be used for the binding operation.void
setDefaultPackageName(String packageName)
Sets the default Java package name into which the generated code will be placed.void
setEntityResolver(EntityResolver entityResolver)
void
setErrorListener(ErrorListener errorListener)
void
setTargetVersion(SpecVersion version)
Specifies the target spec version for this compilaion.
-
-
-
Method Detail
-
getParserHandler
ContentHandler getParserHandler(String systemId)
Parses schemas or external bindings through SAX events by feeding events into SAXContentHandler
.- Parameters:
systemId
- The system ID of the document to be read in.- See Also:
parseSchema(String, XMLStreamReader)
-
parseSchema
void parseSchema(InputSource source)
Parses a schema or an external binding file from an external source.- Parameters:
source
- Its system Id must be set to an absolute URI.
-
setTargetVersion
void setTargetVersion(SpecVersion version)
Specifies the target spec version for this compilaion.- Parameters:
version
- If null, XJC will generate the source code that takes advantage of the latest JAXB spec that it understands.- Since:
- 2.1 EA2
-
parseSchema
void parseSchema(String systemId, Element element)
Parses a schema or an external binding file from the specified DOM element.The given DOM element is treated as if it's the root of a virtual document.
XJC will not be able to print location information for errors found in this document, since DOM doesn't have them. For this reason, use of this method is strongly discouraged.
- Parameters:
systemId
- We need an absolute system ID that uniquely designates the virtual document. This should be different from the system ID of the document which contains this element.One way to do that is by adding a fragment identifier to the system ID of the document. For example, if the document is "foo.wsdl" and you are passing in its types section, you can use an unique identifier like "foo.wsdl#types"
-
parseSchema
void parseSchema(String systemId, XMLStreamReader reader) throws XMLStreamException
Parses a schema or an external binding file from the given source.A stream reader must be pointing at the element or at the start of the document. XML is parsed until the corresponding end tag, then the sub tree is processed as a schema document.
When this method returns successfully, the parser is at the next token of the end element.
- Parameters:
systemId
- The absolute system ID of the document that is being parsed. This information is necessary to avoid double-inclusion and etc. Note thatXMLStreamReader.getLocation()
only returns the system ID of the entity it is parsing, not necessarily the system ID of the document itself.- Throws:
XMLStreamException
- If an error happens while parsing a document. Note that not only the parser but also the XJC itself may throw this error (as a result of the additional validation for example.)
-
setErrorListener
void setErrorListener(ErrorListener errorListener)
-
setEntityResolver
void setEntityResolver(EntityResolver entityResolver)
-
setDefaultPackageName
void setDefaultPackageName(String packageName)
Sets the default Java package name into which the generated code will be placed.Customizations in the binding files/schemas will have precedence over this setting. Set to null to use the default package name computation algorithm as specified by the JAXB spec (which is the default behavior.)
Initially this parameter is set to null.
- Parameters:
packageName
- Java pckage name such as "org.foo.bar". Use "" to represent the root package, and null to defer to the default computation algorithm.- See Also:
forcePackageName(String)
-
forcePackageName
void forcePackageName(String packageName)
Forces all the JAXB-generated classes to go into the specific package.This setting takes precedence over the
setDefaultPackageName(String)
or any of the customization found in the JAXB binding files. This method is designed to implement the semantics of the command-line '-p' option.This somewhat ugly semantics actually have a long history now and too late to change.
- See Also:
setDefaultPackageName(String)
-
setClassNameAllocator
void setClassNameAllocator(ClassNameAllocator allocator)
Sets theClassNameAllocator
to be used for the binding operation.This mechanism would allow the caller to participate in the binding operation.
- See Also:
ClassNameAllocator
-
resetSchema
void resetSchema()
Clears all the schema files parsed so far.- Since:
- 2.1.1
-
bind
S2JJAXBModel bind()
Obtains the compiled schema object model. Once this method is called, no other method should be invoked on the .- Returns:
- null if the compilation fails. The errors should have been delivered to the registered error handler in such a case.
-
getOptions
@Deprecated @NotNull Options getOptions()
Deprecated.This method is not really "deprecated" (in the sense of being removed from future versions), but the JAXB team is not committed to evolveOptions
class in the compatible fashion. So please don't use this method unless you know what you're doing.Allows the calling code to tweak more schema compilation details.The caller can use this method to obtain an
Options
instance, then tweak settings on it. The updated settings will be used when thebind()
method is invoked.The returned
Options
object is useful for example to specify command-line arguments.- Since:
- 2.0.2
-
-