EditMailFactoryAction.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: EditMailFactoryAction.java,v 1.3 2004/03/19 14:31:49 sauthieg Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 package org.objectweb.jonas.webapp.jonasadmin.service.mail;
00027 
00028 import java.util.ArrayList;
00029 import java.util.Collections;
00030 import java.util.Enumeration;
00031 import java.util.Properties;
00032 
00033 import javax.management.ObjectName;
00034 
00035 import org.objectweb.jonas.jmx.JonasManagementRepr;
00036 import org.objectweb.jonas.jmx.JonasObjectName;
00037 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
00038 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
00039 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
00040 
00045 public abstract class EditMailFactoryAction extends JonasBaseAction {
00046 
00047     // Populate the MailFactory form
00048     void populate(ObjectName pObjectName, MailFactoryForm pForm) throws Exception {
00049         // Set configuration attributes
00050         // - get the jndi name
00051         pForm.setJndiName(getStringAttribute(pObjectName, "Name"));
00052         // - get authentication properties
00053         Properties authProps = (Properties)JonasManagementRepr.getAttribute(pObjectName, "AuthenticationProperties");
00054         String username = (String) authProps.getProperty("mail.authentication.username");
00055         pForm.setUsername(username);
00056         String password = (String) authProps.getProperty("mail.authentication.password");
00057         pForm.setPassword(password);
00058 
00059         // - get the mail session properties
00060         Properties sessionProps = (Properties)JonasManagementRepr.getAttribute(pObjectName, "SessionProperties");
00061         StringBuffer bufSessionProps = new StringBuffer();
00062         String propName = null;
00063         String propValue;
00064         for (Enumeration propNames = sessionProps.propertyNames() ; propNames.hasMoreElements() ;) {
00065             propName = (String) propNames.nextElement();
00066             propValue = sessionProps.getProperty(propName);
00067             bufSessionProps.append(propName);
00068             bufSessionProps.append("=");
00069             bufSessionProps.append(propValue);
00070             bufSessionProps.append(",");
00071             bufSessionProps.append("\n");
00072         }
00073         if (!sessionProps.isEmpty()) {
00074             // delete the last 2 chars (, and \n)
00075             bufSessionProps.delete(bufSessionProps.length() - 2, bufSessionProps.length() - 1);
00076         } else {
00077             // Actually no chars in sessionPropsBuf
00078             bufSessionProps.append("mail.host=");
00079         }
00080         String sSessionProps = new String(bufSessionProps);
00081         pForm.setSessionProps(sSessionProps);
00082 
00083         // Set list of EJBs which use this mail factory
00084         ArrayList al = new ArrayList();
00085         String[] asParam = new String[1];
00086         String[] asSignature = new String[1];
00087         asSignature[0] = "java.lang.String";
00088         asParam[0] = pForm.getJndiName();
00089         ObjectName oObjectName = JonasObjectName.ejbService();
00090         if (JonasManagementRepr.isRegistered(oObjectName) == true) {
00091             java.util.Iterator it = ((java.util.Set) JonasManagementRepr.invoke(
00092                                                                                 oObjectName,
00093                                                                                 "getMailFactoryDependence",
00094                                                                                 asParam,
00095                                                                                 asSignature)).iterator();
00096             while (it.hasNext()) {
00097                 al.add(new EjbItem((ObjectName) it.next()));
00098             }
00099             // Sort by name
00100             Collections.sort(al, new EjbItemByNameComparator());
00101         }
00102 
00103         // Set list in form
00104         pForm.setListUsedByEjb(al);
00105     }
00106 
00107     // Set the specific properties of a MimePartDataSource
00108     void setMimePartProps(ObjectName pObjectName, MailFactoryForm pForm) throws Exception {
00109         Properties mimepartProps = (Properties)JonasManagementRepr.getAttribute(pObjectName, "MimeMessageProperties");
00110 
00111         String to = (String) mimepartProps.getProperty("mail.to");
00112         pForm.setTo(to);
00113 
00114         String subject = (String) mimepartProps.getProperty("mail.subject");
00115         pForm.setSubject(subject);
00116 
00117         String cc = (String) mimepartProps.getProperty("mail.cc");
00118         pForm.setCc(cc);
00119 
00120         String bcc = (String) mimepartProps.getProperty("mail.bcc");
00121         pForm.setBcc(bcc);
00122     }
00123 }

Generated on Tue Feb 15 15:05:33 2005 for JOnAS by  doxygen 1.3.9.1