KickJava   Java API By Example, From Geeks To Geeks.

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


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.components.logger.LogFactory;
20 import org.apache.axis.encoding.DeserializationContext;
21 import org.apache.commons.logging.Log;
22 import org.xml.sax.Attributes JavaDoc;
23 import org.xml.sax.SAXException JavaDoc;
24
25 import javax.activation.DataHandler JavaDoc;
26 import javax.mail.internet.MimeMultipart JavaDoc;
27
28 /**
29  * MimeMultipartDataHandler Deserializer
30  * @author Russell Butek (butek@us.ibm.com)
31  */

32 public class MimeMultipartDataHandlerDeserializer extends JAFDataHandlerDeserializer {
33     protected static Log log =
34             LogFactory.getLog(MimeMultipartDataHandlerDeserializer.class.getName());
35
36     public void startElement(String JavaDoc namespace, String JavaDoc localName,
37                              String JavaDoc prefix, Attributes JavaDoc attributes,
38                              DeserializationContext context)
39         throws SAXException JavaDoc {
40
41         super.startElement(namespace, localName, prefix, attributes, context);
42
43         if (getValue() instanceof DataHandler JavaDoc) {
44             try {
45                 DataHandler JavaDoc dh = (DataHandler JavaDoc) getValue();
46                 MimeMultipart JavaDoc mmp = new MimeMultipart JavaDoc(dh.getDataSource());
47                 if (mmp.getCount() == 0) {
48                     mmp = null;
49                 }
50                 setValue(mmp);
51             }
52             catch (Exception JavaDoc e) {
53                 throw new SAXException JavaDoc(e);
54             }
55         }
56     } // startElement
57
} // class MimeMultipartDataHandlerDeserializer
58
Popular Tags