001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)BindingBootstrapUpgrade.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework;
030:
031: import java.io.File;
032: import java.util.List;
033:
034: /**
035: * This is an implementation of the bootstrap class for a Binding Component
036: * that is purely for unit testing. It does nothing but log messages when
037: * its methods are called.
038: *
039: * @author Sun Microsystems, Inc.
040: */
041: public class BindingBootstrapUpgrade extends BindingBootstrap {
042: /**
043: * Perform an upgrade of the component.
044: * @param workspaceRoot the workspace root for the new version of the
045: * component that will replace the currently installed version. This is
046: * populated with the contents of the original workspace root and the
047: * component must update it to match the new version of the component.
048: * @param serviceUnitRoots a list of directory paths to all of the Service
049: * Units currently deployed to the component. The component must update all
050: * of these to match the new version of the component.
051: * @throws javax.jbi.JBIException when there is an error requiring that the
052: * upgrade be terminated.
053: */
054: public void upgrade(String workspaceRoot,
055: List<String> serviceUnitRoots)
056: throws javax.jbi.JBIException {
057: String name = System
058: .getProperty(Constants.PROPERTY_COMPONENT_NAME);
059: mLog.info(name + " upgrade started");
060: if (name.equals(Constants.BC_NAME_BAD_BOOTSTRAP_UPGRADE)) {
061: throw new javax.jbi.JBIException(
062: "unable to complete upgrade");
063: }
064:
065: // Write a file in the workspace root so that the junit test can
066: // verify that the upgrade succeeded.
067:
068: writeFile(workspaceRoot, Constants.UPGRADED_FILE_NAME);
069: mLog.info("workspace root " + workspaceRoot + " upgraded");
070:
071: // Write a file in each SU root so that the junit test can verify
072: // that the upgrade succeeded.
073:
074: for (String suRoot : serviceUnitRoots) {
075: writeFile(suRoot, Constants.UPGRADED_FILE_NAME);
076: mLog.info("SU root " + suRoot + " upgraded");
077: }
078:
079: mLog.info(name + " upgrade complete");
080: }
081:
082: /**
083: * Utility method to write a file, overwriting it if it already exists.
084: *
085: * @param path the full path to the directory where the file is to be
086: * written.
087: * @param name the name of the file to be created.
088: */
089: private void writeFile(String path, String name) {
090: File f = new File(path + "/" + name);
091: if (f.exists()) {
092: f.delete();
093: }
094: try {
095: if (!f.createNewFile()) {
096: mLog.warning("Unable to create file "
097: + f.getAbsolutePath());
098: }
099: } catch (java.io.IOException ioEx) {
100: mLog.warning("Unable to create file " + f.getAbsolutePath()
101: + " due to exception: " + ioEx.getMessage());
102: }
103: }
104: }
|