FileDocCategorySizeDatePackage
Schematron.javaAPI DocGlassfish v2 API5275Fri May 04 22:24:38 BST 2007com.sun.enterprise.config.serverbeans.validation

Schematron

public class Schematron extends Object
This class implements the final transformation in the multi-step Schematron validation process. It is assumed that the user knows something about Schematron. Schematron instances are not thread-safe. Each instance can only be used in a single thread, but each instance can be used multiple times in sequence. We use the default Transformer, as per the javax.xml.transform.TransformFactory class. It is important that the transformer be compatable with the stylesheet being used, but apart from that this class has no constraints on these objects. It simply provides a convenient wrapper for obtaining a validator.

Fields Summary
private Transformer
transformer
Constructors Summary
Schematron(String schemaName)
Construct an instance which will use the given resource name to find the schema to be used for subsequent analyses. The schemaName is looked up as a resource on the classpath using {@link Class.getResourceAsStream(schemaName)}.

param
schemaName the name of the schema to be used
throws
TransformerConfigurationException if the corresponding resource could not be found, or if the transformer could not be constructed.
throws
TransformerFactoryConfigurationError if the underlying transformer factory could not be instantiated.

        transformer = getTransformer(schemaName);
    
Methods Summary
voidanalyze(javax.xml.transform.Source src, javax.xml.transform.Result result)
Analyse the given source onto the given result, using the given schematron stylesheet, using XSLT transformations.

param
src the XML source which is to be analyzed
param
result the result onto which the analsis will be placed
throws
TransformerException if there was a problem with the transformation.

        transformer.transform(src, result);
    
private javax.xml.transform.TransformergetTransformer(java.lang.String schema)

        final InputStream is = this.getClass().getResourceAsStream(schema);
        if (null == is){
            throw new TransformerConfigurationException("Couldn't construct a transformer to perform validation because I couldn't find the resource named \""+schema+"\" from "+this.getClass().getName());
        }
        final TransformerFactory f = TransformerFactory.newInstance();

        final Transformer t = f.newTransformer(new StreamSource(is));

        return t;