001: /*---------------------------------------------------------------------------*\
002: $Id: DisableOutputHandlerPlugIn.java 7041 2007-09-09 01:04:47Z bmc $
003: ---------------------------------------------------------------------------
004: This software is released under a BSD-style license:
005:
006: Copyright (c) 2004-2007 Brian M. Clapper. All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without
009: modification, are permitted provided that the following conditions are
010: met:
011:
012: 1. Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014:
015: 2. The end-user documentation included with the redistribution, if any,
016: must include the following acknowlegement:
017:
018: "This product includes software developed by Brian M. Clapper
019: (bmc@clapper.org, http://www.clapper.org/bmc/). That software is
020: copyright (c) 2004-2007 Brian M. Clapper."
021:
022: Alternately, this acknowlegement may appear in the software itself,
023: if wherever such third-party acknowlegements normally appear.
024:
025: 3. Neither the names "clapper.org", "curn", nor any of the names of the
026: project contributors may be used to endorse or promote products
027: derived from this software without prior written permission. For
028: written permission, please contact bmc@clapper.org.
029:
030: 4. Products derived from this software may not be called "curn", nor may
031: "clapper.org" appear in their names without prior written permission
032: of Brian M. Clapper.
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
036: MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
037: NO EVENT SHALL BRIAN M. CLAPPER BE LIABLE FOR ANY DIRECT, INDIRECT,
038: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
039: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
040: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
041: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044: \*---------------------------------------------------------------------------*/
045:
046: package org.clapper.curn.plugins;
047:
048: import org.clapper.curn.ConfiguredOutputHandler;
049: import org.clapper.curn.CurnConfig;
050: import org.clapper.curn.CurnException;
051: import org.clapper.curn.OutputHandlerConfigItemPlugIn;
052:
053: import org.clapper.util.classutil.ClassUtil;
054: import org.clapper.util.config.ConfigurationException;
055: import org.clapper.util.logging.Logger;
056:
057: /**
058: * The <tt>DisableOutputHandlerPlugIn</tt> handles disabling an output handler. It
059: * intercepts the following per-handler configuration parameters:
060: *
061: * <table border="1">
062: * <tr valign="top">
063: * <td><tt>Disabled</tt></td>
064: * <td>Flag indicating whether or not to disable the output handler.</td>
065: * </tr>
066: * <tr valign="top">
067: * </table>
068: *
069: * @version <tt>$Revision: 7041 $</tt>
070: */
071: public class DisableOutputHandlerPlugIn implements
072: OutputHandlerConfigItemPlugIn {
073: /*----------------------------------------------------------------------*\
074: Private Constants
075: \*----------------------------------------------------------------------*/
076:
077: /*----------------------------------------------------------------------*\
078: Private Classes
079: \*----------------------------------------------------------------------*/
080:
081: /**
082: * For log messages
083: */
084: private static final Logger log = new Logger(
085: DisableOutputHandlerPlugIn.class);
086:
087: /*----------------------------------------------------------------------*\
088: Constructor
089: \*----------------------------------------------------------------------*/
090:
091: /**
092: * Default constructor (required).
093: */
094: public DisableOutputHandlerPlugIn() {
095: // Nothing to do
096: }
097:
098: /*----------------------------------------------------------------------*\
099: Public Methods Required by *PlugIn Interfaces
100: \*----------------------------------------------------------------------*/
101:
102: /**
103: * Get a displayable name for the plug-in.
104: *
105: * @return the name
106: */
107: public String getPlugInName() {
108: return "Disable Output Handler";
109: }
110:
111: /**
112: * Get the sort key for this plug-in.
113: *
114: * @return the sort key string.
115: */
116: public String getPlugInSortKey() {
117: return ClassUtil.getShortClassName(getClass().getName());
118: }
119:
120: /**
121: * Initialize the plug-in. This method is called before any of the
122: * plug-in methods are called.
123: *
124: * @throws CurnException on error
125: */
126: public void initPlugIn() throws CurnException {
127: }
128:
129: /**
130: * Called immediately after <i>curn</i> has read and processed a
131: * configuration item in an output handler configuration section. All
132: * configuration items are passed, one by one, to each loaded plug-in.
133: * If a plug-in class is not interested in a particular configuration
134: * item, this method should simply return without doing anything. Note
135: * that some configuration items may simply be variable assignment;
136: * there's no real way to distinguish a variable assignment from a
137: * blessed configuration item.
138: *
139: * @param sectionName the name of the configuration section where
140: * the item was found
141: * @param paramName the name of the parameter
142: * @param config the {@link CurnConfig} object
143: * @param handler partially complete {@link ConfiguredOutputHandler}
144: * object. The class name is guaranteed to be set,
145: * but the other fields may not be.
146: *
147: * @return <tt>true</tt> to continue processing the handler,
148: * <tt>false</tt> to skip it
149: *
150: * @throws CurnException on error
151: *
152: * @see CurnConfig
153: * @see ConfiguredOutputHandler
154: */
155: public boolean runOutputHandlerConfigItemPlugIn(String sectionName,
156: String paramName, CurnConfig config,
157: ConfiguredOutputHandler handler) throws CurnException {
158: boolean keepGoing = true;
159:
160: try {
161: if (paramName.equals(CurnConfig.VAR_DISABLED)) {
162: boolean disable = config.getRequiredBooleanValue(
163: sectionName, paramName);
164: log.debug("[" + sectionName + "]: " + paramName + "="
165: + disable);
166:
167: if (disable)
168: keepGoing = false;
169: }
170: }
171:
172: catch (ConfigurationException ex) {
173: throw new CurnException(ex);
174: }
175:
176: return keepGoing;
177: }
178: }
|