KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > mail > EditMailFactoryAction


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EditMailFactoryAction.java,v 1.3 2004/03/19 14:31:49 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.mail;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collections JavaDoc;
30 import java.util.Enumeration JavaDoc;
31 import java.util.Properties JavaDoc;
32
33 import javax.management.ObjectName JavaDoc;
34
35 import org.objectweb.jonas.jmx.JonasManagementRepr;
36 import org.objectweb.jonas.jmx.JonasObjectName;
37 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
38 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
39 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
40
41 /**
42  * Helper for actions for management of Mail Factories
43  * @author Adriana Danes
44  */

45 public abstract class EditMailFactoryAction extends JonasBaseAction {
46
47     // Populate the MailFactory form
48
void populate(ObjectName JavaDoc pObjectName, MailFactoryForm pForm) throws Exception JavaDoc {
49         // Set configuration attributes
50
// - get the jndi name
51
pForm.setJndiName(getStringAttribute(pObjectName, "Name"));
52         // - get authentication properties
53
Properties JavaDoc authProps = (Properties JavaDoc)JonasManagementRepr.getAttribute(pObjectName, "AuthenticationProperties");
54         String JavaDoc username = (String JavaDoc) authProps.getProperty("mail.authentication.username");
55         pForm.setUsername(username);
56         String JavaDoc password = (String JavaDoc) authProps.getProperty("mail.authentication.password");
57         pForm.setPassword(password);
58
59         // - get the mail session properties
60
Properties JavaDoc sessionProps = (Properties JavaDoc)JonasManagementRepr.getAttribute(pObjectName, "SessionProperties");
61         StringBuffer JavaDoc bufSessionProps = new StringBuffer JavaDoc();
62         String JavaDoc propName = null;
63         String JavaDoc propValue;
64         for (Enumeration JavaDoc propNames = sessionProps.propertyNames() ; propNames.hasMoreElements() ;) {
65             propName = (String JavaDoc) propNames.nextElement();
66             propValue = sessionProps.getProperty(propName);
67             bufSessionProps.append(propName);
68             bufSessionProps.append("=");
69             bufSessionProps.append(propValue);
70             bufSessionProps.append(",");
71             bufSessionProps.append("\n");
72         }
73         if (!sessionProps.isEmpty()) {
74             // delete the last 2 chars (, and \n)
75
bufSessionProps.delete(bufSessionProps.length() - 2, bufSessionProps.length() - 1);
76         } else {
77             // Actually no chars in sessionPropsBuf
78
bufSessionProps.append("mail.host=");
79         }
80         String JavaDoc sSessionProps = new String JavaDoc(bufSessionProps);
81         pForm.setSessionProps(sSessionProps);
82
83         // Set list of EJBs which use this mail factory
84
ArrayList JavaDoc al = new ArrayList JavaDoc();
85         String JavaDoc[] asParam = new String JavaDoc[1];
86         String JavaDoc[] asSignature = new String JavaDoc[1];
87         asSignature[0] = "java.lang.String";
88         asParam[0] = pForm.getJndiName();
89         ObjectName JavaDoc oObjectName = JonasObjectName.ejbService();
90         if (JonasManagementRepr.isRegistered(oObjectName) == true) {
91             java.util.Iterator JavaDoc it = ((java.util.Set JavaDoc) JonasManagementRepr.invoke(
92                                                                                 oObjectName,
93                                                                                 "getMailFactoryDependence",
94                                                                                 asParam,
95                                                                                 asSignature)).iterator();
96             while (it.hasNext()) {
97                 al.add(new EjbItem((ObjectName JavaDoc) it.next()));
98             }
99             // Sort by name
100
Collections.sort(al, new EjbItemByNameComparator());
101         }
102
103         // Set list in form
104
pForm.setListUsedByEjb(al);
105     }
106
107     // Set the specific properties of a MimePartDataSource
108
void setMimePartProps(ObjectName JavaDoc pObjectName, MailFactoryForm pForm) throws Exception JavaDoc {
109         Properties JavaDoc mimepartProps = (Properties JavaDoc)JonasManagementRepr.getAttribute(pObjectName, "MimeMessageProperties");
110
111         String JavaDoc to = (String JavaDoc) mimepartProps.getProperty("mail.to");
112         pForm.setTo(to);
113
114         String JavaDoc subject = (String JavaDoc) mimepartProps.getProperty("mail.subject");
115         pForm.setSubject(subject);
116
117         String JavaDoc cc = (String JavaDoc) mimepartProps.getProperty("mail.cc");
118         pForm.setCc(cc);
119
120         String JavaDoc bcc = (String JavaDoc) mimepartProps.getProperty("mail.bcc");
121         pForm.setBcc(bcc);
122     }
123 }
124
Popular Tags