KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > serialize > SerializerFactory


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 /*
17  * $Id: SerializerFactory.java,v 1.10 2004/02/16 20:27:14 minchau Exp $
18  */

19 package org.apache.xalan.serialize;
20
21 import java.io.IOException JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.io.Writer JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 import org.w3c.dom.Node JavaDoc;
27 import org.xml.sax.ContentHandler JavaDoc;
28
29 /**
30  * Factory for creating serializers.
31  * @deprecated The new class to use is
32  * org.apache.xml.serializer.SerializerFactory
33  */

34 public abstract class SerializerFactory
35 {
36
37     private SerializerFactory()
38     {
39     }
40     /**
41      * Returns a serializer for the specified output method. Returns
42      * null if no implementation exists that supports the specified
43      * output method. For a list of the default output methods see
44      * {@link Method}.
45      *
46      * @param format The output format
47      * @return A suitable serializer, or null
48      * @throws IllegalArgumentException (apparently -sc) if method is
49      * null or an appropriate serializer can't be found
50      * @throws WrappedRuntimeException (apparently -sc) if an
51      * exception is thrown while trying to find serializer
52      * @deprecated Use org.apache.xml.serializer.SerializerFactory
53      */

54     public static Serializer getSerializer(Properties JavaDoc format)
55     {
56         org.apache.xml.serializer.Serializer ser;
57         ser = org.apache.xml.serializer.SerializerFactory.getSerializer(format);
58         SerializerFactory.SerializerWrapper si = new SerializerWrapper(ser);
59         return si;
60
61     }
62     
63     /**
64      * This class just exists to wrap a new Serializer in the new package by
65      * an old one.
66      * @deprecated
67      */

68
69     private static class SerializerWrapper implements Serializer
70     {
71         private final org.apache.xml.serializer.Serializer m_serializer;
72         private DOMSerializer m_old_DOMSerializer;
73
74         SerializerWrapper(org.apache.xml.serializer.Serializer ser)
75         {
76             m_serializer = ser;
77
78         }
79
80         public void setOutputStream(OutputStream JavaDoc output)
81         {
82             m_serializer.setOutputStream(output);
83         }
84
85         public OutputStream JavaDoc getOutputStream()
86         {
87             return m_serializer.getOutputStream();
88         }
89
90         public void setWriter(Writer JavaDoc writer)
91         {
92             m_serializer.setWriter(writer);
93         }
94
95         public Writer JavaDoc getWriter()
96         {
97             return m_serializer.getWriter();
98         }
99
100         public void setOutputFormat(Properties JavaDoc format)
101         {
102             m_serializer.setOutputFormat(format);
103         }
104
105         public Properties JavaDoc getOutputFormat()
106         {
107             return m_serializer.getOutputFormat();
108         }
109
110         public ContentHandler JavaDoc asContentHandler() throws IOException JavaDoc
111         {
112             return m_serializer.asContentHandler();
113         }
114
115         /**
116          * @return an old style DOMSerializer that wraps a new one.
117          * @see org.apache.xalan.serialize.Serializer#asDOMSerializer()
118          */

119         public DOMSerializer asDOMSerializer() throws IOException JavaDoc
120         {
121             if (m_old_DOMSerializer == null)
122             {
123                 m_old_DOMSerializer =
124                     new DOMSerializerWrapper(m_serializer.asDOMSerializer());
125             }
126             return m_old_DOMSerializer;
127         }
128         /**
129          * @see org.apache.xalan.serialize.Serializer#reset()
130          */

131         public boolean reset()
132         {
133             return m_serializer.reset();
134         }
135
136     }
137
138     /**
139      * This class just wraps a new DOMSerializer with an old style one for
140      * migration purposes.
141   *
142      */

143     private static class DOMSerializerWrapper implements DOMSerializer
144     {
145         private final org.apache.xml.serializer.DOMSerializer m_dom;
146         DOMSerializerWrapper(org.apache.xml.serializer.DOMSerializer domser)
147         {
148             m_dom = domser;
149         }
150
151         public void serialize(Node JavaDoc node) throws IOException JavaDoc
152         {
153             m_dom.serialize(node);
154         }
155     }
156
157 }
158
Popular Tags