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