KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > xml > dom > DefaultDOMHandlerFactory


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

17 package org.apache.excalibur.xml.dom;
18
19 import javax.xml.parsers.DocumentBuilder JavaDoc;
20 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
21 import javax.xml.transform.sax.SAXTransformerFactory JavaDoc;
22 import javax.xml.transform.sax.TransformerHandler JavaDoc;
23
24 import org.apache.avalon.framework.activity.Initializable;
25 import org.apache.avalon.framework.component.Component;
26 import org.apache.avalon.framework.logger.AbstractLogEnabled;
27 import org.apache.avalon.framework.thread.ThreadSafe;
28 import org.w3c.dom.Document JavaDoc;
29
30 /**
31  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
32  * @version CVS $Revision: 1.5 $ $Date: 2004/02/28 11:47:31 $
33  * @avalon.component
34  */

35 public class DefaultDOMHandlerFactory
36     extends AbstractLogEnabled
37     implements DOMHandlerFactory, Initializable, Component, ThreadSafe
38 {
39     private final SAXTransformerFactory JavaDoc m_transformerFactory = (SAXTransformerFactory JavaDoc)SAXTransformerFactory.newInstance();
40     private final DocumentBuilderFactory JavaDoc m_documentBuilderFactory = DocumentBuilderFactory.newInstance();
41     private DocumentBuilder JavaDoc m_documentBuilder;
42
43     public void initialize()
44         throws Exception JavaDoc
45     {
46         m_documentBuilderFactory.setNamespaceAware( true );
47         m_documentBuilder = m_documentBuilderFactory.newDocumentBuilder();
48     }
49
50     public DOMHandler createDOMHandler()
51         throws Exception JavaDoc
52     {
53         final Document JavaDoc document = m_documentBuilder.newDocument();
54         return createDOMHandler( document );
55     }
56
57     public DOMHandler createDOMHandler( final Document JavaDoc document )
58         throws Exception JavaDoc
59     {
60         final TransformerHandler JavaDoc transformerHandler =
61             m_transformerFactory.newTransformerHandler();
62         return new DefaultDOMHandler( transformerHandler, document );
63     }
64 }
65
Popular Tags