KickJava   Java API By Example, From Geeks To Geeks.

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


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: ApplySessionMailFactoryAction.java,v 1.5 2004/03/19 14:31:49 sauthieg Exp $
23 * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.mail;
27
28 import java.io.IOException JavaDoc;
29 import java.util.Properties JavaDoc;
30
31 import javax.management.ObjectName JavaDoc;
32 import javax.servlet.ServletException JavaDoc;
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35
36 import org.apache.struts.action.ActionForm;
37 import org.apache.struts.action.ActionForward;
38 import org.apache.struts.action.ActionMapping;
39 import org.objectweb.jonas.jmx.J2eeObjectName;
40 import org.objectweb.jonas.jmx.JonasManagementRepr;
41 import org.objectweb.jonas.mail.MailServiceImpl;
42 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
43
44
45 /**
46  * @author Adriana Danes
47  */

48
49 public class ApplySessionMailFactoryAction extends JonasBaseAction {
50
51 // --------------------------------------------------------- Public Methods
52

53     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
54         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
55         throws IOException JavaDoc, ServletException JavaDoc {
56
57         // Form used
58
MailFactoryForm oForm = (MailFactoryForm) p_Form;
59         try {
60             // process form ....
61
// Mail factory form
62
String JavaDoc mfName = oForm.getMailFactoryName();
63             // Object name used
64
String JavaDoc domainName = m_WhereAreYou.getCurrentDomainName();
65             String JavaDoc serverName = m_WhereAreYou.getCurrentJonasServerName();
66             ObjectName JavaDoc oObjectName = J2eeObjectName.JavaMailResource(domainName, mfName, serverName,
67                                                                      MailServiceImpl.SESSION_PROPERTY_TYPE);
68             String JavaDoc jndiName = oForm.getJndiName();
69             String JavaDoc currentJndiName = getStringAttribute(oObjectName, "Name");
70             if (!jndiName.equals(currentJndiName)) {
71                 JonasManagementRepr.setAttribute(oObjectName, "Name", jndiName);
72             }
73
74             // apply session properties
75
String JavaDoc sSessionProps = oForm.getSessionProps().trim();
76             Properties JavaDoc pSessionProps = getPropsFromString(sSessionProps); // method in JonasBaseAction
77
JonasManagementRepr.setAttribute(oObjectName, "SessionProperties", pSessionProps);
78
79             // apply authentication properties if changed
80
String JavaDoc username = oForm.getUsername();
81             String JavaDoc password = oForm.getPassword();
82             Properties JavaDoc authProps = new Properties JavaDoc();
83             authProps.setProperty("mail.authentication.username", username);
84             authProps.setProperty("mail.authentication.password", password);
85             JonasManagementRepr.setAttribute(oObjectName, "AuthenticationProperties", authProps);
86
87             if (oForm.getAction().equals("save") == true) {
88                 JonasManagementRepr.invoke(oObjectName, "saveConfig", null, null);
89             }
90         }
91         catch (Throwable JavaDoc t) {
92             addGlobalError(t);
93             saveErrors(p_Request, m_Errors);
94             return (p_Mapping.findForward("Global Error"));
95         }
96         // Forward to the jsp and add the parameter 'name' with the good value.
97
return new ActionForward(p_Mapping.findForward("ActionEditSessionMailFactory").getPath() + "?name="
98             + oForm.getMailFactoryName());
99     }
100
101 }
102
Popular Tags