001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.jbi.jsf.handlers;
038:
039: import com.sun.data.provider.FieldKey;
040: import com.sun.data.provider.RowKey;
041: import com.sun.data.provider.impl.ObjectListDataProvider;
042: import com.sun.enterprise.tools.admingui.util.GuiUtil;
043: import com.sun.jbi.jsf.bean.ListBean;
044: import com.sun.jbi.jsf.bean.Row;
045: import com.sun.jbi.jsf.bean.RuntimeConfigurationBean;
046: import com.sun.jbi.jsf.bean.SelectableTargetInfo;
047: import com.sun.jbi.jsf.bean.ShowBean;
048: import com.sun.jbi.jsf.bean.ServiceUnitBean;
049: import com.sun.jbi.jsf.bean.TargetBean;
050: import com.sun.jbi.jsf.util.BeanUtilities;
051: import com.sun.jbi.jsf.util.ClusterUtilities;
052: import com.sun.jbi.jsf.util.I18nUtilities;
053: import com.sun.jbi.jsf.util.JBILogger;
054: import com.sun.jbi.jsf.util.RuntimeMonitoringUtils;
055: import com.sun.jbi.jsf.util.SharedConstants;
056: import com.sun.jbi.ui.common.ServiceUnitInfo;
057: import com.sun.jsftemplating.annotation.Handler;
058: import com.sun.jsftemplating.annotation.HandlerInput;
059: import com.sun.jsftemplating.annotation.HandlerOutput;
060: import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
061: import com.sun.webui.jsf.component.Label;
062: import com.sun.webui.jsf.component.Property;
063: import com.sun.webui.jsf.component.PropertySheet;
064: import com.sun.webui.jsf.component.PropertySheetSection;
065: import com.sun.webui.jsf.component.StaticText;
066: import com.sun.webui.jsf.component.Table;
067: import com.sun.webui.jsf.component.TableColumn;
068: import com.sun.webui.jsf.component.TableRowGroup;
069: import java.util.ArrayList;
070: import java.util.Arrays;
071: import java.util.HashMap;
072: import java.util.Iterator;
073: import java.util.List;
074: import java.util.Properties;
075: import java.util.logging.Logger;
076: import javax.el.ValueExpression;
077: import javax.faces.context.FacesContext;
078: import javax.management.openmbean.CompositeData;
079: import javax.management.openmbean.CompositeType;
080: import javax.management.openmbean.TabularData;
081:
082: /**
083: * Provides jsftemplating handlers for List/Show tables
084: */
085: public class QueryHandlers {
086: public static final String TBL_PAGE_TYPE_BINDINGS_ENGINES = "bindingsEngines";
087: public static final String TBL_PAGE_TYPE_DEPLOYMENTS = "deployments";
088: public static final String TBL_PAGE_TYPE_LIBRARIES = "libraries";
089:
090: private static Logger sLog = JBILogger.getInstance();
091:
092: /**
093: * <p> This method sets the binding components and service engines
094: * component infos list into the TargetBean.
095: * <p> Input value: "targetName" -- Type: <code>java.lang.String</code></p>
096: * @param context The HandlerContext.
097: */
098: @Handler(id="jbiSetComponentsForTarget",input={@HandlerInput(name="targetName",type=String.class,required=true)})
099: public static void jbiSetComponentsForTarget(
100: HandlerContext handlerCtx) {
101: String targetName = (String) handlerCtx
102: .getInputValue("targetName");
103: sLog
104: .fine("QueryHandlers.jbiSetComponentsForTarget(...), targetName="
105: + targetName);
106: List componentsList = ClusterUtilities
107: .findBindingComponentsForTarget(targetName);
108: componentsList.addAll(ClusterUtilities
109: .findServiceEnginesForTarget(targetName));
110: TargetBean targetBean = BeanUtilities.getTargetBean();
111: sLog
112: .fine("QueryHandlers.jbiSetComponentsForTarget(...), componentsList="
113: + componentsList);
114: targetBean.setComponentsList(componentsList);
115: }
116:
117: /**
118: * <p> This method sets the service assemblies
119: * infos list into the TargetBean.
120: * <p> Input value: "targetName" -- Type: <code>java.lang.String</code></p>
121: * @param context The HandlerContext.
122: */
123: @Handler(id="jbiSetDeploymentsForTarget",input={@HandlerInput(name="targetName",type=String.class,required=true)})
124: public static void jbiSetDeploymentsForTarget(
125: HandlerContext handlerCtx) {
126: String targetName = (String) handlerCtx
127: .getInputValue("targetName");
128: sLog
129: .fine("QueryHandlers.jbiSetDeploymentsForTarget(...), targetName="
130: + targetName);
131: List deploymentsList = ClusterUtilities
132: .findServiceAssembliesForTarget(targetName);
133: TargetBean targetBean = BeanUtilities.getTargetBean();
134: targetBean.setDeploymentsList(deploymentsList);
135: }
136:
137: /**
138: * <p> This method sets the shared library component infos list
139: * into the TargetBean.
140: * <p> Input value: "targetName" -- Type: <code>java.lang.String</code></p>
141: * @param context The HandlerContext.
142: */
143: @Handler(id="jbiSetLibrariesForTarget",input={@HandlerInput(name="targetName",type=String.class,required=true)})
144: public static void jbiSetLibrariesForTarget(
145: HandlerContext handlerCtx) {
146: String targetName = (String) handlerCtx
147: .getInputValue("targetName");
148: sLog
149: .fine("QueryHandlers.jbiSetLibrariesForTarget(...), targetName="
150: + targetName);
151: List librariesList = ClusterUtilities
152: .findSharedLibrariesForTarget(targetName);
153: TargetBean targetBean = BeanUtilities.getTargetBean();
154: targetBean.setLibrariesList(librariesList);
155: }
156:
157: /**
158: * <p> This method filters a list of targets* to just those that have the
159: * "current" (ShowBean) component/deployment installed or deployed and sets
160: * the ShowBean's filteredTargetsList property. If this list is empty,
161: * the component/deploymens is installed/deployed to the 'domain' target only.
162: * <p> Input value: "allTargetsList" -- Type: <code>java.util.List</code></p>
163: * @param context The HandlerContext.
164: */
165: @Handler(id="jbiSetFilteredTargetsList",input={@HandlerInput(name="pageName",type=String.class,required=true),@HandlerInput(name="clustersList",type=java.util.List.class,required=true),@HandlerInput(name="serversList",type=java.util.List.class,required=true)})
166: public static void jbiSetFilteredTargetsList(
167: HandlerContext handlerCtx) {
168: List filteredTargetsList = new ArrayList();
169: String pageName = (String) handlerCtx.getInputValue("pageName");
170: List clustersList = (List) handlerCtx
171: .getInputValue("clustersList");
172: List serversList = (List) handlerCtx
173: .getInputValue("serversList");
174:
175: sLog
176: .fine("QueryHandlers.setFilteredTargetsList, handlerCtx.getInputValue(\"clustersList\")="
177: + clustersList
178: + ", serversList="
179: + serversList
180: + ", pageName=" + pageName);
181:
182: ShowBean showBean = BeanUtilities.getShowBean(); // implicit input
183:
184: List allTargetsList = new ArrayList();
185:
186: // add each cluster to the list in a property containing its name and type (cluster)
187: if (null != clustersList) {
188: Iterator clusters = clustersList.iterator();
189: while (clusters.hasNext()) {
190: String clusterName = (String) clusters.next();
191: Properties clusterProps = new Properties();
192: clusterProps.setProperty("name", clusterName);
193: clusterProps.setProperty("type", "cluster");
194: sLog
195: .fine("QueryHandlers.jbiSetFilteredTargetsList(...), adding clusterProps="
196: + clusterProps);
197: allTargetsList.add(clusterProps);
198: }
199: }
200:
201: // add each server to the list in a property containing its name and type (server)
202: if (null != serversList) {
203: Iterator servers = serversList.iterator();
204: while (servers.hasNext()) {
205: String serverName = (String) servers.next();
206: Properties serverProps = new Properties();
207: serverProps.setProperty("name", serverName);
208: serverProps.setProperty("type", "server");
209: sLog
210: .fine("QueryHandlers.jbiSetFilteredTargetsList(...), adding serverProps="
211: + serverProps);
212: allTargetsList.add(serverProps);
213: }
214: }
215:
216: // Depending on the page, set the filter state value
217: String filterState = SharedConstants.DROP_DOWN_TYPE_SHOW_ALL;
218: ArrayList filterStates = null;
219: if (pageName.equalsIgnoreCase(TBL_PAGE_TYPE_BINDINGS_ENGINES)) {
220: filterState = showBean.getFilterTargetComponentState();
221: filterStates = showBean.getFilterTargetComponentStates();
222: } else if (pageName.equalsIgnoreCase(TBL_PAGE_TYPE_DEPLOYMENTS)) {
223: filterState = showBean.getFilterTargetAssemblyState();
224: filterStates = showBean.getFilterTargetAssemblyStates();
225: }
226:
227: Iterator possibleTargets = allTargetsList.iterator();
228: while (possibleTargets.hasNext()) {
229: Properties targetProps = (Properties) possibleTargets
230: .next();
231: String target = (String) targetProps.getProperty("name");
232: String type = (String) targetProps.getProperty("type");
233:
234: // TBD: instead of calling .check in this loop, pass in an array of target names
235: // to move loop inside of common client
236:
237: String status = showBean.check(target);
238: if (null != status) {
239: sLog
240: .fine("QueryHandlers.setFilteredTargetsList, target="
241: + target + ", status=" + status);
242:
243: SelectableTargetInfo selectableTarget = new SelectableTargetInfo(
244: target, status, type);
245:
246: if (BeanUtilities.checkFilterOptions(selectableTarget
247: .getStatus(), filterState, filterStates)) {
248: filteredTargetsList.add(selectableTarget);
249: }
250: }
251: }
252:
253: sLog
254: .fine("QueryHandlers.setFilteredTargetsList, filteredTargetsList="
255: + filteredTargetsList);
256:
257: showBean.setTargetsList(filteredTargetsList);
258: }
259:
260: /**
261: * sets the component name and type
262: * <p> Input value: "JBIComponentName" -- Type: <code>java.lang.String</code></p>
263: * <p> Input value: "JBIComponentType" -- Type: <code>java.lang.String</code></p>
264: * @param context The HandlerContext.
265: */
266: @Handler(id="setJBIComponentId",input={@HandlerInput(name="JBIComponentName",type=String.class,required=true),@HandlerInput(name="JBIComponentType",type=String.class,required=true)})
267: public static void setJBIComponentId(HandlerContext handlerCtx) {
268:
269: String componentName = (String) handlerCtx
270: .getInputValue("JBIComponentName");
271: String componentType = (String) handlerCtx
272: .getInputValue("JBIComponentType");
273: sLog.fine("QueryHandlers.setJBIComponentId(JBIComponentName="
274: + componentName + ", JBIComponentType=" + componentType
275: + ")");
276: ShowBean showBean = BeanUtilities.getShowBean();
277: showBean.setName(componentName);
278: showBean.setType(componentType);
279: }
280:
281: /**
282: * <p> Gets jbi.xml descriptor from client and sets in a variable
283: * <p> Input value: "compName" -- Type: <code> java.lang.String</code> Name of the component
284: * <p> Input value: "compType" -- Type: <code> java.lang.String</code> JBI type whose decriptor is requested
285: * @param handlerCtx <code>HandlerContext</code> provides inputs and outputs.
286: */
287: @Handler(id="setMetaDataContents",input={@HandlerInput(name="compName",type=String.class,required=true),@HandlerInput(name="compType",type=String.class,required=true)})
288: public static void setMetaDataContents(HandlerContext handlerCtx) {
289: sLog.fine("DEPRECATED setMetaDataContents");
290: String compName = (String) handlerCtx.getInputValue("compName");
291: String compType = (String) handlerCtx.getInputValue("compType");
292:
293: ShowBean showBean = BeanUtilities.getShowBean();
294: showBean.setName(compName);
295: showBean.setType(compType);
296: }
297:
298: /**
299: * Returns a list of names and types for the selected rows.
300: * @param aGroup <code>TableRowGroup</code> the table data with some rows selected.
301: * @return <code>List</code> of <code>Properties</code> objects
302: * <p> Each properties object has 'name' and 'type' keys and values.
303: */
304: private static List getSelectedRowProperties(TableRowGroup aGroup) {
305: ArrayList result = new ArrayList();
306:
307: ObjectListDataProvider dp = (ObjectListDataProvider) aGroup
308: .getSourceData();
309:
310: if (null != dp) {
311: try {
312: FieldKey fkName = dp
313: .getFieldKey(SharedConstants.KEY_NAME);
314: FieldKey fkType = dp
315: .getFieldKey(SharedConstants.KEY_TYPE);
316:
317: RowKey[] rowKeys = aGroup.getSelectedRowKeys();
318:
319: for (int cnt = 0; cnt < rowKeys.length; cnt++) {
320: Properties selectedRowProperties = new Properties();
321:
322: String compName = (String) dp.getValue(fkName,
323: rowKeys[cnt]);
324:
325: selectedRowProperties.setProperty(
326: SharedConstants.KEY_NAME, compName);
327:
328: String compType = (String) dp.getValue(fkType,
329: rowKeys[cnt]);
330:
331: selectedRowProperties.setProperty(
332: SharedConstants.KEY_TYPE, compType);
333:
334: result.add(selectedRowProperties);
335: }
336: } catch (Exception ex) {
337: sLog
338: .fine("QueryHandlers.getSelectedRowProperties(), caught ex="
339: + ex);
340: ex.printStackTrace(System.err);
341: }
342: } else {
343: sLog
344: .fine("QueryHandlers.getSelectedRowProperties(), cannot process dp="
345: + dp);
346: }
347:
348: sLog.fine("QueryHandlers.getSelectedRowProperties(), result="
349: + result);
350: return result;
351: }
352:
353: /**
354: * <p> Sets the specified type of table row group data for a shared table
355: * <p> Input value: "tableType" -- Type: <code> java.lang.String</code>
356: * Valid types: 'deployments,' 'bindingsEngines,' or 'libraries.'
357: * @param handlerCtx <code>HandlerContext</code> provides inputs and outputs.
358: */
359: @Handler(id="setSharedTableData",input={@HandlerInput(name="tableType",type=String.class,required=true)})
360: public static void setSharedTableData(HandlerContext context) {
361: String tableType = (String) context.getInputValue("tableType");
362: sLog.fine("QueryHandlers.setSharedTableData(), tableType="
363: + tableType);
364:
365: ListBean listBean = BeanUtilities.getListBean();
366:
367: if (TBL_PAGE_TYPE_BINDINGS_ENGINES.equals(tableType)) {
368: listBean.setBindingsEnginesTableData();
369: } else if (TBL_PAGE_TYPE_DEPLOYMENTS.equals(tableType)) {
370: listBean.setDeploymentsTableData();
371: } else if (TBL_PAGE_TYPE_LIBRARIES.equals(tableType)) {
372: listBean.setLibrariesTableData();
373: }
374: }
375:
376: @Handler(id="jbiGetWormholeLinkForName",input={@HandlerInput(name="clusterOrServerName",type=String.class,required=true)},output={@HandlerOutput(name="wormholeLink",type=String.class)})
377: public static void jbiGetWormholeLinkForName(
378: HandlerContext handlerCtx) {
379: String result = "";
380: String clusterOrServerName = (String) handlerCtx
381: .getInputValue("clusterOrServerName");
382:
383: if (ClusterUtilities.isCluster(clusterOrServerName)) {
384: result = "cluster/clusterGeneral.jsf?clusterName="
385: + clusterOrServerName;
386: } else if (ClusterUtilities.isServer(clusterOrServerName)) {
387: result = "standalone/standaloneInstanceGeneral.jsf?instanceName="
388: + clusterOrServerName;
389: }
390:
391: handlerCtx.setOutputValue("wormholeLink", result);
392:
393: sLog.fine("QueryHandlers.jbiGetWormholeLinkForName(...), "
394: + " clusterOrServerName=" + clusterOrServerName
395: + ", result=" + result);
396: }
397:
398: /**
399: * <p> Writes a LogLevel.FINE record to the log
400: * <p> Input value: "diagnostic" -- Type: <code>java.lang.String</code></p>
401: * @param context The HandlerContext.
402: */
403: @Handler(id="jbiLogFine",input={@HandlerInput(name="where",type=String.class,required=true),@HandlerInput(name="diagnostic",type=String.class,required=true)})
404: public static void jbiLogFine(HandlerContext handlerCtx) {
405: String where = (String) handlerCtx.getInputValue("where");
406: String diagnostic = (String) handlerCtx
407: .getInputValue("diagnostic");
408: sLog.fine("QueryHandlers.jbiLogFine: where=[" + where
409: + "], diagnostic=" + diagnostic);
410: }
411:
412: /**
413: * <p> Sets the dependencies data into the list bean
414: * <p> Input value: "type" -- Type: <code>java.lang.String</code></p>
415: * one of binding-component, service-engine, or shared-library
416: * <p> Input value: "name" -- Type: <code>java.lang.String</code></p>
417: * the name of a component or library
418: * @param context The HandlerContext.
419: */
420: @Handler(id="jbiSetDependencies",input={@HandlerInput(name="type",type=String.class,required=true),@HandlerInput(name="name",type=String.class,required=true)})
421: public static void jbiSetDependencies(HandlerContext handlerCtx) {
422: String type = (String) handlerCtx.getInputValue("type");
423: String name = (String) handlerCtx.getInputValue("name");
424: sLog.fine("QueryHandlers.jbiSetDependencies: type=[" + type
425: + "], name=" + name);
426:
427: // set list bean dependencies table data
428: ListBean listBean = BeanUtilities.getListBean();
429: listBean.setSharedDepsTableData(type, name);
430: }
431:
432: private static Table createTable(String aUniqueId, String aTitle,
433: String[] anArrayOfRows) {
434: Table result = new Table();
435: result.setId(aUniqueId);
436: result.setLite(true);
437: result.setTitle(aTitle);
438: result.setWidth("55");
439:
440: TableRowGroup trg = new TableRowGroup();
441: trg.setSourceVar("sourceVar");
442:
443: TableColumn nameTableColumn = new TableColumn();
444: nameTableColumn.setId("nameTableColumn" + aUniqueId);
445: StaticText nameText = new StaticText();
446: nameText.setId("nameText" + aUniqueId);
447: String vExprStr = "#{sourceVar.value.name}";
448: FacesContext facesContext = FacesContext.getCurrentInstance();
449: ValueExpression ve = facesContext.getApplication()
450: .getExpressionFactory().createValueExpression(
451: facesContext.getELContext(), vExprStr,
452: Object.class);
453: nameText.setValueExpression("text", ve);
454:
455: nameTableColumn.getChildren().add(nameText);
456:
457: trg.getChildren().add(nameTableColumn);
458:
459: ArrayList rows = new ArrayList();
460:
461: for (int i = 0; i < anArrayOfRows.length; ++i) {
462: Row oneRow = new Row();
463: oneRow.setName(anArrayOfRows[i]);
464: rows.add(oneRow);
465: }
466:
467: ObjectListDataProvider oldp = new ObjectListDataProvider(rows);
468:
469: trg.setSourceData(oldp);
470:
471: result.getChildren().add(trg);
472:
473: return result;
474: }
475: }
|