com.sun.tools.xjc.api.impl.s2j
Class SchemaCompilerImpl

java.lang.Object
  extended by com.sun.tools.xjc.ErrorReceiver
      extended by com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl
All Implemented Interfaces:
SchemaCompiler, ErrorListener, org.xml.sax.ErrorHandler

public final class SchemaCompilerImpl
extends ErrorReceiver
implements SchemaCompiler

SchemaCompiler implementation. This class builds a DOMForest until the bind() method, then this method does the rest of the hard work.

See Also:
ModelLoader

Field Summary
protected  DOMForest forest
           
protected  Options opts
           
 
Constructor Summary
SchemaCompilerImpl()
           
 
Method Summary
 com.sun.tools.xjc.api.impl.s2j.JAXBModelImpl bind()
          Obtains the compiled schema object model.
 void error(org.xml.sax.SAXParseException exception)
           
 void fatalError(org.xml.sax.SAXParseException exception)
           
 void forcePackageName(java.lang.String packageName)
          Forces all the JAXB-generated classes to go into the specific package.
 Options getOptions()
          Allows the calling code to tweak more schema compilation details.
 org.xml.sax.ContentHandler getParserHandler(java.lang.String systemId)
          Parses schemas or external bindings through SAX events by feeding events into SAX ContentHandler.
 void info(org.xml.sax.SAXParseException exception)
          Reports verbose messages to users.
 void parseSchema(org.xml.sax.InputSource source)
          Parses a schema or an external binding file from an external source.
 void parseSchema(java.lang.String systemId, org.w3c.dom.Element element)
          Parses a schema or an external binding file from the specified DOM element.
 void parseSchema(java.lang.String systemId, javax.xml.stream.XMLStreamReader reader)
          Parses a schema or an external binding file from the given source.
 void resetSchema()
          Clears all the schema files parsed so far.
 void setClassNameAllocator(ClassNameAllocator allocator)
          Sets the ClassNameAllocator to be used for the binding operation.
 void setDefaultPackageName(java.lang.String packageName)
          Sets the default Java package name into which the generated code will be placed.
 void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
           
 void setErrorListener(ErrorListener errorListener)
           
 void setTargetVersion(SpecVersion version)
          Specifies the target spec version for this compilaion.
 void warning(org.xml.sax.SAXParseException exception)
           
 
Methods inherited from class com.sun.tools.xjc.ErrorReceiver
debug, error, error, error, error, getLocationString, pollAbort, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

opts

protected final Options opts

forest

@NotNull
protected DOMForest forest
Constructor Detail

SchemaCompilerImpl

public SchemaCompilerImpl()
Method Detail

getOptions

@NotNull
public Options getOptions()
Description copied from interface: SchemaCompiler
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 the SchemaCompiler.bind() method is invoked.

The returned Options object is useful for example to specify command-line arguments.

Specified by:
getOptions in interface SchemaCompiler

getParserHandler

public org.xml.sax.ContentHandler getParserHandler(java.lang.String systemId)
Description copied from interface: SchemaCompiler
Parses schemas or external bindings through SAX events by feeding events into SAX ContentHandler.

Specified by:
getParserHandler in interface SchemaCompiler
Parameters:
systemId - The system ID of the document to be read in.
See Also:
SchemaCompiler.parseSchema(String, XMLStreamReader)

parseSchema

public void parseSchema(java.lang.String systemId,
                        org.w3c.dom.Element element)
Description copied from interface: SchemaCompiler
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.

Specified by:
parseSchema in interface SchemaCompiler
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

public void parseSchema(org.xml.sax.InputSource source)
Description copied from interface: SchemaCompiler
Parses a schema or an external binding file from an external source.

Specified by:
parseSchema in interface SchemaCompiler
Parameters:
source - Its system Id must be set to an absolute URI.

setTargetVersion

public void setTargetVersion(SpecVersion version)
Description copied from interface: SchemaCompiler
Specifies the target spec version for this compilaion.

Specified by:
setTargetVersion in interface SchemaCompiler
Parameters:
version - If null, XJC will generate the source code that takes advantage of the latest JAXB spec that it understands.

parseSchema

public void parseSchema(java.lang.String systemId,
                        javax.xml.stream.XMLStreamReader reader)
                 throws javax.xml.stream.XMLStreamException
Description copied from interface: SchemaCompiler
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.

Specified by:
parseSchema in interface SchemaCompiler
Parameters:
systemId - The absolute system ID of the document that is being parsed. This information is necessary to avoid double-inclusion and etc. Note that XMLStreamReader.getLocation() only returns the system ID of the entity it is parsing, not necessarily the system ID of the document itself.
Throws:
javax.xml.stream.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.)

setEntityResolver

public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
Specified by:
setEntityResolver in interface SchemaCompiler

setDefaultPackageName

public void setDefaultPackageName(java.lang.String packageName)
Description copied from interface: SchemaCompiler
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.

Specified by:
setDefaultPackageName in interface SchemaCompiler
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:
SchemaCompiler.forcePackageName(String)

forcePackageName

public void forcePackageName(java.lang.String packageName)
Description copied from interface: SchemaCompiler
Forces all the JAXB-generated classes to go into the specific package.

This setting takes precedence over the SchemaCompiler.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.

Specified by:
forcePackageName in interface SchemaCompiler
See Also:
SchemaCompiler.setDefaultPackageName(String)

setClassNameAllocator

public void setClassNameAllocator(ClassNameAllocator allocator)
Description copied from interface: SchemaCompiler
Sets the ClassNameAllocator to be used for the binding operation.

This mechanism would allow the caller to participate in the binding operation.

Specified by:
setClassNameAllocator in interface SchemaCompiler
See Also:
ClassNameAllocator

resetSchema

public void resetSchema()
Description copied from interface: SchemaCompiler
Clears all the schema files parsed so far.

Specified by:
resetSchema in interface SchemaCompiler

bind

public com.sun.tools.xjc.api.impl.s2j.JAXBModelImpl bind()
Description copied from interface: SchemaCompiler
Obtains the compiled schema object model. Once this method is called, no other method should be invoked on the SchemaCompiler.

Specified by:
bind in interface SchemaCompiler
Returns:
null if the compilation fails. The errors should have been delivered to the registered error handler in such a case.

setErrorListener

public void setErrorListener(ErrorListener errorListener)
Specified by:
setErrorListener in interface SchemaCompiler

info

public void info(org.xml.sax.SAXParseException exception)
Description copied from class: ErrorReceiver
Reports verbose messages to users. This method can be used to report additional non-essential messages. The implementation usually discards them unless some specific debug option is turned on.

Specified by:
info in interface ErrorListener
Specified by:
info in class ErrorReceiver

warning

public void warning(org.xml.sax.SAXParseException exception)
Specified by:
warning in interface ErrorListener
Specified by:
warning in interface org.xml.sax.ErrorHandler
Specified by:
warning in class ErrorReceiver

error

public void error(org.xml.sax.SAXParseException exception)
Specified by:
error in interface ErrorListener
Specified by:
error in interface org.xml.sax.ErrorHandler
Specified by:
error in class ErrorReceiver

fatalError

public void fatalError(org.xml.sax.SAXParseException exception)
Specified by:
fatalError in interface ErrorListener
Specified by:
fatalError in interface org.xml.sax.ErrorHandler
Specified by:
fatalError in class ErrorReceiver