001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ApplyDestinationAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.joramplatform;
025:
026: import java.io.IOException;
027: import java.util.Set;
028:
029: import javax.management.InstanceNotFoundException;
030: import javax.management.ObjectName;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.objectweb.jonas.jmx.JonasManagementRepr;
039: import org.objectweb.jonas.jmx.JoramObjectName;
040: import org.objectweb.jonas.webapp.jonasadmin.deploy.BaseDeployAction;
041:
042: /**
043: * @author Adriana Danes
044: * Creation of new destinations
045: */
046:
047: public class ApplyDestinationAction extends BaseDeployAction {
048:
049: // --------------------------------------------------------- Public Methods
050:
051: public ActionForward executeAction(ActionMapping p_Mapping,
052: ActionForm p_Form, HttpServletRequest p_Request,
053: HttpServletResponse p_Response) throws IOException,
054: ServletException {
055:
056: // Current JOnAS server
057: String jonasServerName = m_WhereAreYou
058: .getCurrentJonasServerName();
059:
060: // Form used
061: JoramDestinationForm oForm = (JoramDestinationForm) p_Form;
062: String idString = (String) m_Session.getAttribute("currentId");
063: Integer idInteger = (new Integer(idString));
064: int id = idInteger.intValue();
065:
066: try {
067: ObjectName oObjectName;
068: Set adapterOns = JonasManagementRepr.queryNames(
069: JoramObjectName.joramAdapter(), jonasServerName);
070: if (adapterOns.isEmpty()) {
071: throw new InstanceNotFoundException();
072: }
073: ObjectName joramAdapterON = (ObjectName) adapterOns
074: .iterator().next();
075: if (JonasManagementRepr.isRegistered(joramAdapterON,
076: jonasServerName)) {
077: oObjectName = joramAdapterON;
078: } else {
079: oObjectName = JoramObjectName.joramAdmin();
080: }
081:
082: Object[] asParam = { idInteger, oForm.getName() };
083: String[] asSignature = { "int", "java.lang.String" };
084: String type = oForm.getType();
085: if (type
086: .equals(m_Resources
087: .getMessage("label.joramplatform.destinations.queue"))) {
088: JonasManagementRepr.invoke(oObjectName, "createQueue",
089: asParam, asSignature, jonasServerName);
090: } else if (type
091: .equals(m_Resources
092: .getMessage("label.joramplatform.destinations.topic"))) {
093: JonasManagementRepr.invoke(oObjectName, "createTopic",
094: asParam, asSignature, jonasServerName);
095: }
096: refreshJoramTree(p_Request, idString);
097:
098: oForm.reset(p_Mapping, p_Request);
099:
100: } catch (Throwable t) {
101: addGlobalError(t);
102: saveErrors(p_Request, m_Errors);
103: return (p_Mapping.findForward("Global Error"));
104: }
105:
106: // Forward to the jsp.
107: return (p_Mapping.findForward("Create Joram Destination"));
108: }
109: }
|