001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2003-2004 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: ListRegistryAction.java 9764 2006-10-19 07:53:13Z durieuxp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.jonasserver;
025:
026: import java.io.IOException;
027: import java.util.Iterator;
028: import java.util.List;
029: import java.util.Vector;
030:
031: import javax.management.ObjectName;
032: import javax.servlet.ServletException;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.http.HttpServletResponse;
035:
036: import org.apache.struts.action.ActionForm;
037: import org.apache.struts.action.ActionForward;
038: import org.apache.struts.action.ActionMapping;
039: import org.objectweb.jonas.jmx.J2eeObjectName;
040: import org.objectweb.jonas.jmx.JonasManagementRepr;
041: import org.objectweb.jonas.jmx.JonasObjectName;
042: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
043: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
044:
045: /**
046: * @author Adriana Danes <br>
047: * Contributor Michel-Ange Anton
048: */
049: public class ListRegistryAction extends JonasBaseAction {
050: /**
051: * Execute action for registry management
052: * @param pMapping mapping info
053: * @param pForm form object
054: * @param pRequest HTTP request
055: * @param pResponse HTTP response
056: *
057: * @return An <code>ActionForward</code> instance or <code>null</code>
058: *
059: * @exception IOException if an input/output error occurs
060: * @exception ServletException if a servlet exception occurs
061: */
062: public ActionForward executeAction(ActionMapping pMapping,
063: ActionForm pForm, HttpServletRequest pRequest,
064: HttpServletResponse pResponse) throws IOException,
065: ServletException {
066:
067: // Force the node selected in tree
068: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER),
069: true);
070: // Form used
071: JndiResourcesForm oForm = new JndiResourcesForm();
072:
073: String sDomainName = m_WhereAreYou.getCurrentDomainName();
074:
075: try {
076: String pDomainName = m_WhereAreYou.getCurrentDomainName();
077: String pServerName = m_WhereAreYou
078: .getCurrentJonasServerName();
079: ObjectName resourceOn = null; // used if only one JNDI resource
080: ObjectName ons = J2eeObjectName.JNDIResources(pDomainName,
081: pServerName);
082: Iterator itNames = JonasManagementRepr.queryNames(ons,
083: pServerName).iterator();
084: List lNames = null;
085: int nbJNDIResources = 0;
086: while (itNames.hasNext()) {
087: JndiResourceItem item = new JndiResourceItem();
088: ObjectName itOn = (ObjectName) itNames.next();
089: item.setProviderUrl(getStringAttribute(itOn,
090: "ProviderURL"));
091: item.setProtocol(getStringAttribute(itOn, "Name"));
092: item.setResourceON(itOn.toString());
093: lNames = getListAttribute(itOn, "Names");
094: oForm.addProvider(item);
095: resourceOn = itOn;
096: nbJNDIResources++;
097: }
098:
099: if (nbJNDIResources == 1) {
100: // test if the resource corresponds to the CMI protocol
101: // in this case, the resource name is 'cmi'
102: // and we have a CMI type MBean
103: boolean cmi = false;
104: ObjectName cmiOn = new ObjectName(sDomainName
105: + ":type=CMI,J2EEServer="
106: + m_WhereAreYou.getCurrentJonasServerName()
107: + ",name=CMI");
108: if (JonasAdminJmx.hasMBeanName(cmiOn, pServerName)) {
109: cmi = true;
110: }
111: if (cmi
112: && "cmi".equals(resourceOn
113: .getKeyProperty("name"))) {
114: List namesAndNodes = CmiRegistryResource
115: .getCmiRegistry(cmiOn, pServerName);
116: oForm.setVector(namesAndNodes);
117: } else {
118: oForm.setListNames(lNames);
119: }
120: oForm.setRegistryProtocol(getStringAttribute(
121: resourceOn, "Name"));
122: }
123: if (JonasManagementRepr.isRegistered(JonasObjectName
124: .webContainerService(), pServerName)) {
125: oForm.setPresentServletContainer(true);
126: } else {
127: oForm.setPresentServletContainer(false);
128: }
129: pRequest.setAttribute("jndiResourcesForm", oForm);
130: } catch (Throwable t) {
131: addGlobalError(t);
132: saveErrors(pRequest, m_Errors);
133: return (pMapping.findForward("Global Error"));
134: }
135: // Forward to the jsp.
136: return (pMapping.findForward("Registry"));
137: }
138:
139: }
|