/*
* Copyright (C) 2010 Dedicon <http://dedicon.nl>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Linking altText statically or dynamically with other modules
is making a combined work based on altText. Thus, the terms and
conditions of the GNU General Public License cover
the whole combination. In addition, as a special exception,
the copyright holders of altText give you permission to
combine altText program with free software programs or libraries
that are released under the GNU LGPL or the Common Public License version 1.0.
You may copy and distribute such a system following the terms
of the GNU GPL for altText and the licenses of the other code
concerned, provided that you include the source code of that other
code when and as the GNU GPL requires distribution of source code.
Note that people who make modified versions of altText are not obligated to
grant this special exception for their modified versions; it is their
choice whether to do so. The GNU General Public License gives permission
to release a modified version without this exception; this exception
also makes it possible to release a modified version which carries
forward this exception.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author : Javier Asensio Cubero capitan{.}cambio{@}gmail{.}com
*/
package nl.dedicon.converter.core;
import java.util.logging.Logger;
import nl.dedicon.converter.core.io.Package;
import nl.dedicon.converter.core.util.Configurable;
import nl.dedicon.converter.core.util.Configurator;
import nl.dedicon.converter.core.util.EventBus;
import nl.dedicon.converter.core.util.event.StepEvent;
// TODO: Auto-generated Javadoc
/**
* Generic processor interface. Any processor used for a document conversion
* will be a concrete object of this type. It can be configured using a
* configurator object.
*
* @author javier
* @version 1.0
* @created 21-okt-2009 13:52:59
*/
public abstract class Processor implements Configurable {
/** Next processor in the conversion process. */
private Processor mNextProcessor;
/** The logger. */
private Logger logger = Logger.getLogger("nl.dedicon.converter.core");
/** The temp path for temporal files. */
protected String mTmpPath = null;
/** The tmp prefix for temporal files. */
protected String mTmpPrefix = "";
/**
* Instantiates a new processor.
*/
public Processor() {
this.configure();
}
/**
* Configures this object calling to the ProcessorConfigurator.
*/
private void configure() {
Configurator c = new ProcessorConfigurator();
c.configure(this);
}
/**
* Sets the tmp path.
*
* @param tmpPath the new tmp path
*/
void setTmpPath(String tmpPath) {
this.mTmpPath = tmpPath;
}
/**
* Sets the tmp prefix.
*
* @param tmpPrefix the new tmp prefix
*/
void setTmpPrefix(String tmpPrefix) {
this.mTmpPrefix = tmpPrefix;
}
/**
* Cleans the unused data or files and calls the clean method of the next
* processor.
*/
public void clean() {
this.logger.entering("Processor", "clean");
if (mNextProcessor != null)
this.mNextProcessor.clean();
this.logger.exiting("Processor", "clean");
}
/**
* Do perform, this method has to be overwitten by its children to define
* the concrete processor behaviour.
*
* @param pack package
*/
protected abstract void doPerform(Package pack);
/**
* Calls to the perform element of this concrete processor object and calls
* to the perform method of the following processor.
*
* @param pack package
*
* @return the package
*/
public final Package perform(Package pack) {
this.logger.entering("Processor", "perform");
this.doPerform(pack);
EventBus.getInstance()
.fireEvent(
new StepEvent(pack.stepCompleted(), pack
.getTotalSteps(), pack));
if (mNextProcessor != null)
return mNextProcessor.perform(pack);
else
return pack;
}
/**
* Sets the next processor in the conversion process.
*
* @param processor processor
*/
public void setNextProcessor(Processor processor) {
mNextProcessor = processor;
}
/**
* Gets the next processor.
*
* @return the next processor
*/
public Processor getNextProcessor() {
return mNextProcessor;
}
}
|