KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > xml > AbstractXMLProducer


1 /*
2  * Copyright 1999-2004 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.xml;
17
18 import org.apache.avalon.excalibur.pool.Recyclable;
19 import org.apache.avalon.framework.logger.AbstractLogEnabled;
20 import org.xml.sax.ContentHandler JavaDoc;
21 import org.xml.sax.ext.LexicalHandler JavaDoc;
22 import org.xml.sax.helpers.DefaultHandler JavaDoc;
23
24 /**
25  * This abstract class provides default implementation of the methods specified
26  * by the <code>XMLProducer</code> interface.
27  *
28  * @author <a HREF="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
29  * (Apache Software Foundation)
30  * @version CVS $Id: AbstractXMLProducer.java 225805 2005-07-28 15:57:33Z sylvain $
31  */

32 public abstract class AbstractXMLProducer extends AbstractLogEnabled
33                                           implements XMLProducer, Recyclable {
34     
35     protected static final ContentHandler JavaDoc EMPTY_CONTENT_HANDLER = new DefaultHandler JavaDoc();
36
37     /** The <code>XMLConsumer</code> receiving SAX events. */
38     protected XMLConsumer xmlConsumer;
39
40     /** The <code>ContentHandler</code> receiving SAX events. */
41     protected ContentHandler JavaDoc contentHandler = EMPTY_CONTENT_HANDLER;
42
43     /** The <code>LexicalHandler</code> receiving SAX events. */
44     protected LexicalHandler JavaDoc lexicalHandler = DefaultLexicalHandler.NULL_HANDLER;
45
46     /**
47      * Set the <code>XMLConsumer</code> that will receive XML data.
48      * <br>
49      * This method will simply call <code>setContentHandler(consumer)</code>
50      * and <code>setLexicalHandler(consumer)</code>.
51      */

52     public void setConsumer(XMLConsumer consumer) {
53         this.xmlConsumer = consumer;
54         setContentHandler(consumer);
55         setLexicalHandler(consumer);
56     }
57
58     /**
59      * Set the <code>ContentHandler</code> that will receive XML data.
60      * <br>
61      * Subclasses may retrieve this <code>ContentHandler</code> instance
62      * accessing the protected <code>super.contentHandler</code> field.
63      */

64     public void setContentHandler(ContentHandler JavaDoc handler) {
65         this.contentHandler = handler;
66     }
67
68     /**
69      * Set the <code>LexicalHandler</code> that will receive XML data.
70      * <br>
71      * Subclasses may retrieve this <code>LexicalHandler</code> instance
72      * accessing the protected <code>super.lexicalHandler</code> field.
73      */

74     public void setLexicalHandler(LexicalHandler JavaDoc handler) {
75         this.lexicalHandler = handler;
76     }
77
78     /**
79      * Recycle the producer by removing references, and resetting handlers to
80      * null (empty) implementations.
81      */

82     public void recycle() {
83         this.xmlConsumer = null;
84         this.contentHandler = EMPTY_CONTENT_HANDLER;
85         this.lexicalHandler = DefaultLexicalHandler.NULL_HANDLER;
86     }
87 }
88
Popular Tags