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: * @(#)JbiSetRuntimeLoggersTask.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.TreeMap;
043: import java.util.Properties;
044: import org.apache.tools.ant.BuildException;
045:
046: /** This class is an ant task for updating service engine or binding component.
047: *
048: * @author Sun Microsystems, Inc.
049: */
050: public class JbiSetRuntimeLoggersTask extends JbiTargetTask {
051: /**
052: * logger success msg key
053: */
054: private static final String LOGGER_SUCCESS_STATUS_KEY = "jbi.ui.ant.set.logger.successful";
055:
056: /**
057: * logger failure msg key
058: */
059: private static final String LOGGER_FAILED_STATUS_KEY = "jbi.ui.ant.set.logger.failed";
060:
061: /**
062: * logger partial success msg key
063: */
064: private static final String LOGGER_PARTIAL_SUCCESS_STATUS_KEY = "jbi.ui.ant.set.logger.partial.success";
065:
066: /** Holds Nested element list of <logger> */
067: private List mLoggerList;
068:
069: private void debugPrintParams(Properties params) {
070: if (params == null) {
071: this .logDebug("Set Configuration params are NULL");
072: return;
073: }
074: StringWriter stringWriter = new StringWriter();
075: PrintWriter out = new PrintWriter(stringWriter);
076: params.list(out);
077: out.close();
078: this .logDebug(stringWriter.getBuffer().toString());
079: }
080:
081: private String createFormatedSuccessJbiResultMessage(
082: String i18nKey, Object[] args) {
083:
084: String msgCode = getI18NBundle().getMessage(i18nKey + ".ID");
085: String msg = getI18NBundle().getMessage(i18nKey, args);
086:
087: String jbiResultXml = JBIResultXmlBuilder.getInstance()
088: .createJbiResultXml("JBI_ANT_TASK_SET_CONFIG",
089: JBIResultXmlBuilder.SUCCESS_RESULT,
090: JBIResultXmlBuilder.INFO_MSG_TYPE, msgCode,
091: msg, args, null);
092:
093: JBIManagementMessage mgmtMsg = null;
094: mgmtMsg = JBIManagementMessage
095: .createJBIManagementMessage(jbiResultXml);
096: return (mgmtMsg != null) ? mgmtMsg.getMessage() : msg;
097: }
098:
099: private void executeSetRuntimeLoggers() throws BuildException {
100:
101: this .logDebug("Executing Set Runtime Loggers ....");
102:
103: String target = getValidTarget();
104: boolean restartRequired = false;
105: try {
106: List loggerList = this .getLoggerList();
107: boolean emptyFlag = true;
108:
109: Iterator it = loggerList.iterator();
110: while (it.hasNext()) {
111: Logger logger = (Logger) it.next();
112: String theName = "" + logger.getName();
113: if (theName.compareTo("") != 0) {
114: if (("" + logger.getLevel()).toUpperCase()
115: .compareTo("DEFAULT") != 0) {
116: this .logDebug("logger name: "
117: + logger.getName()
118: + " logger level: "
119: + java.util.logging.Level.parse(logger
120: .getLevel()) + " target: "
121: + target);
122: this .getJBIAdminCommands()
123: .setRuntimeLoggerLevel(
124: logger.getName(),
125: java.util.logging.Level
126: .parse(logger
127: .getLevel()),
128: target, target);
129: } else {
130: this .getJBIAdminCommands()
131: .setRuntimeLoggerLevel(
132: logger.getName(), null, target,
133: target);
134: }
135:
136: emptyFlag = false;
137: }
138: }
139:
140: if (emptyFlag == true) {
141: String msg = createFailedFormattedJbiAdminResult(
142: "jbi.ui.ant.task.error.no.input.runtime.logger.data.found",
143: null);
144: throw new BuildException(msg, getLocation());
145: }
146:
147: String i18nKey = "jbi.ui.ant.task.info.logger.done.on.target";
148: Object[] args = { target };
149: this
150: .printTaskSuccess(createFormatedSuccessJbiResultMessage(
151: i18nKey, args));
152: } catch (Exception ex) {
153: processTaskException(ex);
154: }
155: }
156:
157: /** executes the install task. Ant Task framework calls this method to
158: * excute the task.
159: * @throws BuildException if error or exception occurs.
160: */
161: public void executeTask() throws BuildException {
162: this .logDebug("Executing Set Configuration Task....");
163:
164: executeSetRuntimeLoggers();
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 LOGGER_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 LOGGER_SUCCESS_STATUS_KEY;
181: }
182:
183: /**
184: * return i18n key for the partial success
185: * @return i18n key for the partial success
186: */
187: protected String getTaskPartialSuccessStatusI18NKey() {
188: return LOGGER_PARTIAL_SUCCESS_STATUS_KEY;
189: }
190:
191: /**
192: * returns nested element list of <logger>
193: * @return Paramter List
194: */
195: protected List getLoggerList() {
196: if (this .mLoggerList == null) {
197: this .mLoggerList = new ArrayList();
198: }
199: return this .mLoggerList;
200: }
201:
202: /**
203: * factory method for creating the nested element <logger>
204: * @return Logger Object
205: */
206: public Logger createLogger() {
207: Logger logger = new Logger();
208: this.getLoggerList().add(logger);
209: return logger;
210: }
211: }
|