1 25 26 package org.objectweb.jonas.webapp.jonasadmin.service.mail; 27 28 import java.util.ArrayList ; 29 import java.util.Collections ; 30 import java.util.Enumeration ; 31 import java.util.Properties ; 32 33 import javax.management.ObjectName ; 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 45 public abstract class EditMailFactoryAction extends JonasBaseAction { 46 47 void populate(ObjectName pObjectName, MailFactoryForm pForm) throws Exception { 49 pForm.setJndiName(getStringAttribute(pObjectName, "Name")); 52 Properties authProps = (Properties )JonasManagementRepr.getAttribute(pObjectName, "AuthenticationProperties"); 54 String username = (String ) authProps.getProperty("mail.authentication.username"); 55 pForm.setUsername(username); 56 String password = (String ) authProps.getProperty("mail.authentication.password"); 57 pForm.setPassword(password); 58 59 Properties sessionProps = (Properties )JonasManagementRepr.getAttribute(pObjectName, "SessionProperties"); 61 StringBuffer bufSessionProps = new StringBuffer (); 62 String propName = null; 63 String propValue; 64 for (Enumeration propNames = sessionProps.propertyNames() ; propNames.hasMoreElements() ;) { 65 propName = (String ) 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 bufSessionProps.delete(bufSessionProps.length() - 2, bufSessionProps.length() - 1); 76 } else { 77 bufSessionProps.append("mail.host="); 79 } 80 String sSessionProps = new String (bufSessionProps); 81 pForm.setSessionProps(sSessionProps); 82 83 ArrayList al = new ArrayList (); 85 String [] asParam = new String [1]; 86 String [] asSignature = new String [1]; 87 asSignature[0] = "java.lang.String"; 88 asParam[0] = pForm.getJndiName(); 89 ObjectName oObjectName = JonasObjectName.ejbService(); 90 if (JonasManagementRepr.isRegistered(oObjectName) == true) { 91 java.util.Iterator it = ((java.util.Set ) JonasManagementRepr.invoke( 92 oObjectName, 93 "getMailFactoryDependence", 94 asParam, 95 asSignature)).iterator(); 96 while (it.hasNext()) { 97 al.add(new EjbItem((ObjectName ) it.next())); 98 } 99 Collections.sort(al, new EjbItemByNameComparator()); 101 } 102 103 pForm.setListUsedByEjb(al); 105 } 106 107 void setMimePartProps(ObjectName pObjectName, MailFactoryForm pForm) throws Exception { 109 Properties mimepartProps = (Properties )JonasManagementRepr.getAttribute(pObjectName, "MimeMessageProperties"); 110 111 String to = (String ) mimepartProps.getProperty("mail.to"); 112 pForm.setTo(to); 113 114 String subject = (String ) mimepartProps.getProperty("mail.subject"); 115 pForm.setSubject(subject); 116 117 String cc = (String ) mimepartProps.getProperty("mail.cc"); 118 pForm.setCc(cc); 119 120 String bcc = (String ) mimepartProps.getProperty("mail.bcc"); 121 pForm.setBcc(bcc); 122 } 123 } 124 | Popular Tags |