KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > n3 > nanoxml > ValidatorPlugin


1 /* ValidatorPlugin.java NanoXML/Java
2  *
3  * $Revision: 1421 $
4  * $Date: 2006-03-12 17:32:32 +0100 (Sun, 12 Mar 2006) $
5  * $Name$
6  *
7  * This file is part of NanoXML 2 for Java.
8  * Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved.
9  *
10  * This software is provided 'as-is', without any express or implied warranty.
11  * In no event will the authors be held liable for any damages arising from the
12  * use of this software.
13  *
14  * Permission is granted to anyone to use this software for any purpose,
15  * including commercial applications, and to alter it and redistribute it
16  * freely, subject to the following restrictions:
17  *
18  * 1. The origin of this software must not be misrepresented; you must not
19  * claim that you wrote the original software. If you use this software in
20  * a product, an acknowledgment in the product documentation would be
21  * appreciated but is not required.
22  *
23  * 2. Altered source versions must be plainly marked as such, and must not be
24  * misrepresented as being the original software.
25  *
26  * 3. This notice may not be removed or altered from any source distribution.
27  */

28
29 package net.n3.nanoxml;
30
31 import java.util.Properties JavaDoc;
32
33 /**
34  * ValidatorPlugin allows the application to insert additional validators into NanoXML.
35  *
36  * @author Marc De Scheemaecker
37  * @version $Name$, $Revision: 1421 $
38  */

39 public class ValidatorPlugin implements IXMLValidator
40 {
41
42     /**
43      * The delegate.
44      */

45     private IXMLValidator delegate;
46
47     /**
48      * Initializes the plugin.
49      */

50     public ValidatorPlugin()
51     {
52         this.delegate = null;
53     }
54
55     /**
56      * Cleans up the object when it's destroyed.
57      */

58     protected void finalize() throws Throwable JavaDoc
59     {
60         this.delegate = null;
61         super.finalize();
62     }
63
64     /**
65      * Returns the delegate.
66      */

67     public IXMLValidator getDelegate()
68     {
69         return this.delegate;
70     }
71
72     /**
73      * Sets the delegate.
74      *
75      * @param delegate the delegate
76      */

77     public void setDelegate(IXMLValidator delegate)
78     {
79         this.delegate = delegate;
80     }
81
82     /**
83      * Sets the parameter entity resolver.
84      *
85      * @param resolver the entity resolver.
86      */

87     public void setParameterEntityResolver(IXMLEntityResolver resolver)
88     {
89         this.delegate.setParameterEntityResolver(resolver);
90     }
91
92     /**
93      * Returns the parameter entity resolver.
94      *
95      * @return the entity resolver.
96      */

97     public IXMLEntityResolver getParameterEntityResolver()
98     {
99         return this.delegate.getParameterEntityResolver();
100     }
101
102     /**
103      * Parses the DTD. The validator object is responsible for reading the full DTD.
104      *
105      * @param publicID the public ID, which may be null.
106      * @param reader the reader to read the DTD from.
107      * @param entityResolver the entity resolver.
108      * @param external true if the DTD is external.
109      *
110      * @throws java.lang.Exception if something went wrong.
111      */

112     public void parseDTD(String JavaDoc publicID, IXMLReader reader, IXMLEntityResolver entityResolver,
113             boolean external) throws Exception JavaDoc
114     {
115         this.delegate.parseDTD(publicID, reader, entityResolver, external);
116     }
117
118     /**
119      * Indicates that an element has been started.
120      *
121      * @param name the name of the element.
122      * @param nsPrefix the prefix used to identify the namespace
123      * @param nsSystemId the system ID associated with the namespace
124      * @param systemId the system ID of the XML data of the element.
125      * @param lineNr the line number in the XML data of the element.
126      *
127      * @throws java.lang.Exception if the element could not be validated.
128      */

129     public void elementStarted(String JavaDoc name, String JavaDoc nsPrefix, String JavaDoc nsSystemId, String JavaDoc systemId,
130             int lineNr) throws Exception JavaDoc
131     {
132         this.delegate.elementStarted(name, nsPrefix, nsSystemId, systemId, lineNr);
133     }
134
135     /**
136      * Indicates that the current element has ended.
137      *
138      * @param name the name of the element.
139      * @param nsPrefix the prefix used to identify the namespace
140      * @param nsSystemId the system ID associated with the namespace
141      * @param systemId the system ID of the XML data of the element.
142      * @param lineNr the line number in the XML data of the element.
143      *
144      * @throws java.lang.Exception if the element could not be validated.
145      */

146     public void elementEnded(String JavaDoc name, String JavaDoc nsPrefix, String JavaDoc nsSystemId, String JavaDoc systemId,
147             int lineNr) throws Exception JavaDoc
148     {
149         this.delegate.elementEnded(name, nsPrefix, nsSystemId, systemId, lineNr);
150     }
151
152     /**
153      * Indicates that an attribute has been added to the current element.
154      *
155      * @param name the name of the element.
156      * @param nsPrefix the prefix used to identify the namespace
157      * @param nsSystemId the system ID associated with the namespace
158      * @param extraAttributes where to put extra attributes.
159      * @param systemId the system ID of the XML data of the element.
160      * @param lineNr the line number in the XML data of the element.
161      *
162      * @throws java.lang.Exception if the attribute could not be validated.
163      */

164     public void elementAttributesProcessed(String JavaDoc name, String JavaDoc nsPrefix, String JavaDoc nsSystemId,
165             Properties JavaDoc extraAttributes, String JavaDoc systemId, int lineNr) throws Exception JavaDoc
166     {
167         this.delegate.elementAttributesProcessed(name, nsPrefix, nsSystemId, extraAttributes,
168                 systemId, lineNr);
169     }
170
171     /**
172      * This method is called when the attributes of an XML element have been processed. If there are
173      * attributes with a default value which have not been specified yet, they have to be put into
174      * <I>extraAttributes</I>.
175      *
176      * @param key the name of the attribute.
177      * @param nsPrefix the prefix used to identify the namespace
178      * @param nsSystemId the system ID associated with the namespace
179      * @param value the value of the attribute.
180      * @param systemId the system ID of the XML data of the element.
181      * @param lineNr the line number in the XML data of the element.
182      *
183      * @throws java.lang.Exception if the element could not be validated.
184      */

185     public void attributeAdded(String JavaDoc key, String JavaDoc nsPrefix, String JavaDoc nsSystemId, String JavaDoc value,
186             String JavaDoc systemId, int lineNr) throws Exception JavaDoc
187     {
188         this.delegate.attributeAdded(key, nsPrefix, nsSystemId, value, systemId, lineNr);
189     }
190
191     /**
192      * Indicates that a new #PCDATA element has been encountered.
193      *
194      * @param systemId the system ID of the XML data of the element.
195      * @param lineNr the line number in the XML data of the element.
196      *
197      * @throws java.lang.Exception if the element could not be validated.
198      */

199     public void PCDataAdded(String JavaDoc systemId, int lineNr) throws Exception JavaDoc
200     {
201         this.delegate.PCDataAdded(systemId, lineNr);
202     }
203
204     /**
205      * Throws an XMLValidationException to indicate that an element is missing.
206      *
207      * @param systemID the system ID of the XML data of the element
208      * @param lineNr the line number in the XML data of the element
209      * @param parentElementName the name of the parent element
210      * @param missingElementName the name of the missing element
211      *
212      * @throws net.n3.nanoxml.XMLValidationException of course :-)
213      */

214     public void missingElement(String JavaDoc systemID, int lineNr, String JavaDoc parentElementName,
215             String JavaDoc missingElementName) throws XMLValidationException
216     {
217         XMLUtil.errorMissingElement(systemID, lineNr, parentElementName, missingElementName);
218     }
219
220     /**
221      * Throws an XMLValidationException to indicate that an element is unexpected.
222      *
223      * @param systemID the system ID of the XML data of the element
224      * @param lineNr the line number in the XML data of the element
225      * @param parentElementName the name of the parent element
226      * @param unexpectedElementName the name of the missing element
227      *
228      * @throws net.n3.nanoxml.XMLValidationException of course :-)
229      */

230     public void unexpectedElement(String JavaDoc systemID, int lineNr, String JavaDoc parentElementName,
231             String JavaDoc unexpectedElementName) throws XMLValidationException
232     {
233         XMLUtil.errorUnexpectedElement(systemID, lineNr, parentElementName, unexpectedElementName);
234     }
235
236     /**
237      * Throws an XMLValidationException to indicate that an attribute is missing.
238      *
239      * @param systemID the system ID of the XML data of the element
240      * @param lineNr the line number in the XML data of the element
241      * @param elementName the name of the element
242      * @param attributeName the name of the missing attribute
243      *
244      * @throws net.n3.nanoxml.XMLValidationException of course :-)
245      */

246     public void missingAttribute(String JavaDoc systemID, int lineNr, String JavaDoc elementName,
247             String JavaDoc attributeName) throws XMLValidationException
248     {
249         XMLUtil.errorMissingAttribute(systemID, lineNr, elementName, attributeName);
250     }
251
252     /**
253      * Throws an XMLValidationException to indicate that an attribute is unexpected.
254      *
255      * @param systemID the system ID of the XML data of the element
256      * @param lineNr the line number in the XML data of the element
257      * @param elementName the name of the element
258      * @param attributeName the name of the unexpected attribute
259      *
260      * @throws net.n3.nanoxml.XMLValidationException of course :-)
261      */

262     public void unexpectedAttribute(String JavaDoc systemID, int lineNr, String JavaDoc elementName,
263             String JavaDoc attributeName) throws XMLValidationException
264     {
265         XMLUtil.errorUnexpectedAttribute(systemID, lineNr, elementName, attributeName);
266     }
267
268     /**
269      * Throws an XMLValidationException to indicate that an attribute has an invalid value.
270      *
271      * @param systemID the system ID of the XML data of the element
272      * @param lineNr the line number in the XML data of the element
273      * @param elementName the name of the element
274      * @param attributeName the name of the attribute
275      * @param attributeValue the value of the attribute
276      *
277      * @throws net.n3.nanoxml.XMLValidationException of course :-)
278      */

279     public void invalidAttributeValue(String JavaDoc systemID, int lineNr, String JavaDoc elementName,
280             String JavaDoc attributeName, String JavaDoc attributeValue) throws XMLValidationException
281     {
282         XMLUtil.errorInvalidAttributeValue(systemID, lineNr, elementName, attributeName,
283                 attributeValue);
284     }
285
286     /**
287      * Throws an XMLValidationException to indicate that a #PCDATA element was missing.
288      *
289      * @param systemID the system ID of the XML data of the element
290      * @param lineNr the line number in the XML data of the element
291      * @param parentElementName the name of the parent element
292      *
293      * @throws net.n3.nanoxml.XMLValidationException of course :-)
294      */

295     public void missingPCData(String JavaDoc systemID, int lineNr, String JavaDoc parentElementName)
296             throws XMLValidationException
297     {
298         XMLUtil.errorMissingPCData(systemID, lineNr, parentElementName);
299     }
300
301     /**
302      * Throws an XMLValidationException to indicate that a #PCDATA element was unexpected.
303      *
304      * @param systemID the system ID of the XML data of the element
305      * @param lineNr the line number in the XML data of the element
306      * @param parentElementName the name of the parent element
307      *
308      * @throws net.n3.nanoxml.XMLValidationException of course :-)
309      */

310     public void unexpectedPCData(String JavaDoc systemID, int lineNr, String JavaDoc parentElementName)
311             throws XMLValidationException
312     {
313         XMLUtil.errorUnexpectedPCData(systemID, lineNr, parentElementName);
314     }
315
316     /**
317      * Throws an XMLValidationException.
318      *
319      * @param systemID the system ID of the XML data of the element
320      * @param lineNr the line number in the XML data of the element
321      * @param message the error message
322      * @param elementName the name of the element (may be null)
323      * @param attributeName the name of the attribute (may be null)
324      * @param attributeValue the value of the attribute (may be null)
325      *
326      * @throws net.n3.nanoxml.XMLValidationException of course :-)
327      */

328     public void validationError(String JavaDoc systemID, int lineNr, String JavaDoc message, String JavaDoc elementName,
329             String JavaDoc attributeName, String JavaDoc attributeValue) throws XMLValidationException
330     {
331         XMLUtil.validationError(systemID, lineNr, message, elementName, attributeName,
332                 attributeValue);
333     }
334
335 }
336
Popular Tags