Java Doc for SchemaFactory.java in  » 6.0-JDK-Core » xml » javax » xml » validation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » xml » javax.xml.validation 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javax.xml.validation.SchemaFactory

SchemaFactory
abstract public class SchemaFactory (Code)
Factory that creates Schema objects. Entry-point to the validation API.

SchemaFactory is a schema compiler. It reads external representations of schemas and prepares them for validation.

The SchemaFactory class is not thread-safe. In other words, it is the application's responsibility to ensure that at most one thread is using a SchemaFactory object at any given moment. Implementations are encouraged to mark methods as synchronized to protect themselves from broken clients.

SchemaFactory is not re-entrant. While one of the newSchema methods is being invoked, applications may not attempt to recursively invoke the newSchema method, even from the same thread.

Schema Language

This spec uses a namespace URI to designate a schema language. The following table shows the values defined by this specification.

To be compliant with the spec, the implementation is only required to support W3C XML Schema 1.0. However, if it chooses to support other schema languages listed here, it must conform to the relevant behaviors described in this spec.

Schema languages not listed here are expected to introduce their own URIs to represent themselves. The SchemaFactory class is capable of locating other implementations for other schema languages at run-time.

Note that because the XML DTD is strongly tied to the parsing process and has a significant effect on the parsing process, it is impossible to define the DTD validation as a process independent from parsing. For this reason, this specification does not define the semantics for the XML DTD. This doesn't prohibit implentors from implementing it in a way they see fit, but users are warned that any DTD validation implemented on this interface necessarily deviate from the XML DTD semantics as defined in the XML 1.0.
value language
javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI ("http://www.w3.org/2001/XMLSchema") W3C XML Schema 1.0
javax.xml.XMLConstants.RELAXNG_NS_URI ("http://relaxng.org/ns/structure/1.0") RELAX NG 1.0

author:
   Kohsuke Kawaguchi
author:
   Neeraj Bajaj
version:
   $Revision: 1.7 $, $Date: 2006/05/19 01:08:43 $
since:
   1.5




Constructor Summary
protected  SchemaFactory()
    

Method Summary
abstract public  ErrorHandlergetErrorHandler()
     Gets the current ErrorHandler set to this SchemaFactory .
public  booleangetFeature(String name)
     Look up the value of a feature flag.

The feature name is any fully-qualified URI.

public  ObjectgetProperty(String name)
     Look up the value of a property.

The property name is any fully-qualified URI.

abstract public  LSResourceResolvergetResourceResolver()
     Gets the current LSResourceResolver set to this SchemaFactory .
abstract public  booleanisSchemaLanguageSupported(String schemaLanguage)
    

Is specified schema supported by this SchemaFactory?


Parameters:
  schemaLanguage - Specifies the schema language which the returned SchemaFactory will understand.schemaLanguage must specify a valid schema language.
final public static  SchemaFactorynewInstance(String schemaLanguage)
    

Lookup an implementation of the SchemaFactory that supports the specified schema language and return it.

To find a SchemaFactory object for a given schema language, this method looks the following places in the following order where "the class loader" refers to the context class loader:

  1. If the system property "javax.xml.validation.SchemaFactory:schemaLanguage" is present (where schemaLanguage is the parameter to this method), then its value is read as a class name.
public static  SchemaFactorynewInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader)
    

Obtain a new instance of a SchemaFactory from class name.

public  SchemanewSchema(Source schema)
    

Parses the specified source as a schema and returns it as a schema.

This is a convenience method for SchemaFactory.newSchema(Source[] schemas) .


Parameters:
  schema - Source that represents a schema.
public  SchemanewSchema(File schema)
    

Parses the specified File as a schema and returns it as a Schema.

This is a convenience method for SchemaFactory.newSchema(Source schema) .


Parameters:
  schema - File that represents a schema.
public  SchemanewSchema(URL schema)
    

Parses the specified URL as a schema and returns it as a Schema.

This is a convenience method for SchemaFactory.newSchema(Source schema) .


Parameters:
  schema - URL that represents a schema.
abstract public  SchemanewSchema(Source[] schemas)
     Parses the specified source(s) as a schema and returns it as a schema.

The callee will read all the Source s and combine them into a single schema.

abstract public  SchemanewSchema()
     Creates a special Schema object.

The exact semantics of the returned Schema object depend on the schema language for which this SchemaFactory is created.

Also, implementations are allowed to use implementation-specific property/feature to alter the semantics of this method.

Implementors and developers should pay particular attention to how the features set on this SchemaFactory are processed by this special Schema . In some cases, for example, when the SchemaFactory and the class actually loading the schema come from different implementations, it may not be possible for SchemaFactory features to be inherited automatically. Developers should make sure that features, such as secure processing, are explicitly set in both places.

W3C XML Schema 1.0

For XML Schema, this method creates a Schema object that performs validation by using location hints specified in documents.

The returned Schema object assumes that if documents refer to the same URL in the schema location hints, they will always resolve to the same schema document.

abstract public  voidsetErrorHandler(ErrorHandler errorHandler)
     Sets the ErrorHandler to receive errors encountered during the newSchema method invocation.

Error handler can be used to customize the error handling process during schema parsing.

public  voidsetFeature(String name, boolean value)
    

Set a feature for this SchemaFactory, Schema s created by this factory, and by extension, Validator s and ValidatorHandler s created by those Schema s.

Implementors and developers should pay particular attention to how the special Schema object returned by SchemaFactory.newSchema() is processed.

public  voidsetProperty(String name, Object object)
     Set the value of a property.

The property name is any fully-qualified URI.

abstract public  voidsetResourceResolver(LSResourceResolver resourceResolver)
     Sets the LSResourceResolver to customize resource resolution when parsing schemas.

SchemaFactory uses a LSResourceResolver when it needs to locate external resources while parsing schemas, although exactly what constitutes "locating external resources" is up to each schema language.



Constructor Detail
SchemaFactory
protected SchemaFactory()(Code)

Constructor for derived classes.

The constructor does nothing.

Derived classes must create SchemaFactory objects that have null ErrorHandler and null LSResourceResolver .





Method Detail
getErrorHandler
abstract public ErrorHandler getErrorHandler()(Code)
Gets the current ErrorHandler set to this SchemaFactory . This method returns the object that was last set throughthe SchemaFactory.setErrorHandler(ErrorHandler) method, or nullif that method has never been called since this SchemaFactoryhas created.
See Also:   SchemaFactory.setErrorHandler(ErrorHandler)



getFeature
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException(Code)
Look up the value of a feature flag.

The feature name is any fully-qualified URI. It is possible for a SchemaFactory to recognize a feature name but temporarily be unable to return its value.

Implementors are free (and encouraged) to invent their own features, using names built on their own URIs.


Parameters:
  name - The feature name, which is a non-null fully-qualified URI. The current value of the feature (true or false).
throws:
  SAXNotRecognizedException - If the featurevalue can't be assigned or retrieved.
throws:
  SAXNotSupportedException - When theSchemaFactory recognizes the feature name but cannot determine its value at this time.
throws:
  NullPointerException - If name is null.
See Also:   SchemaFactory.setFeature(String,boolean)



getProperty
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException(Code)
Look up the value of a property.

The property name is any fully-qualified URI. It is possible for a SchemaFactory to recognize a property name but temporarily be unable to return its value.

SchemaFactory s are not required to recognize any specific property names.

Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs.


Parameters:
  name - The property name, which is a non-null fully-qualified URI. The current value of the property.
throws:
  SAXNotRecognizedException - If the propertyvalue can't be assigned or retrieved.
throws:
  SAXNotSupportedException - When theXMLReader recognizes the property name but cannot determine its value at this time.
throws:
  NullPointerException - If name is null.
See Also:   SchemaFactory.setProperty(String,Object)



getResourceResolver
abstract public LSResourceResolver getResourceResolver()(Code)
Gets the current LSResourceResolver set to this SchemaFactory . This method returns the object that was last set throughthe SchemaFactory.setResourceResolver(LSResourceResolver) method, or nullif that method has never been called since this SchemaFactoryhas created.
See Also:   SchemaFactory.setErrorHandler(ErrorHandler)



isSchemaLanguageSupported
abstract public boolean isSchemaLanguageSupported(String schemaLanguage)(Code)

Is specified schema supported by this SchemaFactory?


Parameters:
  schemaLanguage - Specifies the schema language which the returned SchemaFactory will understand.schemaLanguage must specify a valid schema language. true if SchemaFactory supports schemaLanguage, else false.
throws:
  NullPointerException - If schemaLanguage is null.
throws:
  IllegalArgumentException - If schemaLanguage.length() == 0or schemaLanguage does not specify a valid schema language.



newInstance
final public static SchemaFactory newInstance(String schemaLanguage)(Code)

Lookup an implementation of the SchemaFactory that supports the specified schema language and return it.

To find a SchemaFactory object for a given schema language, this method looks the following places in the following order where "the class loader" refers to the context class loader:

  1. If the system property "javax.xml.validation.SchemaFactory:schemaLanguage" is present (where schemaLanguage is the parameter to this method), then its value is read as a class name. The method will try to create a new instance of this class by using the class loader, and returns it if it is successfully created.
  2. $java.home/lib/jaxp.properties is read and the value associated with the key being the system property above is looked for. If present, the value is processed just like above.
  3. The class loader is asked for service provider provider-configuration files matching javax.xml.validation.SchemaFactory in the resource directory META-INF/services. See the JAR File Specification for file format and parsing rules. Each potential service provider is required to implement the method:

    SchemaFactory.isSchemaLanguageSupported(String schemaLanguage) 
    The first service provider found in class loader order that supports the specified schema language is returned.
  4. Platform default SchemaFactory is located in a implementation specific way. There must be a platform default SchemaFactory for W3C XML Schema.

If everything fails, IllegalArgumentException will be thrown.

Tip for Trouble-shooting:

See java.util.Properties.load(java.io.InputStream) for exactly how a property file is parsed. In particular, colons ':' need to be escaped in a property file, so make sure schema language URIs are properly escaped in it. For example:

 http\://www.w3.org/2001/XMLSchema=org.acme.foo.XSSchemaFactory
 

Parameters:
  schemaLanguage - Specifies the schema language which the returnedSchemaFactory will understand. Seethe list of availableschema languages for the possible values. New instance of a SchemaFactory
throws:
  IllegalArgumentException - If no implementation of the schema language is available.
throws:
  NullPointerException - If the schemaLanguage parameter is null.
See Also:   SchemaFactory.newInstance(String schemaLanguage,String factoryClassName,ClassLoader classLoader)



newInstance
public static SchemaFactory newInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader)(Code)

Obtain a new instance of a SchemaFactory from class name. SchemaFactory is returned if specified factory class name supports the specified schema language. This function is useful when there are multiple providers in the classpath. It gives more control to the application as it can specify which provider should be loaded.

Tip for Trouble-shooting

Setting the jaxp.debug system property will cause this method to print a lot of debug messages to System.err about what it is doing and where it is looking at.

If you have problems try:

 java -Djaxp.debug=1 YourProgram ....
 

Parameters:
  schemaLanguage - Specifies the schema language which the returnedSchemaFactory will understand. Seethe list of availableschema languages for the possible values.
Parameters:
  factoryClassName - fully qualified factory class name that provides implementation of javax.xml.validation.SchemaFactory.
Parameters:
  classLoader - ClassLoader used to load the factory class. If null current Thread's context classLoader is used to load the factory class. New instance of a SchemaFactory
throws:
  IllegalArgumentException - if factoryClassName is null, or the factory class cannot be loaded, instantiated or doesn't support the schema language specified in schemLanguageparameter.
throws:
  NullPointerException - If the schemaLanguage parameter is null.
See Also:   SchemaFactory.newInstance(String schemaLanguage)
since:
   1.6



newSchema
public Schema newSchema(Source schema) throws SAXException(Code)

Parses the specified source as a schema and returns it as a schema.

This is a convenience method for SchemaFactory.newSchema(Source[] schemas) .


Parameters:
  schema - Source that represents a schema. New Schema from parsing schema.
throws:
  SAXException - If a SAX error occurs during parsing.
throws:
  NullPointerException - if schema is null.



newSchema
public Schema newSchema(File schema) throws SAXException(Code)

Parses the specified File as a schema and returns it as a Schema.

This is a convenience method for SchemaFactory.newSchema(Source schema) .


Parameters:
  schema - File that represents a schema. New Schema from parsing schema.
throws:
  SAXException - If a SAX error occurs during parsing.
throws:
  NullPointerException - if schema is null.



newSchema
public Schema newSchema(URL schema) throws SAXException(Code)

Parses the specified URL as a schema and returns it as a Schema.

This is a convenience method for SchemaFactory.newSchema(Source schema) .


Parameters:
  schema - URL that represents a schema. New Schema from parsing schema.
throws:
  SAXException - If a SAX error occurs during parsing.
throws:
  NullPointerException - if schema is null.



newSchema
abstract public Schema newSchema(Source[] schemas) throws SAXException(Code)
Parses the specified source(s) as a schema and returns it as a schema.

The callee will read all the Source s and combine them into a single schema. The exact semantics of the combination depends on the schema language that this SchemaFactory object is created for.

When an ErrorHandler is set, the callee will report all the errors found in sources to the handler. If the handler throws an exception, it will abort the schema compilation and the same exception will be thrown from this method. Also, after an error is reported to a handler, the callee is allowed to abort the further processing by throwing it. If an error handler is not set, the callee will throw the first error it finds in the sources.

W3C XML Schema 1.0

The resulting schema contains components from the specified sources. The same result would be achieved if all these sources were imported, using appropriate values for schemaLocation and namespace, into a single schema document with a different targetNamespace and no components of its own, if the import elements were given in the same order as the sources. Section 4.2.3 of the XML Schema recommendation describes the options processors have in this regard. While a processor should be consistent in its treatment of JAXP schema sources and XML Schema imports, the behaviour between JAXP-compliant parsers may vary; in particular, parsers may choose to ignore all but the first <import> for a given namespace, regardless of information provided in schemaLocation.

If the parsed set of schemas includes error(s) as specified in the section 5.1 of the XML Schema spec, then the error must be reported to the ErrorHandler .

RELAX NG

For RELAX NG, this method must throw UnsupportedOperationException if schemas.length!=1.
Parameters:
  schemas - inputs to be parsed. SchemaFactory is requiredto recognize javax.xml.transform.sax.SAXSource,StreamSource,javax.xml.transform.stax.StAXSource, and javax.xml.transform.dom.DOMSource.Input schemas must be XML documents orXML elements and must not be null. For backwards compatibility,the results of passing anything other thana document or element are implementation-dependent.Implementations must either recognize and process the inputor thrown an IllegalArgumentException.Always return a non-null valid Schema object.Note that when an error has been reported, there is noguarantee that the returned Schema object ismeaningful.
throws:
  SAXException - If an error is found during processing the specified inputs.When an ErrorHandler is set, errors are reported tothere first. See SchemaFactory.setErrorHandler(ErrorHandler).
throws:
  NullPointerException - If the schemas parameter itself is null orany item in the array is null.
throws:
  IllegalArgumentException - If any item in the array is not recognized by this method.
throws:
  UnsupportedOperationException - If the schema language doesn't support this operation.




newSchema
abstract public Schema newSchema() throws SAXException(Code)
Creates a special Schema object.

The exact semantics of the returned Schema object depend on the schema language for which this SchemaFactory is created.

Also, implementations are allowed to use implementation-specific property/feature to alter the semantics of this method.

Implementors and developers should pay particular attention to how the features set on this SchemaFactory are processed by this special Schema . In some cases, for example, when the SchemaFactory and the class actually loading the schema come from different implementations, it may not be possible for SchemaFactory features to be inherited automatically. Developers should make sure that features, such as secure processing, are explicitly set in both places.

W3C XML Schema 1.0

For XML Schema, this method creates a Schema object that performs validation by using location hints specified in documents.

The returned Schema object assumes that if documents refer to the same URL in the schema location hints, they will always resolve to the same schema document. This asusmption allows implementations to reuse parsed results of schema documents so that multiple validations against the same schema will run faster.

Note that the use of schema location hints introduces a vulnerability to denial-of-service attacks.

RELAX NG

RELAX NG does not support this operation. Always return non-null valid Schema object.
throws:
  UnsupportedOperationException - If this operation is not supported by the callee.
throws:
  SAXException - If this operation is supported but failed for some reason.




setErrorHandler
abstract public void setErrorHandler(ErrorHandler errorHandler)(Code)
Sets the ErrorHandler to receive errors encountered during the newSchema method invocation.

Error handler can be used to customize the error handling process during schema parsing. When an ErrorHandler is set, errors found during the parsing of schemas will be first sent to the ErrorHandler .

The error handler can abort the parsing of a schema immediately by throwing SAXException from the handler. Or for example it can print an error to the screen and try to continue the processing by returning normally from the ErrorHandler

If any Throwable (or instances of its derived classes) is thrown from an ErrorHandler , the caller of the newSchema method will be thrown the same Throwable object.

SchemaFactory is not allowed to throw SAXException without first reporting it to ErrorHandler .

Applications can call this method even during a Schema is being parsed.

When the ErrorHandler is null, the implementation will behave as if the following ErrorHandler is set:

 class DraconianErrorHandler implements 
ErrorHandler  {
 public void fatalError( 
org.xml.sax.SAXParseException  e ) throws 
SAXException  {
 throw e;
 }
 public void error( 
org.xml.sax.SAXParseException  e ) throws 
SAXException  {
 throw e;
 }
 public void warning( 
org.xml.sax.SAXParseException  e ) throws 
SAXException  {
 // noop
 }
 }
 

When a new SchemaFactory object is created, initially this field is set to null. This field will NOT be inherited to Schema s, Validator s, or ValidatorHandler s that are created from this SchemaFactory .
Parameters:
  errorHandler - A new error handler to be set.This parameter can be null.




setFeature
public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException(Code)

Set a feature for this SchemaFactory, Schema s created by this factory, and by extension, Validator s and ValidatorHandler s created by those Schema s.

Implementors and developers should pay particular attention to how the special Schema object returned by SchemaFactory.newSchema() is processed. In some cases, for example, when the SchemaFactory and the class actually loading the schema come from different implementations, it may not be possible for SchemaFactory features to be inherited automatically. Developers should make sure that features, such as secure processing, are explicitly set in both places.

The feature name is any fully-qualified URI. It is possible for a SchemaFactory to expose a feature value but to be unable to change the current value.

All implementations are required to support the javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING feature. When the feature is:

  • true: the implementation will limit XML processing to conform to implementation limits. Examples include enity expansion limits and XML Schema constructs that would consume large amounts of resources. If XML processing is limited for security reasons, it will be reported via a call to the registered ErrorHandler.fatalError(SAXParseException exception) . See SchemaFactory.setErrorHandler(ErrorHandler errorHandler) .
  • false: the implementation will processing XML according to the XML specifications without regard to possible implementation limits.

Parameters:
  name - The feature name, which is a non-null fully-qualified URI.
Parameters:
  value - The requested value of the feature (true or false).
throws:
  SAXNotRecognizedException - If the featurevalue can't be assigned or retrieved.
throws:
  SAXNotSupportedException - When theSchemaFactory recognizes the feature name but cannot set the requested value.
throws:
  NullPointerException - If name is null.
See Also:   SchemaFactory.getFeature(String)



setProperty
public void setProperty(String name, Object object) throws SAXNotRecognizedException, SAXNotSupportedException(Code)
Set the value of a property.

The property name is any fully-qualified URI. It is possible for a SchemaFactory to recognize a property name but to be unable to change the current value.

SchemaFactory s are not required to recognize setting any specific property names.


Parameters:
  name - The property name, which is a non-null fully-qualified URI.
Parameters:
  object - The requested value for the property.
throws:
  SAXNotRecognizedException - If the propertyvalue can't be assigned or retrieved.
throws:
  SAXNotSupportedException - When theSchemaFactory recognizes the property name butcannot set the requested value.
throws:
  NullPointerException - If name is null.



setResourceResolver
abstract public void setResourceResolver(LSResourceResolver resourceResolver)(Code)
Sets the LSResourceResolver to customize resource resolution when parsing schemas.

SchemaFactory uses a LSResourceResolver when it needs to locate external resources while parsing schemas, although exactly what constitutes "locating external resources" is up to each schema language. For example, for W3C XML Schema, this includes files <include>d or <import>ed, and DTD referenced from schema files, etc.

Applications can call this method even during a Schema is being parsed.

When the LSResourceResolver is null, the implementation will behave as if the following LSResourceResolver is set:

 class DumbDOMResourceResolver implements 
LSResourceResolver  {
 public 
org.w3c.dom.ls.LSInput  resolveResource(
 String publicId, String systemId, String baseURI) {
 return null; // always return null
 }
 }
 

If a LSResourceResolver throws a RuntimeException (or instances of its derived classes), then the SchemaFactory will abort the parsing and the caller of the newSchema method will receive the same RuntimeException .

When a new SchemaFactory object is created, initially this field is set to null. This field will NOT be inherited to Schema s, Validator s, or ValidatorHandler s that are created from this SchemaFactory .
Parameters:
  resourceResolver - A new resource resolver to be set. This parameter can be null.




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.