KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > validation > jaxp > JaxpSchema


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.validation.jaxp;
17
18 import javax.xml.validation.Schema JavaDoc;
19 import javax.xml.validation.ValidatorHandler JavaDoc;
20
21 import org.apache.cocoon.components.validation.ValidationHandler;
22 import org.apache.cocoon.components.validation.impl.AbstractSchema;
23 import org.apache.cocoon.components.validation.impl.DefaultValidationHandler;
24 import org.apache.cocoon.components.validation.impl.DraconianErrorHandler;
25 import org.apache.excalibur.source.SourceValidity;
26 import org.xml.sax.ErrorHandler JavaDoc;
27 import org.xml.sax.SAXException JavaDoc;
28
29 /**
30  * <p>An extension of the {@link AbstractSchema} class specific to the
31  * {@link JaxpSchemaParser} implementation.</p>
32  *
33  * @author <a HREF="mailto:pier@betaversion.org">Pier Fumagalli</a>
34  */

35 public class JaxpSchema extends AbstractSchema {
36
37     /** <p>The wrapped JAXP {@link Schema} instance.</p> */
38     private final Schema JavaDoc schema;
39
40     /**
41      * <p>Create a new {@link JaxpSchema} instance.</p>
42      *
43      * @param schema the {@link Schema} instance to wrap.
44      * @param validity the {@link SourceValidity} associated with the schema.
45      */

46     public JaxpSchema(Schema JavaDoc schema, SourceValidity validity) {
47         super(validity);
48         this.schema = schema;
49     }
50
51     /**
52      * <p>Return a new {@link ValidationHandler} instance that can be used to
53      * validate an XML document by sending SAX events to it.</p>
54      *
55      * <p>The specified {@link ErrorHandler} will be notified of all warnings or
56      * errors encountered validating the SAX events sent to the returned
57      * {@link ValidationHandler}, and <b>must not</b> be <b>null</b>.</p>
58      *
59      * <p>The returned {@link ValidationHandler} can be used to validate <b>only
60      * one</b> XML document. To validate more than one document, this method should
61      * be called once for each document to validate.</p>
62      *
63      * @param handler an {@link ErrorHandler} to notify of validation errors.
64      * @return a <b>non-null</b> {@link ValidationHandler} instance.
65      * @throws SAXException if an error occurred creating the validation handler.
66      */

67     public ValidationHandler createValidator(ErrorHandler handler)
68     throws SAXException JavaDoc {
69         if (handler == null) handler = DraconianErrorHandler.INSTANCE;
70         ValidatorHandler JavaDoc validator = this.schema.newValidatorHandler();
71         validator.setErrorHandler(handler);
72         return new DefaultValidationHandler(this.getValidity(), validator);
73     }
74 }
75
Popular Tags