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: * @(#)JbiDeployServiceAssemblyTask.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 org.apache.tools.ant.BuildException;
033:
034: /** This class is an ant task for service assembly deployment.
035: *
036: * @author Sun Microsystems, Inc.
037: */
038: public class JbiDeployServiceAssemblyTask extends JbiTargetTask {
039: /**
040: * success msg key
041: */
042: private static final String PARTIAL_SUCCESS_STATUS_KEY = "jbi.ui.ant.deploy.partial.success";
043:
044: /**
045: * success msg key
046: */
047: private static final String SUCCESS_STATUS_KEY = "jbi.ui.ant.deploy.successful";
048: /**
049: * failure msg key
050: */
051: private static final String FAILED_STATUS_KEY = "jbi.ui.ant.deploy.failed";
052:
053: /** Holds value of property deployFile. */
054: private File mDeployFile;
055:
056: /** Holds value of property service assembly Name. */
057: private String mSAName = null;
058:
059: /** Getter for property service assembly Name.
060: * @return Value of property service assembly Name.
061: *
062: */
063: public String getName() {
064: return this .mSAName;
065: }
066:
067: /**
068: * Setter for property service assembly Name.
069: * @param name service assembly name.
070: */
071: public void setName(String name) {
072: this .mSAName = name;
073: }
074:
075: /** Getter for property deploy file.
076: * @return Value of property deploy file.
077: *
078: */
079: public File getFile() {
080: return this .mDeployFile;
081: }
082:
083: /**
084: * Setter for property file.
085: * @param file file object
086: */
087: public void setFile(File file) {
088: this .mDeployFile = file;
089: }
090:
091: /**
092: * validates the file
093: */
094: protected void validateDeployFile(File deployFile)
095: throws BuildException {
096: if (deployFile == null) {
097: throwTaskBuildException("jbi.ui.ant.deploy.error.sa.archive.file.path.null");
098: }
099:
100: if (deployFile.getPath().trim().length() <= 0) {
101: throwTaskBuildException("jbi.ui.ant.deploy.error.sa.archive.file.path.required");
102: }
103:
104: if (!deployFile.exists()) {
105:
106: throwTaskBuildException(
107: "jbi.ui.ant.deploy.error.sa.archive.file.not.exist",
108: deployFile.getName());
109: }
110:
111: if (deployFile.isDirectory()) {
112:
113: throwTaskBuildException("jbi.ui.ant.deploy.error.sa.archive.file.is.directory");
114: }
115:
116: }
117:
118: /**
119: * validate compName with valid target
120: * @param saName name of the service assembly in the repository
121: * @param target value, can not be domain
122: */
123: protected void validateDeployFromDomainAttributes(String saName,
124: String target) throws BuildException {
125: if (saName.trim().length() == 0) {
126: throwTaskBuildException("jbi.ui.ant.deploy.from.domain.error.sa.name.required");
127: }
128: if ("domain".equals(target)) {
129: throwTaskBuildException("jbi.ui.ant.deploy.error.sa.invalid.target.with.name.attrib");
130: }
131: }
132:
133: /** executes the deployment task. Ant Task framework calls this method to
134: * excute the task.
135: * @throws BuildException if error or exception occurs.
136: */
137: public void executeTask() throws BuildException {
138: String deployFileAbsolutePath = null;
139: boolean deployFromDoamin = false;
140:
141: String saName = getName();
142:
143: File deployFile = getFile();
144:
145: String target = getValidTarget();
146:
147: if (saName == null && deployFile == null) {
148: throwTaskBuildException("jbi.ui.ant.deploy.error.sa.name.or.file.required");
149: }
150:
151: if (saName != null && deployFile != null) {
152: throwTaskBuildException("jbi.ui.ant.deploy.error.sa.name.and.file.set");
153: }
154:
155: if (saName != null) {
156: validateDeployFromDomainAttributes(saName, target);
157: deployFromDoamin = true;
158: } else {
159: validateDeployFile(deployFile);
160: deployFileAbsolutePath = deployFile.getAbsolutePath();
161: }
162:
163: // perform deployment
164:
165: String result = null;
166:
167: try {
168: if (deployFromDoamin) {
169: result = this
170: .getJBIAdminCommands()
171: .deployServiceAssemblyFromDomain(saName, target);
172: } else {
173: result = this .getJBIAdminCommands()
174: .deployServiceAssembly(deployFileAbsolutePath,
175: target);
176: }
177: } catch (Exception ex) {
178: processTaskException(ex);
179: }
180:
181: processTaskResult(result);
182:
183: }
184:
185: /**
186: * returns i18n key. tasks implement this method.
187: * @return i18n key for the success status
188: */
189: protected String getTaskFailedStatusI18NKey() {
190: return FAILED_STATUS_KEY;
191: }
192:
193: /**
194: * returns i18n key. tasks implement this method.
195: * @return i18n key for the failed status
196: */
197: protected String getTaskSuccessStatusI18NKey() {
198: return SUCCESS_STATUS_KEY;
199: }
200:
201: /**
202: * return i18n key for the partial success
203: * @return i18n key for the partial success
204: */
205: protected String getTaskPartialSuccessStatusI18NKey() {
206: return PARTIAL_SUCCESS_STATUS_KEY;
207: }
208:
209: }
|