KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > admingui > handlers > JmsHandlers


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * CommonHandlers.java
26  *
27  */

28
29 package com.sun.enterprise.tools.admingui.handlers;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.EventObject JavaDoc;
33 import java.util.StringTokenizer JavaDoc;
34 import java.util.Properties JavaDoc;
35 import java.util.Enumeration JavaDoc;
36
37 import com.iplanet.jato.RequestContext;
38 import com.iplanet.jato.RequestContextImpl;
39 import com.iplanet.jato.RequestManager;
40 import com.iplanet.jato.model.DefaultModel;
41 import com.iplanet.jato.model.Model;
42 import com.iplanet.jato.util.RootCauseException;
43 import com.iplanet.jato.view.ContainerView;
44 import com.iplanet.jato.view.ContainerViewBase;
45 import com.iplanet.jato.view.View;
46 import com.iplanet.jato.view.DisplayFieldImpl;
47 import com.iplanet.jato.view.ViewBase;
48 import com.iplanet.jato.view.ViewBean;
49 import com.iplanet.jato.view.html.SelectableGroup;
50 import com.iplanet.jato.view.html.OptionList;
51 import com.iplanet.jato.model.ModelControlException;
52
53 import javax.management.MBeanException JavaDoc;
54 import javax.management.ObjectName JavaDoc;
55 import javax.management.AttributeList JavaDoc;
56 import javax.management.Attribute JavaDoc;
57 import javax.servlet.ServletRequest JavaDoc;
58
59 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
60 import com.sun.enterprise.tools.guiframework.model.ModelManager;
61 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
62 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
63 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
64 import com.sun.enterprise.tools.guiframework.view.descriptors.CCActionTableDescriptor;
65 import com.sun.enterprise.tools.guiframework.view.event.BeforeCreateEvent;
66 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent;
67
68 import com.sun.web.ui.model.CCActionTableModelInterface;
69
70 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
71 import com.sun.enterprise.tools.admingui.util.Util;
72
73
74 public class JmsHandlers {
75
76     public static final String JavaDoc PROPERTY_NAME = "propertyName";
77     public static final String JavaDoc PROPERTY_VALUE = "propertyValue";
78     
79     public void loadJmsPhysicalDestinations(RequestContext ctx, HandlerContext handlerCtx) {
80     View view = handlerCtx.getView();
81     if (!(handlerCtx.getEvent() instanceof BeforeCreateEvent)) {
82         ViewDescriptor desc = (view instanceof DescriptorContainerView) ?
83         ((DescriptorContainerView)view).getViewDescriptor() :
84         (ViewDescriptor)null;
85         throw new FrameworkException("This handler is for 'beforeCreate'" +
86         " handlers only!", desc, view);
87     }
88             
89         ViewDescriptor desc = ((BeforeCreateEvent)handlerCtx.getEvent()).getViewDescriptor();
90         if (!(desc instanceof CCActionTableDescriptor)) {
91         throw new FrameworkException("Table model expected here", desc, view);
92         }
93         CCActionTableDescriptor ccDesc = (CCActionTableDescriptor)desc;
94         CCActionTableModelInterface model = ccDesc.getModel();
95         String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
96         String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
97         String JavaDoc configName = (String JavaDoc)handlerCtx.getInputValue("configName");
98         
99         ObjectName JavaDoc[] objectNames = null;
100         String JavaDoc [] params = {configName};
101         String JavaDoc [] types = {"java.lang.String"};
102         try{
103             objectNames = (ObjectName JavaDoc[])MBeanUtil.invoke(objectName, methodName, params, types);
104         }catch (Exception JavaDoc ex){
105             //There maybe problem connecting to the MQ server, just report the exception got from backend
106
handlerCtx.setOutputValue("hasError", "true");
107             Throwable JavaDoc upper = ex.getCause(); //bypass the FrameworkException
108
handlerCtx.setOutputValue("errorMsg", upper.getCause());
109             ex.printStackTrace();
110             return;
111         }
112         
113         if (objectNames == null) {
114             return; //nothing to load..
115
}
116         for (int i = 0; i < objectNames.length; i++) {
117             // getAttributes for the given objectName...
118
model.appendRow();
119             model.setValue("name", objectNames[i].getKeyProperty("destName"));
120             model.setValue("type", objectNames[i].getKeyProperty("destType"));
121         }
122     }
123     public void physicalDestinationActions(RequestContext ctx, HandlerContext handlerCtx) {
124     View view = handlerCtx.getView();
125     DescriptorContainerView descView = (DescriptorContainerView)(((ViewBase)view).getParentViewBean());
126     ViewDescriptor vd = descView.getViewDescriptor();
127     String JavaDoc childName = (String JavaDoc)vd.getParameter("tableChildName");
128     if(childName == null) {
129         throw new FrameworkException("deleteHandler: childName not specified", vd, view);
130     }
131         
132     ViewDescriptor tableDescriptor = vd.getChildDescriptor(childName);
133     if(tableDescriptor == null) {
134         throw new FrameworkException("deleteHandler: tableDescriptor is null", vd, view);
135     }
136     if(!(tableDescriptor instanceof CCActionTableDescriptor)) {
137         throw new FrameworkException("deleteHandler: tableDescriptor is of wrong type", tableDescriptor, view);
138     }
139         CCActionTableModelInterface model = ((CCActionTableDescriptor)tableDescriptor).getModel();
140     String JavaDoc methodName = (String JavaDoc)handlerCtx.getInputValue("methodName");
141     String JavaDoc objectName = (String JavaDoc)handlerCtx.getInputValue("objectName");
142     String JavaDoc target = (String JavaDoc)handlerCtx.getInputValue("target");
143     if(objectName == null) {
144         throw new FrameworkException("No ObjectName specified");
145     }
146     model.setRowSelectionType("multiple");
147     try {
148         model.beforeFirst();
149         // from the model, get the child that has the needed value...
150
while(model.next()) {
151         if (model.isRowSelected()) {
152                     Object JavaDoc[] params = new Object JavaDoc[]{
153                         model.getValue("name"),
154                         model.getValue("type"),
155                         target};
156                     String JavaDoc[] types = new String JavaDoc[]{
157                         "java.lang.String",
158                         "java.lang.String",
159                         "java.lang.String"};
160                     MBeanUtil.invoke(objectName, methodName, params, types);
161             model.setRowSelected(false);
162                 }
163             }
164     } catch (Exception JavaDoc ex) {
165         throw new FrameworkException(ex);
166         }
167     ContainerViewBase containerView = (ContainerViewBase)(tableDescriptor.getView(ctx).getParent());
168     containerView.removeChild(tableDescriptor.getName());
169     ((DefaultModel)model).clear();
170     }
171     
172     /*
173     public void getJmsConnectionStatus(RequestContext ctx, HandlerContext handlerCtx) {
174     View view = handlerCtx.getView();
175         DescriptorContainerView descView = (DescriptorContainerView)(view.getParent());
176         String objectName = "ias:type=connector-resource,category=config,jndi-name=" +
177             descView.getDisplayFieldValue("editKey");
178     try {
179         descView.setDisplayFieldValue("ResourceEnabled",
180         MBeanUtil.getAttribute(new ObjectName(objectName), "enabled"));
181     } catch (Exception ex) {
182         throw new FrameworkException(
183         ex, descView.getViewDescriptor(), view);
184     }
185     }
186     
187     public void setJmsConnectionStatus(RequestContext ctx, HandlerContext handlerCtx) {
188     View view = handlerCtx.getView();
189         DescriptorContainerView descView = (DescriptorContainerView)(view.getParent().getParent());
190         String objectName = "ias:type=connector-resource,category=config,jndi-name=" +
191             descView.getDisplayFieldValue("editKey");
192         Attribute attr =
193             new Attribute("enabled", descView.getDisplayFieldValue("ResourceEnabled"));
194         MBeanUtil.setAttribute(objectName, attr);
195     }
196     
197     */

198     
199 }
200
Popular Tags