KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > mail > dsn > message_deliverystatus


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)message_deliverystatus.java 1.3 06/02/27
24  *
25  * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
26  */

27
28 package com.sun.mail.dsn;
29
30 import java.io.*;
31 import java.util.Properties JavaDoc;
32 import java.awt.datatransfer.DataFlavor JavaDoc;
33 import javax.activation.*;
34 import javax.mail.*;
35 import javax.mail.internet.*;
36
37
38 /**
39  * @version 1.3, 06/02/27
40  */

41 public class message_deliverystatus implements DataContentHandler {
42
43     ActivationDataFlavor ourDataFlavor = new ActivationDataFlavor(
44     DeliveryStatus.class,
45     "message/delivery-status",
46     "Delivery Status");
47
48     /**
49      * return the DataFlavors for this <code>DataContentHandler</code>
50      * @return The DataFlavors.
51      */

52     public DataFlavor JavaDoc[] getTransferDataFlavors() {
53     return new DataFlavor JavaDoc[] { ourDataFlavor };
54     }
55
56     /**
57      * return the Transfer Data of type DataFlavor from InputStream
58      * @param df The DataFlavor.
59      * @param ins The InputStream corresponding to the data.
60      * @return a Message object
61      */

62     public Object JavaDoc getTransferData(DataFlavor JavaDoc df, DataSource ds)
63                 throws IOException {
64     // make sure we can handle this DataFlavor
65
if (ourDataFlavor.equals(df))
66         return getContent(ds);
67     else
68         return null;
69     }
70     
71     /**
72      * Return the content.
73      */

74     public Object JavaDoc getContent(DataSource ds) throws IOException {
75     // create a new DeliveryStatus
76
try {
77         /*
78         Session session;
79         if (ds instanceof MessageAware) {
80         javax.mail.MessageContext mc =
81             ((MessageAware)ds).getMessageContext();
82         session = mc.getSession();
83         } else {
84         // Hopefully a rare case. Also hopefully the application
85         // has created a default Session that can just be returned
86         // here. If not, the one we create here is better than
87         // nothing, but overall not a really good answer.
88         session = Session.getDefaultInstance(new Properties(), null);
89         }
90         return new DeliveryStatus(session, ds.getInputStream());
91         */

92         return new DeliveryStatus(ds.getInputStream());
93     } catch (MessagingException me) {
94         throw new IOException("Exception creating DeliveryStatus in " +
95             "message/devliery-status DataContentHandler: " +
96             me.toString());
97     }
98     }
99     
100     /**
101      */

102     public void writeTo(Object JavaDoc obj, String JavaDoc mimeType, OutputStream os)
103             throws IOException {
104     // if the object is a DeliveryStatus, we know how to write that out
105
if (obj instanceof DeliveryStatus) {
106         DeliveryStatus ds = (DeliveryStatus)obj;
107         try {
108         ds.writeTo(os);
109         } catch (MessagingException me) {
110         throw new IOException(me.toString());
111         }
112         
113     } else {
114         throw new IOException("unsupported object");
115     }
116     }
117 }
118
Popular Tags