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