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: * @(#)JbiDeleteApplicationConfigurationsTask.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.JBIManagementMessage;
032: import com.sun.jbi.ui.common.JBIResultXmlBuilder;
033: import java.io.File;
034: import java.io.FileInputStream;
035: import java.io.IOException;
036: import java.io.PrintWriter;
037: import java.io.StringWriter;
038: import java.util.ArrayList;
039: import java.util.Iterator;
040: import java.util.List;
041: import java.util.Map;
042: import java.util.Vector;
043: import java.util.TreeMap;
044: import java.util.Properties;
045: import org.apache.tools.ant.BuildException;
046:
047: /** This class is an ant task for updating service engine or binding component.
048: *
049: * @author Sun Microsystems, Inc.
050: */
051: public class JbiDeleteApplicationConfigurationsTask extends
052: JbiTargetTask {
053: /**
054: * appconfig success msg key
055: */
056: private static final String APPCONFIG_SUCCESS_STATUS_KEY = "jbi.ui.ant.delete.appconfig.successful";
057:
058: /**
059: * appconfig failure msg key
060: */
061: private static final String APPCONFIG_FAILED_STATUS_KEY = "jbi.ui.ant.delete.appconfig.failed";
062:
063: /**
064: * appconfig success msg key
065: */
066: private static final String APPCONFIG_PARTIAL_SUCCESS_STATUS_KEY = "jbi.ui.ant.delete.appconfig.partial.success";
067:
068: /** Holds appconfig Nested elements */
069: private List mAppConfigList;
070:
071: /** Holds value of property componentName. */
072: private String mComponentName = null;
073:
074: /**
075: * Getter for property componentName.
076: * @return Value of property componentName.
077: */
078: public String getComponentName() {
079: return this .mComponentName;
080: }
081:
082: /**
083: * Setter for property componentName.
084: * @param componentName name of the component.
085: */
086: public void setComponentName(String componentName) {
087: this .mComponentName = componentName;
088: }
089:
090: private void debugPrintParams(Properties params) {
091: if (params == null) {
092: this .logDebug("Set Configuration params are NULL");
093: return;
094: }
095: StringWriter stringWriter = new StringWriter();
096: PrintWriter out = new PrintWriter(stringWriter);
097: params.list(out);
098: out.close();
099: this .logDebug(stringWriter.getBuffer().toString());
100: }
101:
102: private String createFormatedSuccessJbiResultMessage(
103: String i18nKey, Object[] args) {
104:
105: String msgCode = getI18NBundle().getMessage(i18nKey + ".ID");
106: String msg = getI18NBundle().getMessage(i18nKey, args);
107:
108: String jbiResultXml = JBIResultXmlBuilder.getInstance()
109: .createJbiResultXml("JBI_ANT_TASK_SET_CONFIG",
110: JBIResultXmlBuilder.SUCCESS_RESULT,
111: JBIResultXmlBuilder.INFO_MSG_TYPE, msgCode,
112: msg, args, null);
113:
114: JBIManagementMessage mgmtMsg = null;
115: mgmtMsg = JBIManagementMessage
116: .createJBIManagementMessage(jbiResultXml);
117: return (mgmtMsg != null) ? mgmtMsg.getMessage() : msg;
118: }
119:
120: private void executeDeleteApplicationConfigurations(
121: List appConfigList, String compName, String target)
122: throws Exception, BuildException {
123: // Go throught the appconfig elements
124: Properties appConfigParamProps = new Properties();
125:
126: Iterator it = appConfigList.iterator();
127: while (it.hasNext()) {
128: Param appConfig = (Param) it.next();
129: String appConfigName = appConfig.getName();
130: this
131: .logDebug("Delete application configuration, component name: "
132: + compName
133: + " Application Configuration name: "
134: + appConfigName + " target: " + target);
135:
136: String rtnXml = this .getJBIAdminCommands()
137: .deleteApplicationConfiguration(compName, target,
138: appConfigName);
139:
140: JBIManagementMessage mgmtMsg = JBIManagementMessage
141: .createJBIManagementMessage(rtnXml);
142: if (mgmtMsg.isFailedMsg()) {
143: throw new Exception(rtnXml);
144: } else {
145: // print success message
146: printTaskSuccess(mgmtMsg);
147: }
148: }
149: }
150:
151: /** executes the install task. Ant Task framework calls this method to
152: * excute the task.
153: * @throws BuildException if error or exception occurs.
154: */
155: public void executeTask() throws BuildException {
156: try {
157: String compName = getComponentName();
158: String target = getValidTarget();
159: List appConfigList = this .getAppConfigList();
160:
161: if ((compName == null) || (compName.compareTo("") == 0)) {
162: String errMsg = createFailedFormattedJbiAdminResult(
163: "jbi.ui.ant.task.error.nullCompName", null);
164: throw new BuildException(errMsg);
165: }
166:
167: this
168: .logDebug("Executing delete application configurations Task....");
169: executeDeleteApplicationConfigurations(appConfigList,
170: compName, target);
171: } catch (Exception ex) {
172: processTaskException(ex);
173: }
174: }
175:
176: /**
177: * returns i18n key. tasks implement this method.
178: * @return i18n key for the success status
179: */
180: protected String getTaskFailedStatusI18NKey() {
181: return APPCONFIG_FAILED_STATUS_KEY;
182: }
183:
184: /**
185: * returns i18n key. tasks implement this method.
186: * @return i18n key for the failed status
187: */
188: protected String getTaskSuccessStatusI18NKey() {
189: return APPCONFIG_SUCCESS_STATUS_KEY;
190: }
191:
192: /**
193: * return i18n key for the partial success
194: * @return i18n key for the partial success
195: */
196: protected String getTaskPartialSuccessStatusI18NKey() {
197: return APPCONFIG_PARTIAL_SUCCESS_STATUS_KEY;
198: }
199:
200: /**
201: * returns AppConfig element list
202: * @return AppConfig List
203: */
204: protected List getAppConfigList() {
205: if (this .mAppConfigList == null) {
206: this .mAppConfigList = new ArrayList();
207: }
208: return this .mAppConfigList;
209: }
210:
211: /**
212: * factory method for creating the nested element <appconfig>
213: * @return AppConfig Object
214: */
215: public Param createAppConfig() {
216: Param appConfig = new Param();
217: this.getAppConfigList().add(appConfig);
218: return appConfig;
219: }
220: }
|