KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > validation > jing > JingSchema


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.jing;
17
18 import org.apache.cocoon.components.validation.ValidationHandler;
19 import org.apache.cocoon.components.validation.impl.AbstractSchema;
20 import org.apache.cocoon.components.validation.impl.DefaultValidationHandler;
21 import org.apache.cocoon.components.validation.impl.DraconianErrorHandler;
22 import org.apache.excalibur.source.SourceValidity;
23 import org.xml.sax.ContentHandler JavaDoc;
24 import org.xml.sax.ErrorHandler JavaDoc;
25 import org.xml.sax.SAXException JavaDoc;
26
27 import com.thaiopensource.util.PropertyMap;
28 import com.thaiopensource.util.PropertyMapBuilder;
29 import com.thaiopensource.validate.Schema;
30 import com.thaiopensource.validate.ValidateProperty;
31 import com.thaiopensource.validate.Validator;
32
33 /**
34  * <p>An extension of {@link AbstractSchema} used by the {@link JingSchemaParser}
35  * implementation.</p>
36  *
37  * @author <a HREF="mailto:pier@betaversion.org">Pier Fumagalli</a>
38  */

39 public class JingSchema extends AbstractSchema {
40     
41     /** <p>The original schema instance to wrap.</p> */
42     private final Schema schema;
43
44     /**
45      * <p>Create a new {@link JingSchema} instance.</p>
46      *
47      * @param schema the JING original schema to wrap.
48      * @param validity the {@link SourceValidity} associated with the schema.
49      */

50     protected JingSchema(Schema schema, SourceValidity validity) {
51         super(validity);
52         this.schema = schema;
53     }
54
55     /**
56      * <p>Return a new {@link ValidationHandler} instance that can be used to send
57      * SAX events to for proper validation.</p>
58      *
59      * <p>The specified {@link ErrorHandler} will be notified of all warnings or
60      * errors encountered validating the SAX events sent to the returned
61      * {@link ValidationHandler}.</p>
62      *
63      * @param errorHandler 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 errorHandler)
68     throws SAXException JavaDoc {
69         if (errorHandler == null) errorHandler = DraconianErrorHandler.INSTANCE;
70         final PropertyMapBuilder builder = new PropertyMapBuilder();
71         ValidateProperty.ERROR_HANDLER.put(builder, errorHandler);
72         final PropertyMap properties = builder.toPropertyMap();
73         final Validator validator = this.schema.createValidator(properties);
74         final ContentHandler JavaDoc handler = validator.getContentHandler();
75         return new DefaultValidationHandler(this.getValidity(), handler);
76     }
77 }
Popular Tags