KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdic > desktop > internal > impl > WinMapiMailer


1 /*
2  * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
3  * subject to license terms.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the Lesser GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  */

20
21 package org.jdesktop.jdic.desktop.internal.impl;
22
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.ArrayList JavaDoc;
26
27 import org.jdesktop.jdic.desktop.Message;
28 import org.jdesktop.jdic.desktop.internal.LaunchFailedException;
29 import org.jdesktop.jdic.desktop.internal.MailerService;
30
31
32 /**
33  * Represents the Mapi implementation of MailerService interface for Windows.
34  *
35  * @see MailerService
36  * @see WinMozMailer
37  */

38 public class WinMapiMailer implements MailerService {
39     /**
40      * Opens the default system mailer
41      *
42      * @throws LaunchFailedException if the native system mailer is not found,
43      * or fails to be launched.
44      */

45     public void open() throws LaunchFailedException {
46         WinAPIWrapper.WinOpenMapiMailer(null, null, null, null, null, null);
47     }
48   
49     /**
50      * Opens the default system mailer with the information in msg filled in.
51      *
52      * @param msg the given Message object.
53      * @throws LaunchFailedException if the system mailer is not found, or fails
54      * to be launched.
55      */

56     public void open(Message msg) throws LaunchFailedException {
57         String JavaDoc[] toArray = ItrToStringArray(msg.getToAddrs());
58         String JavaDoc[] ccArray = ItrToStringArray(msg.getCcAddrs());
59         String JavaDoc[] bccArray = ItrToStringArray(msg.getBccAddrs());
60         String JavaDoc[] attachArray = ItrToStringArray(msg.getAttachments());
61
62         /* open message compose window for the system mailer by native method */
63         WinAPIWrapper.WinOpenMapiMailer(toArray, ccArray, bccArray, msg.getSubject(), msg.getBody(), attachArray);
64     }
65   
66     /**
67      * Converts List object to String[] to faciliate handling in native code
68      *
69      * @param inList input List
70      * @return String[] array contains inList's elements
71      */

72     private String JavaDoc[] ItrToStringArray(Iterator JavaDoc inItr) {
73         String JavaDoc[] stringArray = null;
74         int count = 0; /* count for array conversion */
75         List JavaDoc tmpList = null;
76         Iterator JavaDoc tmpItr = null;
77
78         if(inItr != null) {
79             tmpList = new ArrayList JavaDoc();
80             while(inItr.hasNext())
81                 tmpList.add(inItr.next());
82         }
83         if(tmpList != null) {
84             tmpItr = tmpList.iterator();
85             if(tmpItr != null) {
86                 stringArray = new String JavaDoc[tmpList.size()];
87                 while(tmpItr.hasNext()) {
88                     stringArray[count] = (String JavaDoc) tmpItr.next();
89                     count++;
90                 }
91             }
92         }
93
94         return stringArray;
95     }
96 }
97
Popular Tags