001: package org.objectweb.jonas.webapp.jonasadmin.jonasmqconnect;
002:
003: import java.io.IOException;
004: import java.util.ArrayList;
005: import java.util.Collections;
006: import java.util.ListIterator;
007:
008: import javax.management.ObjectName;
009: import javax.servlet.ServletException;
010: import javax.servlet.http.HttpServletRequest;
011: import javax.servlet.http.HttpServletResponse;
012:
013: import org.apache.struts.action.ActionForm;
014: import org.apache.struts.action.ActionForward;
015: import org.apache.struts.action.ActionMapping;
016: import org.objectweb.jonas.jmx.JonasManagementRepr;
017: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
018: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
019: import org.objectweb.jonas.webapp.jonasadmin.jonasmqconnect.util.ItemDestination;
020: import org.objectweb.jonas.webapp.jonasadmin.jonasmqconnect.util.MqObjectNames;
021: import org.objectweb.jonas.webapp.jonasadmin.jonasmqconnect.util.PropertiesComparator;
022: import org.objectweb.jonas.webapp.jonasadmin.jonasmqconnect.util.PropertiesUtil;
023: import org.objectweb.jonas.webapp.jonasadmin.jonasmqconnect.util.Property;
024:
025: public class DestinationEditAction extends JonasBaseAction {
026:
027: public ActionForward executeAction(ActionMapping mapping,
028: ActionForm form, HttpServletRequest request,
029: HttpServletResponse response) throws IOException,
030: ServletException {
031:
032: DestinationEditForm fBean = (DestinationEditForm) form;
033: String jndiName = fBean.getJndiName();
034: String operation = fBean.getOperation();
035: ArrayList properties = new ArrayList();
036: ArrayList statProperties = new ArrayList();
037: ObjectName mbName;
038:
039: WhereAreYou oWhere = (WhereAreYou) request.getSession()
040: .getAttribute(WhereAreYou.SESSION_NAME);
041: String serverName = oWhere.getCurrentJonasServerName();
042: String domainName = oWhere.getCurrentDomainName();
043:
044: /*
045: * Get the connector name
046: */
047: String connector = request.getParameter("connector");
048: if (connector == null) {
049: connector = (String) m_Session.getAttribute("mqconnector");
050: } else {
051: m_Session.setAttribute("mqconnector", connector);
052: }
053:
054: try {
055:
056: /*
057: * FWA BEGIN : get the exact ObjectName of the destination
058: */
059: /* */
060: mbName = MqObjectNames.getDestinationON(domainName,
061: jndiName, connector);
062:
063: //domain*jmq1*jonasmqconnect*jonasmqconnector*<myconnector>*destination*<mydestination>
064: // Force the node selection in tree
065: String nodeName = "domain" + WhereAreYou.NODE_SEPARATOR
066: + serverName + WhereAreYou.NODE_SEPARATOR
067: + "jonasmqconnect" + WhereAreYou.NODE_SEPARATOR
068: + "jonasmqconnector" + WhereAreYou.NODE_SEPARATOR
069: + connector + WhereAreYou.NODE_SEPARATOR
070: + "destination" + WhereAreYou.NODE_SEPARATOR
071: + jndiName;
072: m_WhereAreYou.selectNameNode(nodeName, true);
073:
074: /*
075: * FWA END
076: */
077:
078: boolean isTopic = ((Boolean) JonasManagementRepr
079: .getAttribute(mbName, "IsTopic", serverName))
080: .booleanValue();
081: fBean.setIsTopic(isTopic);
082: properties.add(new Property("JndiName", jndiName,
083: "JndiName"));
084: properties.add(new Property("Type", (isTopic) ? "Topic"
085: : "Queue", "Type"));
086:
087: /*
088: * FWA commented out
089: */
090: /*
091: * TODO : check why are ALL OF THESE properties out.
092: * - Class: OK. it's a java class
093: * - Refernce: OK. Sums all of the properties
094: * - why Version ?
095: * - Why Expiry ?
096: */
097: String[] propertiesToSkip = new String[] { "Class",
098: "Expiry", "Reference", "Version" };
099: properties = PropertiesUtil.getJMSObjectProperties(mbName,
100: ((isTopic) ? "Topic" : "Queue"), "getProperty",
101: propertiesToSkip, serverName, domainName);
102:
103: /*
104: * FWA end
105: */
106: if (!isTopic) {
107: int currentDepth = ((Integer) JonasManagementRepr
108: .getAttribute(mbName, "CurrentDepth",
109: serverName)).intValue();
110: int maxQueueDepth = ((Integer) JonasManagementRepr
111: .getAttribute(mbName, "MaxQueueDepth",
112: serverName)).intValue();
113: int inputCount = ((Integer) JonasManagementRepr
114: .getAttribute(mbName, "InputCount", serverName))
115: .intValue();
116: int outputCount = ((Integer) JonasManagementRepr
117: .getAttribute(mbName, "OutputCount", serverName))
118: .intValue();
119:
120: statProperties
121: .add(new Property(
122: "CurrentDepth",
123: "" + currentDepth,
124: m_Resources
125: .getMessage("label.joansmqconnect.destination.currentdepth")));
126: statProperties
127: .add(new Property(
128: "MaxQueueDepth",
129: "" + maxQueueDepth,
130: m_Resources
131: .getMessage("label.joansmqconnect.destination.maxqueuedepth")));
132: statProperties
133: .add(new Property(
134: "InputCount",
135: "" + inputCount,
136: m_Resources
137: .getMessage("label.joansmqconnect.destination.inputcount")));
138: statProperties
139: .add(new Property(
140: "OutputCount",
141: "" + outputCount,
142: m_Resources
143: .getMessage("label.joansmqconnect.destination.outputcount")));
144: }
145: if ("apply".equals(operation)) {
146: for (int i = 0; i < properties.size(); i++) {
147: Property property = (Property) properties.get(i);
148: property.setValue(request.getParameter(property
149: .getName()));
150: }
151:
152: PropertiesUtil.setClassProperties(mbName, /* FWA - commented out: mqClass, */
153: "setProperty", properties, serverName);
154: properties = PropertiesUtil.getJMSObjectProperties(
155: mbName, ((isTopic) ? "Topic" : "Queue"),
156: "getProperty", propertiesToSkip, serverName,
157: domainName);
158: /* FWA - commented out: properties = PropertiesUtil.getClassProperties(mbName, mqClass,
159: "getProperty", new String []{"Version"}, serverName);
160: */
161: }
162: if ("clearQueue".equals(operation)) {
163: Object[] params = {};
164: String[] signature = {};
165: JonasManagementRepr.invoke(mbName, "clearQueue",
166: params, signature, serverName);
167: fBean.setOperation("view");
168: }
169:
170: Collections.sort(properties, new PropertiesComparator());
171: } catch (Throwable t) {
172: addGlobalError(t);
173: saveErrors(request, m_Errors);
174: return (mapping.findForward("Global Error"));
175: }
176: fBean.setProperties(properties);
177: fBean.setStatProperties(statProperties);
178: return mapping.findForward("JonasMqConnectDestinationEdit");
179: }
180: }
|