KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > jaxp > validation > InsulatedValidatorComponent


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57 package com.sun.org.apache.xerces.internal.jaxp.validation;
58
59 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
60 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
61 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
62 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
63 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentFilter;
64
65 /**
66  * Wraps a validator {@link XMLComponent} and isolates
67  * it from the rest of the components.
68  *
69  * <p>
70  * For the performance reason, when a validator from Xerces is used
71  * for a parser from Xerces, we will do "chating" by building an
72  * XNI pipeline. This saves the overhead of conversion between
73  * XNI events and SAX events.
74  *
75  * <p>
76  * However, if we just insert the validator component into the
77  * parser pipeline, the {@link XMLComponentManager} that the parser
78  * uses could change the way the validator works. On the other hand,
79  * certain configuration (such as error handlers) need to be given
80  * through a parser configuration.
81  *
82  * <p>
83  * To avoid this harmful interaction, this class wraps the validator
84  * and behaves as an insulation. The class itself will implement
85  * {@link XMLComponent}, and it selectively deliver properties to
86  * the wrapped validator.
87  *
88  * <p>
89  * Since the exact set of properties/features that require insulation
90  * depends on the actual validator implementation, this class is
91  * expected to be derived to add such validator-specific insulation
92  * code.
93  *
94  * @author
95  * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
96  */

97 public abstract class InsulatedValidatorComponent implements
98     XMLComponent, // this object behaves as a component to the parent component manager
99
XMLComponentManager // this object behaves as a manager to the wrapped validator.
100
{
101     
102     /**
103      * The object being wrapped.
104      * We require the validator to be both {@link XMLDocumentFilter}
105      * and {@link XMLComponent}.
106      */

107     private final XMLDocumentFilter fValidator;
108     
109     /**
110      * The same object as {@link #fValidator}.
111      */

112     private final XMLComponent fValidatorComponent;
113     
114     /**
115      * We will not use external {@link ValidationManager} to
116      * avoid interaction.
117      * <p>
118      * The existance of JAXP validator should not change the
119      * semantics of the parser processing. IOW it should not
120      * interact with the other validators in the parser pipeline.
121      */

122     private final ValidationManager fValidationManager = new ValidationManager();
123     
124     /**
125      * The current component manager.
126      */

127     private XMLComponentManager fManager;
128     
129     public InsulatedValidatorComponent( XMLDocumentFilter validator ) {
130         fValidator = validator;
131         fValidatorComponent = (XMLComponent)validator;
132     }
133     
134     
135     /**
136      * Obtains a reference to the validator as a filter.
137      *
138      * @return
139      * non-null valid object.
140      */

141     public final XMLDocumentFilter getValidator() {
142         return fValidator;
143     }
144
145     
146 //
147
//
148
// XMLComponent implementation
149
//
150
//
151
public final void reset(XMLComponentManager componentManager) throws XMLConfigurationException {
152         fManager = componentManager;
153         fValidatorComponent.reset(this);
154         fValidationManager.reset();
155     }
156
157
158     public final String JavaDoc[] getRecognizedFeatures() {
159         return fValidatorComponent.getRecognizedFeatures();
160     }
161
162
163     public final void setFeature(String JavaDoc featureId, boolean state) throws XMLConfigurationException {
164         // don't allow features to be set.
165
}
166
167
168     public final String JavaDoc[] getRecognizedProperties() {
169         return fValidatorComponent.getRecognizedProperties();
170     }
171
172
173     public final void setProperty(String JavaDoc propertyId, Object JavaDoc value) throws XMLConfigurationException {
174         // don't allow properties to be set.
175
}
176
177
178     public final Boolean JavaDoc getFeatureDefault(String JavaDoc featureId) {
179         return fValidatorComponent.getFeatureDefault(featureId);
180     }
181
182
183     public final Object JavaDoc getPropertyDefault(String JavaDoc propertyId) {
184         return fValidatorComponent.getPropertyDefault(propertyId);
185     }
186
187     
188 //
189
//
190
// XMLComponentManager implementation
191
//
192
//
193
/**
194      * Derived class may override this method to block additional features.
195      */

196     public boolean getFeature(String JavaDoc featureId) throws XMLConfigurationException {
197         return fManager.getFeature(featureId);
198     }
199
200
201     /**
202      * Derived class may override this method to block additional properties.
203      */

204     public Object JavaDoc getProperty(String JavaDoc propertyId) throws XMLConfigurationException {
205         if( propertyId.equals(XercesConstants.VALIDATION_MANAGER) )
206             return fValidationManager;
207         return fManager.getProperty(propertyId);
208     }
209 }
210
Popular Tags