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