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: /*
038: * DeletionBean.java
039: */
040:
041: package com.sun.jbi.jsf.bean;
042:
043: import com.sun.jbi.jsf.util.BeanUtilities;
044: import com.sun.jbi.jsf.util.JBIConstants;
045: import com.sun.jbi.jsf.util.JBILogger;
046: import com.sun.jbi.jsf.util.SharedConstants;
047: import com.sun.jbi.jsf.util.I18nUtilities;
048: import com.sun.jbi.ui.common.JBIAdminCommands;
049: import com.sun.jbi.ui.common.JBIComponentInfo;
050: import com.sun.jbi.ui.common.ServiceAssemblyInfo;
051: import com.sun.jbi.ui.common.JBIRemoteException;
052: import com.sun.jbi.ui.common.JBIManagementMessage;
053: import java.util.Iterator;
054: import java.util.List;
055: import java.util.Properties;
056: import java.util.logging.Logger;
057:
058: public class DeletionBean {
059: /**
060: * Controls printing of diagnostic messages to the log
061: */
062: private static Logger sLog = JBILogger.getInstance();
063:
064: public DeletionBean() {
065: mJac = BeanUtilities.getClient();
066: }
067:
068: public Properties delete(Properties aRequestResponse,
069: boolean aRetainFlag, List aTargetsList) {
070: sLog.fine("DeletionBean.delete(" + aRequestResponse + ", "
071: + aTargetsList + ")");
072:
073: Properties result = aRequestResponse;
074: for (Iterator it = aTargetsList.iterator(); it.hasNext();) {
075: String target = (String) it.next();
076: result = doDeleteOnTarget(aRequestResponse, aRetainFlag,
077: target);
078: }
079:
080: sLog.fine("DeletionBean.delete(...), result=" + result);
081: return result;
082: }
083:
084: /**
085: * Will make sure the Service Assembly or Component is shutdown.
086: * @param aType specifies the type of the component/service assembly
087: * @param aName the name of the component/service assembly
088: * @param aTarget the target that the component/service assembly resides on
089: * @return the results string if shutdown was performed
090: */
091: private String shutItDown(String aType, String aName, String aTarget)
092: throws JBIRemoteException {
093: String componentDetails = "";
094: String state = "";
095: if (JBIConstants.JBI_SERVICE_ASSEMBLY_TYPE.equals(aType)) {
096: componentDetails = mJac.showServiceAssembly(aName,
097: SharedConstants.NO_STATE_CHECK,
098: SharedConstants.NO_COMPONENT_CHECK, aTarget);
099: if (componentDetails != null) {
100: List list = ServiceAssemblyInfo
101: .readFromXmlTextWithProlog(componentDetails);
102: Iterator itr = list.iterator();
103: ServiceAssemblyInfo saInfo = (ServiceAssemblyInfo) itr
104: .next();
105: List suInfoList = saInfo.getServiceUnitInfoList();
106: state = saInfo.getState();
107: if (!(state
108: .equalsIgnoreCase(JBIComponentInfo.SHUTDOWN_STATE))) {
109: componentDetails = mJac.shutdownServiceAssembly(
110: aName, aTarget);
111: }
112: }
113: } else if ((JBIConstants.JBI_BINDING_COMPONENT_TYPE
114: .equals(aType))
115: || (JBIConstants.JBI_SERVICE_ENGINE_TYPE.equals(aType))) {
116: if (JBIConstants.JBI_BINDING_COMPONENT_TYPE.equals(aType)) {
117: componentDetails = mJac.showBindingComponent(aName,
118: SharedConstants.NO_STATE_CHECK,
119: SharedConstants.NO_LIBRARY_CHECK,
120: SharedConstants.NO_DEPLOYMENT_CHECK, aTarget);
121: } else if (JBIConstants.JBI_SERVICE_ENGINE_TYPE
122: .equals(aType)) {
123: componentDetails = mJac.showServiceEngine(aName,
124: SharedConstants.NO_STATE_CHECK,
125: SharedConstants.NO_LIBRARY_CHECK,
126: SharedConstants.NO_DEPLOYMENT_CHECK, aTarget);
127: }
128: if (componentDetails != null) {
129: List list = JBIComponentInfo
130: .readFromXmlText(componentDetails);
131: Iterator it = list.iterator();
132: JBIComponentInfo info = ((JBIComponentInfo) it.next());
133: state = info.getState();
134: if (!(state
135: .equalsIgnoreCase(JBIComponentInfo.SHUTDOWN_STATE))) {
136: componentDetails = mJac.shutdownComponent(aName,
137: SharedConstants.NO_FORCE_DELETE, aTarget);
138: }
139: }
140: }
141: return componentDetails;
142: }
143:
144: private Properties doDeleteOnTarget(Properties aRequestResponse,
145: boolean aRetainFlag, String aTarget) {
146: sLog.fine("DeletionBean.doDeleteOnTarget(" + aRequestResponse
147: + ", " + aTarget + ")");
148:
149: Properties result = aRequestResponse;
150: String jbiName = (String) aRequestResponse
151: .getProperty(SharedConstants.KEY_NAME);
152: String jbiType = (String) aRequestResponse
153: .getProperty(SharedConstants.KEY_TYPE);
154:
155: String deletionResult = "";
156: String shutdownResult = "";
157:
158: try {
159: if (null != mJac) {
160: if (JBIConstants.JBI_SERVICE_ASSEMBLY_TYPE
161: .equals(jbiType)) {
162: //shutdownResult = shutItDown (jbiType, jbiName, aTarget);
163: deletionResult = mJac.undeployServiceAssembly(
164: jbiName, SharedConstants.NO_FORCE_DELETE,
165: aRetainFlag, aTarget);
166: result.setProperty(SharedConstants.SUCCESS_RESULT,
167: deletionResult);
168: } else if ((JBIConstants.JBI_BINDING_COMPONENT_TYPE
169: .equals(jbiType))
170: || (JBIConstants.JBI_SERVICE_ENGINE_TYPE
171: .equals(jbiType))) {
172: //shutdownResult = shutItDown (jbiType, jbiName, aTarget);
173: deletionResult = mJac.uninstallComponent(jbiName,
174: SharedConstants.NO_FORCE_DELETE,
175: aRetainFlag, aTarget);
176: result.setProperty(SharedConstants.SUCCESS_RESULT,
177: deletionResult);
178: } else if (JBIConstants.JBI_SHARED_LIBRARY_TYPE
179: .equals(jbiType)) {
180: deletionResult = mJac.uninstallSharedLibrary(
181: jbiName, SharedConstants.NO_FORCE_DELETE,
182: aRetainFlag, aTarget);
183: result.setProperty(SharedConstants.SUCCESS_RESULT,
184: deletionResult);
185: } else {
186: // error unexpected or missing JBI type
187: result
188: .setProperty(
189: SharedConstants.FAILURE_RESULT,
190: "unexpected or missing JBI type="
191: + jbiType);
192: }
193: } else {
194: // error: no JBI admin common client/connection
195: result.setProperty(SharedConstants.FAILURE_RESULT,
196: "missing JBI admin common client");
197: }
198: } catch (com.sun.jbi.ui.common.JBIRemoteException jbiRemoteEx) {
199: jbiRemoteEx.printStackTrace(System.err);
200: JBIManagementMessage mgmtMsg = BeanUtilities
201: .extractJBIManagementMessage(jbiRemoteEx);
202: if (mgmtMsg == null) {
203: String internalErrorMsg = I18nUtilities
204: .getResourceString("jbi.internal.error.invalid.remote.exception");
205: result.setProperty(SharedConstants.INTERNAL_ERROR,
206: internalErrorMsg);
207: } else {
208: String msg = mgmtMsg.getMessage();
209: result.setProperty(SharedConstants.FAILURE_RESULT, msg);
210: }
211: sLog.fine("Deletion.doDeleteOnTarget(...), result="
212: + result);
213: }
214: return result;
215: }
216:
217: private JBIAdminCommands mJac;
218:
219: }
|