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