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: * @(#)JbiListSharedLibrariesTask.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 com.sun.jbi.ui.common.JBIComponentInfo;
032: import java.util.ArrayList;
033: import org.apache.tools.ant.BuildException;
034:
035: /** This class is an ant task for displaying shared libraries information.
036: *
037: * @author Sun Microsystems, Inc.
038: */
039: public class JbiListSharedLibrariesTask extends JbiQueryTask {
040: /**
041: * success msg key
042: */
043: private static final String SUCCESS_STATUS_KEY = "jbi.ui.ant.list.shared.lib.successful";
044: /**
045: * failure msg key
046: */
047: private static final String FAILED_STATUS_KEY = "jbi.ui.ant.list.shared.lib.failed";
048:
049: /**
050: * Holds value of property sharedLibraryName.
051: */
052: private String mSharedLibraryName;
053:
054: /**
055: * Holds value of property componentName.
056: */
057: private String mComponentName;
058:
059: /**
060: * Holds value of property descriptor (flag) which indicates whether showing descriptor or nor.
061: */
062: private boolean mDescriptor;
063:
064: /**
065: * Getter for property sharedLibraryName.
066: * @return Value of property sharedLibraryName.
067: */
068: public String getSharedLibraryName() {
069: return this .mSharedLibraryName;
070: }
071:
072: /**
073: * Setter for property sharedLibraryName.
074: * @param sharedLibraryName New value of property sharedLibraryName.
075: */
076: public void setSharedLibraryName(String sharedLibraryName) {
077: this .mSharedLibraryName = sharedLibraryName;
078: }
079:
080: /**
081: * Getter for property componentName.
082: * @return Value of property componentName.
083: */
084: public String getComponentName() {
085: return this .mComponentName;
086: }
087:
088: /**
089: * Setter for property componentName.
090: * @param componentName name of the component.
091: */
092: public void setComponentName(String componentName) {
093: this .mComponentName = componentName;
094: }
095:
096: /**
097: * Getter for property descriptor (flag) which indicates showing descriptor or not.
098: * @return Value of property descriptor.
099: */
100: public boolean getDescriptor() {
101: return this .mDescriptor;
102: }
103:
104: /**
105: * Setter for property descriptor (flag) which indicates showing descriptor or not..
106: * @param descriptor New value of property descriptor.
107: */
108: public void setDescriptor(boolean descriptor) {
109: this .mDescriptor = descriptor;
110: }
111:
112: /** executes the list shared libraries task. Ant Task framework calls this method to
113: * excute the task.
114: * @throws BuildException if error or exception occurs.
115: */
116: public void executeTask() throws BuildException {
117: // set a empty component info list if xml output set
118: initXmlOutput(JBIComponentInfo.writeAsXmlText(new ArrayList()));
119:
120: String descriptor = null;
121: String target = getValidTarget();
122: try {
123: String result;
124: String name = this .getSharedLibraryName();
125: String compName = this .getComponentName();
126:
127: if (null != name && name.length() > 0) {
128: // if shared library name present, execute show to display single object info.
129: result = this .getJBIAdminCommands().showSharedLibrary(
130: name, compName, target);
131:
132: this .setSingleQueryResultType();
133:
134: if (mDescriptor == true) {
135: descriptor = this .getJBIAdminCommands()
136: .getSharedLibraryInstallationDescriptor(
137: name);
138: if (descriptor == null) {
139: String errMsg = createFailedFormattedJbiAdminResult(
140: "jbi.ui.ant.show.shared.library.descriptor.not.found",
141: new String[] { name });
142: throw new Exception(errMsg);
143: }
144: }
145: } else {
146: if (mDescriptor == true) {
147: String errMsg = createFailedFormattedJbiAdminResult(
148: "jbi.ui.ant.show.shared.library.descriptor.single.only",
149: null);
150: throw new Exception(errMsg);
151: }
152:
153: result = this .getJBIAdminCommands()
154: .listSharedLibraries(compName, target);
155: }
156:
157: printComponentQueryResults(result);
158: if (descriptor != null) {
159: printMessage("");
160: printMessage(getI18NBundle().getMessage(
161: "jbi.ui.ant.print.shared.lib.descriptor"));
162: printMessage(descriptor);
163: printMessage("");
164: }
165: } catch (Exception ex) {
166: // throwTaskBuildException(ex);
167: processTaskException(ex);
168: }
169:
170: }
171:
172: /**
173: * returns i18n key. tasks implement this method.
174: * @return i18n key for the success status
175: */
176: protected String getTaskFailedStatusI18NKey() {
177: return FAILED_STATUS_KEY;
178: }
179:
180: /**
181: * returns i18n key. tasks implement this method.
182: * @return i18n key for the failed status
183: */
184: protected String getTaskSuccessStatusI18NKey() {
185: return SUCCESS_STATUS_KEY;
186: }
187:
188: /**
189: * returns i18n key
190: * @return the i18n key
191: */
192: protected String getEmptyQueryResultI18NKey() {
193: return "jbi.ui.ant.print.no.slib";
194: }
195:
196: /**
197: * returns i18n key
198: * @return the i18n key
199: */
200: protected String getQueryResultHeaderI18NKey() {
201: return "jbi.ui.ant.print.slib.header";
202: }
203:
204: /**
205: * returns i18n key
206: * @return the i18n key
207: */
208: protected String getQueryResultHeaderSeparatorI18NKey() {
209: return "jbi.ui.ant.print.comp.info.header.separator";
210: }
211:
212: /**
213: * returns i18n key
214: * @return the i18n key
215: */
216: protected String getQueryResultPageSeparatorI18NKey() {
217: return "jbi.ui.ant.print.comp.info.separator";
218: }
219:
220: /**
221: * message text for empty query results
222: * @return message text
223: */
224: protected String getEmptyQueryResultI18NMessage() {
225: if (this .getQueryResultType() == this .SINGLE_QUERY_RESULT_TYPE) {
226: return getI18NBundle().getMessage(
227: "jbi.ui.ant.print.no.slib.with.name",
228: this.getSharedLibraryName());
229: } else {
230: return getI18NBundle().getMessage(
231: getEmptyQueryResultI18NKey());
232: }
233: }
234: }
|