KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > ser > SourceDataHandlerSerializer


1 /*
2  * Copyright 2001-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 package org.apache.axis.encoding.ser;
18
19 import org.apache.axis.attachments.SourceDataSource;
20 import org.apache.axis.components.logger.LogFactory;
21 import org.apache.axis.encoding.SerializationContext;
22 import org.apache.axis.utils.Messages;
23 import org.apache.commons.logging.Log;
24 import org.xml.sax.Attributes JavaDoc;
25
26 import javax.activation.DataHandler JavaDoc;
27 import javax.xml.namespace.QName JavaDoc;
28 import javax.xml.transform.stream.StreamSource JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 /**
32  * SourceDataHandler Serializer
33  * @author Russell Butek (butek@us.ibm.com)
34  */

35 public class SourceDataHandlerSerializer extends JAFDataHandlerSerializer {
36
37     protected static Log log =
38         LogFactory.getLog(SourceDataHandlerSerializer.class.getName());
39
40     /**
41      * Serialize a Source DataHandler quantity.
42      */

43     public void serialize(QName JavaDoc name, Attributes JavaDoc attributes,
44                           Object JavaDoc value, SerializationContext context)
45         throws IOException JavaDoc
46     {
47         if (value != null) {
48             if (!(value instanceof StreamSource JavaDoc)) {
49                 throw new IOException JavaDoc(Messages.getMessage("badSource",
50                         value.getClass().getName()));
51             }
52             DataHandler JavaDoc dh = new DataHandler JavaDoc(new SourceDataSource("source",
53                     "text/xml", (StreamSource JavaDoc) value));
54             super.serialize(name, attributes, dh, context);
55         }
56     } // serialize
57
} // class SourceDataHandlerSerializer
58
Popular Tags