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: * @(#)JbiUpgradeComponentTask.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.ui.ant;
030:
031: import java.io.File;
032: import java.io.FileInputStream;
033: import java.io.IOException;
034: import java.util.ArrayList;
035: import java.util.Iterator;
036: import java.util.List;
037: import java.util.Properties;
038: import org.apache.tools.ant.BuildException;
039:
040: /** This class is an ant task for updating service engine or binding component.
041: *
042: * @author Sun Microsystems, Inc.
043: */
044: public class JbiUpgradeComponentTask extends JbiJmxTask {
045: /**
046: * success msg key
047: */
048: private static final String SUCCESS_STATUS_KEY = "jbi.ui.ant.upgrade.component.successful";
049: /**
050: * failure msg key
051: */
052: private static final String FAILED_STATUS_KEY = "jbi.ui.ant.upgrade.component.failed";
053: /** Holds value of property installFile. */
054: private File mInstallFile;
055:
056: /** Holds value of property componentName. */
057: private String mComponentName = null;
058:
059: /** Getter for property componentName.
060: * @return Value of property componentName.
061: *
062: */
063: public String getName() {
064: return this .mComponentName;
065: }
066:
067: /**
068: * Setter for property componentName.
069: * @param name component name.
070: */
071: public void setName(String name) {
072: this .mComponentName = name;
073: }
074:
075: /** Getter for property component installer zip file.
076: * @return Value of property installer zip file.
077: *
078: */
079: public File getFile() {
080: return this .mInstallFile;
081: }
082:
083: /** Setter for property installer zip file.
084: * @param file New value of property installer zip file.
085: *
086: */
087: public void setFile(File file) {
088: this .mInstallFile = file;
089: }
090:
091: /**
092: * validates the file
093: */
094: protected void validateInstallFileAttribute(File installFile)
095: throws BuildException {
096: if (installFile == null) {
097: throwTaskBuildException("jbi.ui.ant.upgrade.error.comp.archive.file.path.null");
098: }
099:
100: if (installFile.getPath().trim().length() <= 0) {
101: throwTaskBuildException("jbi.ui.ant.upgrade.error.comp.archive.file.path.required");
102: }
103:
104: if (!installFile.exists()) {
105:
106: throwTaskBuildException(
107: "jbi.ui.ant.upgrade.error.comp.archive.file.not.exist",
108: installFile.getName());
109: }
110:
111: if (installFile.isDirectory()) {
112: throwTaskBuildException("jbi.ui.ant.upgrade.error.comp.archive.file.is.directory");
113: }
114:
115: }
116:
117: /**
118: * validate compName with valid target
119: * @param compName name of the component in the repository
120: */
121: protected void validateNameAttribute(String compName)
122: throws BuildException {
123: if (compName == null) {
124: throwTaskBuildException("jbi.ui.ant.upgrade.error.comp.name.required");
125: }
126:
127: if (compName.trim().length() == 0) {
128: throwTaskBuildException("jbi.ui.ant.task.error.nullCompName");
129: }
130: }
131:
132: /** executes the install task. Ant Task framework calls this method to
133: * excute the task.
134: * @throws BuildException if error or exception occurs.
135: */
136: public void executeTask() throws BuildException {
137: String installFileAbsolutePath = null;
138:
139: String compName = getName();
140:
141: File installFile = getFile();
142:
143: validateNameAttribute(compName);
144: validateInstallFileAttribute(installFile);
145: installFileAbsolutePath = installFile.getAbsolutePath();
146:
147: try {
148: String result = null;
149: result = this .getJBIAdminCommands().updateComponent(
150: compName, installFileAbsolutePath);
151: // Wait for Marc's change
152: // result = this.getJBIAdminCommands().upgradeComponent(compName, installFileAbsolutePath);
153: printTaskSuccess(result);
154:
155: } catch (Exception ex) {
156: processTaskException(ex);
157: }
158:
159: }
160:
161: /**
162: * returns i18n key. tasks implement this method.
163: * @return i18n key for the success status
164: */
165: protected String getTaskFailedStatusI18NKey() {
166: return FAILED_STATUS_KEY;
167: }
168:
169: /**
170: * returns i18n key. tasks implement this method.
171: * @return i18n key for the failed status
172: */
173: protected String getTaskSuccessStatusI18NKey() {
174: return SUCCESS_STATUS_KEY;
175: }
176:
177: }
|