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.jbi.jsf.bean.ListBean;
040: import com.sun.jbi.jsf.bean.ServiceUnitBean;
041: import com.sun.jbi.jsf.bean.SelectableServiceUnitInfo;
042: import com.sun.jbi.jsf.util.BeanUtilities;
043: import com.sun.jbi.jsf.util.JBILogger;
044: import com.sun.jsftemplating.annotation.Handler;
045: import com.sun.jsftemplating.annotation.HandlerInput;
046: import com.sun.jsftemplating.annotation.HandlerOutput;
047: import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
048: import java.util.logging.Logger;
049:
050: import com.sun.jbi.ui.common.ServiceAssemblyInfo;
051: import com.sun.jbi.ui.common.JBIAdminCommands;
052: import com.sun.jbi.ui.common.ServiceUnitInfo;
053:
054: import java.util.ArrayList;
055: import java.util.Iterator;
056: import java.util.List;
057:
058: /**
059: * Provides jsftemplating handlers for List/Show tables
060: */
061: public class ServiceUnitHandlers {
062: public final static String TBL_PAGE_TYPE_BINDINGS_ENGINES = "bindingsEngines";
063: public final static String TBL_PAGE_TYPE_DEPLOYMENTS = "deployments";
064: public final static String TBL_PAGE_TYPE_LIBRARIES = "libraries";
065:
066: private static Logger sLog = JBILogger.getInstance();
067:
068: private static SelectableServiceUnitInfo createSelectableServiceUnitInfo(
069: ServiceUnitInfo aServiceUnitInfo, String aSaName,
070: String aTarget) {
071: String suName = aServiceUnitInfo.getName();
072: String suDesc = aServiceUnitInfo.getDescription();
073: String suTgt = aServiceUnitInfo.getTargetName();
074: String suState = aServiceUnitInfo.getState();
075:
076: SelectableServiceUnitInfo selectableServiceUnit = new SelectableServiceUnitInfo(
077: suName, suDesc, suTgt, suState, aSaName);
078:
079: String compType = BeanUtilities
080: .getComponentType(suTgt, aTarget);
081: selectableServiceUnit.setComponentType(compType);
082:
083: return selectableServiceUnit;
084: }
085:
086: /**
087: * <p> This method sets the information for the service unit in the show bean.
088: * <p> Input value: "serviceUnitName" -- Type: <code>java.lang.String</code></p>
089: * @param context The HandlerContext.
090: */
091: @Handler(id="jbiSetServiceUnitInfo",input={@HandlerInput(name="serviceUnitName",type=String.class,required=true),@HandlerInput(name="serviceAssemblyName",type=String.class,required=true),@HandlerInput(name="componentType",type=String.class,required=true),@HandlerInput(name="targetComponent",type=String.class,required=true)})
092: public static void jbiSetServiceUnitInfo(HandlerContext handlerCtx) {
093: String serviceUnitName = (String) handlerCtx
094: .getInputValue("serviceUnitName");
095: String serviceAssemblyName = (String) handlerCtx
096: .getInputValue("serviceAssemblyName");
097: String componentType = (String) handlerCtx
098: .getInputValue("componentType");
099: String targetComponent = (String) handlerCtx
100: .getInputValue("targetComponent");
101:
102: String description = "";
103: boolean done = false;
104:
105: sLog
106: .fine("QueryHandlers.jbiGetServiceUnitInfo(...), serviceUnitName="
107: + serviceUnitName);
108: ServiceUnitBean serviceUnitBean = BeanUtilities
109: .getServiceUnitBean();
110: serviceUnitBean.setName(serviceUnitName);
111: serviceUnitBean.setServiceAssemblyName(serviceAssemblyName);
112: serviceUnitBean.setComponentType(componentType);
113: serviceUnitBean.setTargetComponent(targetComponent);
114:
115: try {
116: JBIAdminCommands mJac = BeanUtilities.getClient();
117: String xml = mJac.listServiceAssemblies(targetComponent,
118: "server");
119: List saInfoList = ServiceAssemblyInfo
120: .readFromXmlTextWithProlog(xml);
121: if (saInfoList != null) {
122: Iterator<Object> it = saInfoList.iterator();
123: while (it.hasNext()) {
124: Object saInfoObject = it.next();
125: String saName = ((ServiceAssemblyInfo) saInfoObject)
126: .getName();
127: if (serviceAssemblyName.equals(saName)) {
128: List infoList = ((ServiceAssemblyInfo) saInfoObject)
129: .getServiceUnitInfoList();
130: Iterator<Object> it2 = infoList.iterator();
131: while (it2.hasNext()) {
132: Object suInfoObject = it2.next();
133: String suName = ((ServiceUnitInfo) suInfoObject)
134: .getName();
135: if (suName.equals(serviceUnitName)) {
136: done = true;
137: description = ((ServiceUnitInfo) suInfoObject)
138: .getDescription();
139: }
140: }
141: }
142: if (done) {
143: break;
144: }
145: }
146: }
147: } catch (com.sun.jbi.ui.common.JBIRemoteException jbiRemoteEx) {
148: sLog
149: .fine("QueryHandlers.jbiSetServiceUnitInfo(): caught jbiRemoteEx="
150: + jbiRemoteEx);
151: }
152:
153: serviceUnitBean.setDescription(description);
154: }
155:
156: /**
157: * <p> This method initializes the Service Unit Bean for listing
158: * the service units.
159: * <p> Input target: "String" -- Type: <code>String.class</code></p>
160: * <p> Input pageType: "String" -- Type: <code>String.class</code></p>
161: * <p> Input name: "String" -- Type: <code>String.class</code></p>
162: * @param context The HandlerContext.
163: */
164: @Handler(id="jbiInitServieAssemblyServiceUnitsList",input={@HandlerInput(name="target",type=String.class,required=false),@HandlerInput(name="pageType",type=String.class,required=true),@HandlerInput(name="name",type=String.class,required=true)})
165: public static void jbiInitServieAssemblyServiceUnitsList(
166: HandlerContext handlerCtx) {
167: String pageType = (String) handlerCtx.getInputValue("pageType");
168: String name = (String) handlerCtx.getInputValue("name");
169: String target = (String) handlerCtx.getInputValue("target");
170:
171: ListBean listBean = BeanUtilities.getListBean();
172: ServiceUnitBean serviceUnitBean = BeanUtilities
173: .getServiceUnitBean();
174: List filteredServiceUnitList = new ArrayList();
175: String saName = "";
176:
177: String xmlQueryResults = listBean.getListServiceAssemblies();
178:
179: if (pageType.equals(TBL_PAGE_TYPE_DEPLOYMENTS)) {
180: List saInfoList = ServiceAssemblyInfo
181: .readFromXmlTextWithProlog(xmlQueryResults);
182: if (saInfoList != null) {
183: Iterator<Object> it = saInfoList.iterator();
184: while (it.hasNext()) {
185: Object saInfoObject = it.next();
186: saName = ((ServiceAssemblyInfo) saInfoObject)
187: .getName();
188: if (name.equals(saName)) {
189: List infoList = ((ServiceAssemblyInfo) saInfoObject)
190: .getServiceUnitInfoList();
191: Iterator<Object> it2 = infoList.iterator();
192: while (it2.hasNext()) {
193: Object suInfoObject = it2.next();
194:
195: SelectableServiceUnitInfo selectableServiceUnit = createSelectableServiceUnitInfo(
196: (ServiceUnitInfo) suInfoObject,
197: saName, target);
198: selectableServiceUnit.setQueryString("sa");
199: filteredServiceUnitList
200: .add(selectableServiceUnit);
201: }
202: break; // There can only be one match, so no use continuing
203: }
204: }
205: }
206: }
207:
208: else if (pageType.equals(TBL_PAGE_TYPE_BINDINGS_ENGINES)) {
209: try {
210: JBIAdminCommands mJac = BeanUtilities.getClient();
211: String xml = mJac.listServiceAssemblies(name, target);
212: List saInfoList = ServiceAssemblyInfo
213: .readFromXmlTextWithProlog(xml);
214: if (saInfoList != null) {
215: Iterator<Object> it = saInfoList.iterator();
216: while (it.hasNext()) {
217: Object saInfoObject = it.next();
218: List infoList = ((ServiceAssemblyInfo) saInfoObject)
219: .getServiceUnitInfoList();
220: saName = ((ServiceAssemblyInfo) saInfoObject)
221: .getName();
222: Iterator<Object> it2 = infoList.iterator();
223: while (it2.hasNext()) {
224: Object suInfoObject = it2.next();
225: String tgtName = ((ServiceUnitInfo) suInfoObject)
226: .getTargetName();
227: if (tgtName.equals(name)) {
228: SelectableServiceUnitInfo selectableServiceUnit = createSelectableServiceUnitInfo(
229: (ServiceUnitInfo) suInfoObject,
230: saName, target);
231: selectableServiceUnit
232: .setQueryString("comp");
233: filteredServiceUnitList
234: .add(selectableServiceUnit);
235: }
236: }
237: }
238: }
239: } catch (com.sun.jbi.ui.common.JBIRemoteException jbiRemoteEx) {
240: sLog
241: .fine("QueryHandlers.jbiInitServieAssemblyServiceUnitsList(): caught jbiRemoteEx="
242: + jbiRemoteEx);
243: }
244: }
245: serviceUnitBean.setServiceUnitsList(filteredServiceUnitList);
246: }
247:
248: }
|