KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConnectorConnectionPoolHandlers.java
26  *
27  * Created on November 26, 2003, 2:35 PM
28  */

29
30 package com.sun.enterprise.tools.admingui.handlers;
31
32 import java.util.EventObject JavaDoc;
33 import javax.servlet.http.HttpSession JavaDoc;
34 import javax.management.AttributeList JavaDoc;
35 import javax.management.Attribute JavaDoc;
36 import java.util.Properties JavaDoc;
37 import java.util.Enumeration JavaDoc;
38
39 import com.iplanet.jato.RequestContext;
40 import com.iplanet.jato.RequestManager;
41 import com.iplanet.jato.model.DefaultModel;
42 import com.iplanet.jato.view.View;
43 import com.iplanet.jato.view.ViewBean;
44 import com.iplanet.jato.model.ModelControlException;
45 import com.iplanet.jato.view.ContainerViewBase;
46 import com.iplanet.jato.view.ViewBase;
47 import com.iplanet.jato.view.html.SelectableGroup;
48 import com.iplanet.jato.view.html.OptionList;
49
50 import com.sun.enterprise.tools.guiframework.view.DescriptorContainerView;
51 import com.sun.enterprise.tools.guiframework.view.HandlerContext;
52 import com.sun.enterprise.tools.guiframework.exception.FrameworkException;
53 import com.sun.enterprise.tools.guiframework.model.ModelManager;
54 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor;
55
56 import com.sun.web.ui.model.CCActionTableModelInterface;
57 import com.sun.enterprise.tools.admingui.util.MBeanUtil;
58
59 /**
60  *
61  * @author sirajg
62  */

63 public class ConnectorConnectionPoolHandlers {
64     
65     public static final String JavaDoc PROPERTY_NAME = "propertyName";
66     public static final String JavaDoc PROPERTY_VALUE = "propertyValue";
67     
68     /* called from step2, to get values from step1 */
69     public void getValuesFromStep1(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException {
70         View view = handlerCtx.getView();
71     DescriptorContainerView descView = (DescriptorContainerView)(((ViewBase)view));
72     ViewDescriptor vd = descView.getViewDescriptor();
73     HttpSession JavaDoc session = RequestManager.getSession();
74         DefaultModel step1Model = (DefaultModel)(session.getValue("connectorPoolStep1.model"));
75         descView.setDisplayFieldValue("Name", step1Model.getValue("Name"));
76         descView.setDisplayFieldValue("ResourceAdapter", step1Model.getValue("ResourceAdapter"));
77         descView.setDisplayFieldValue("ConnectionDefinition", step1Model.getValue("ConnectionDefinition"));
78     }
79     
80
81     /* gets default properties for given resource adapter and connectiondefinition */
82     public void populateDefaultProperties(RequestContext ctx, HandlerContext handlerCtx)
83             throws ModelControlException {
84         View view = handlerCtx.getView();
85     DescriptorContainerView descView = (DescriptorContainerView)(((ViewBase)view));
86         DescriptorContainerView parent = (DescriptorContainerView)descView.getParent();
87         String JavaDoc connectionDefinition = (String JavaDoc)parent.getDisplayFieldValue("ConnectionDefinition");
88         String JavaDoc resourceAdapter = (String JavaDoc)parent.getDisplayFieldValue("ResourceAdapter");
89         AttributeList JavaDoc attrList = new AttributeList JavaDoc();
90         attrList.add(new Attribute JavaDoc("resource-adapter-name", resourceAdapter));
91         attrList.add(new Attribute JavaDoc("connection-definition-name", connectionDefinition));
92         Object JavaDoc[] params = new Object JavaDoc[]{attrList};
93         String JavaDoc[] types = new String JavaDoc[]{"javax.management.AttributeList"};
94         
95         Properties JavaDoc properties =
96                 (Properties JavaDoc)MBeanUtil.invoke("com.sun.appserv:type=resources,category=config",
97                                  "getMCFConfigProps",
98                                  params, types );
99         CCActionTableModelInterface model =
100             (CCActionTableModelInterface)handlerCtx.getInputValue("propertiesModel");
101         ((DefaultModel)model).clear();
102         if (properties == null)
103             return;
104         model.beforeFirst();
105         Enumeration JavaDoc propertyNames = properties.propertyNames();
106         while(propertyNames.hasMoreElements()){
107             model.appendRow();
108             String JavaDoc name = (String JavaDoc)propertyNames.nextElement();
109             model.setValue(PROPERTY_NAME, name);
110             model.setValue(PROPERTY_VALUE, properties.getProperty(name));
111             model.setRowSelected(false);
112         }
113     }
114
115     /* gets connectiondefinition for given resource adapter */
116     public void populateConnectionDefinitions(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException {
117         View view = handlerCtx.getView();
118         // the child should be something like: com.sun.web.ui.view.html.CCDropDownMenu
119
SelectableGroup dropDownChild = (SelectableGroup) view;
120         // get the parent container of the dropdown
121
DescriptorContainerView parent = (DescriptorContainerView) dropDownChild.getParent();
122         String JavaDoc resAdapter = (String JavaDoc)parent.getDisplayFieldValue("ResourceAdapter");
123         Object JavaDoc[] params = {resAdapter};
124         String JavaDoc[] types = {"java.lang.String"};
125         String JavaDoc[] connectionDefinitions =
126                 (String JavaDoc[])MBeanUtil.invoke("com.sun.appserv:type=resources,category=config",
127                                  "getConnectionDefinitionNames",
128                                  params, types );
129         if (connectionDefinitions == null)
130             return;
131         OptionList dropDownMenuOptions = new OptionList(connectionDefinitions, connectionDefinitions ); // label and values
132
dropDownChild.setOptions(dropDownMenuOptions);
133     }
134
135     /* if default properties should be reloaded, sets 'connectorPoolStep3.areDefaultPropertiesLoaded'
136      * to true, otherwise to false */

137     public void areDefaultPropertiesLoaded(RequestContext ctx, HandlerContext handlerCtx) throws ModelControlException {
138         View view = handlerCtx.getView();
139     DescriptorContainerView descView = (DescriptorContainerView)(((ViewBase)view));
140         DescriptorContainerView parent = (DescriptorContainerView)descView.getParent();
141         String JavaDoc newConnectionDefinition = (String JavaDoc)parent.getDisplayFieldValue("ConnectionDefinition");
142         HttpSession JavaDoc session = RequestManager.getSession();
143         String JavaDoc oldConnectionDefinition = (String JavaDoc)session.getAttribute("connectorPoolStep3.ConnectionDefinition");
144         if (oldConnectionDefinition == null ||
145             !oldConnectionDefinition .equals(newConnectionDefinition)) {
146             ctx.getRequest().setAttribute("connectorPoolStep3.areDefaultPropertiesLoaded", "false");
147         }
148         else {
149             ctx.getRequest().setAttribute("connectorPoolStep3.areDefaultPropertiesLoaded", "true");
150         }
151         session.setAttribute("connectorPoolStep3.ConnectionDefinition", newConnectionDefinition);
152     }
153     
154 }
155
Popular Tags