|
From: <tr...@us...> - 2003-07-01 12:46:00
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline/feeder In directory sc8-pr-cvs1:/tmp/cvs-serv1709 Added Files: FeederFactory.java Log Message: missing file --- NEW FILE: FeederFactory.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/pipeline/feeder/FeederFactory.java,v 1.1 2003/07/01 12:45:57 triphop Exp $ * $Author: triphop $ * */ package com.babeldoc.core.pipeline.feeder; import com.babeldoc.core.config.IConfig; import com.babeldoc.core.config.ConfigService; import com.babeldoc.core.TieredConfigurationHelper; import com.babeldoc.core.GeneralException; import com.babeldoc.core.service.ServiceFactory; import com.babeldoc.core.service.ServiceException; import java.util.Collection; import java.util.Map; import java.util.HashMap; /** * The feeder factory provides an easy way to feed documents into the pipelines in * babeldoc. There exists a number of "feeders" which are implemented in a number of * generally useful ways. Each of the feeders have a name and are stored in the * feeder/config configuration file. Each feeder has to have a type associated with it. * There are two defined feeders in the system: sync & async. The sync feeder * synchronously feeds each document to the pipeline. The async feeder uses a multithread * queue with producer/collector pattern to separate the feedign from thr processing. * * Please look at the process methods which provide a number of generally useful and easy * methods of getting data into the system. */ public class FeederFactory { private static FeederFactory instance; private Map feeders; private TieredConfigurationHelper configHelper; public static final String FEEDER_CONFIG = "feeder/config"; public static final String FEEDER_TYPE = "type"; public static final String SERVICE_FEEDER = "Feeder."; public static final String SYNC = "sync"; public static final String ASYNC = "async"; /** * Private constructor - this must be instantiated through the feeder factory * getInstance method */ private FeederFactory() { feeders = new HashMap(); } /** * Get the current instance of this singleton class. If there is not a current * implementation, create a new implementation. * * @return */ public static FeederFactory getInstance() { if(instance==null) { instance = new FeederFactory(); } return instance; } /** * Get the feeder with this name. If this feeder does not exist, then * create it. This is done by reading the feeder/config configuration file. * This file is arranged as follows: * * feeder-name.type=Synchonous|Asynchronous|etc * feeder-name.cfg-1=value-1 * ... * feeder-name.cfg-n=value-n * * @param name * @return * @throws ServiceException */ public IFeeder getFeeder(String name) throws GeneralException { // System.out.println("Getting feeder)"); IFeeder feeder = (IFeeder)feeders.get(name); if(feeder==null) { // System.out.println("Creating feeder)"); if(configHelper==null) { // System.out.println("Creating configHelper"); IConfig config = ConfigService.getInstance().getConfig(FEEDER_CONFIG); configHelper = new TieredConfigurationHelper(config); } Map feederConfig = (Map)configHelper.getNamedConfigs().get(name); if(feederConfig!=null) { // System.out.println("config data not null: "+feederConfig.toString()); String feederType = (String)feederConfig.get(FEEDER_TYPE); feeder = (IFeeder)(ServiceFactory.getService(SERVICE_FEEDER+feederType)); feeder.initialize(feederConfig); } } return feeder; } /** * Feed the document according to the name of the feeder. This method takes a * feed document. * * @param name feeder name * @param feedDoc document to feed * @return * @throws GeneralException */ public Collection process(String name, FeedDocument feedDoc) throws GeneralException { return getFeeder(name).process(feedDoc); } /** * Feed the document according to the name of the feeder. This method takes * all the data to construct a full feed document * * @param name feeder name * @param pipelineName name of the pipeline * @param data array of bytes that is the document to process * @param attributes map of attributes * @param isBinary sets the isBinary flag on the document * @param noJournal allows for the journal to be turned on or off for this processing. * @return * @throws GeneralException */ public Collection process(String name, String pipelineName, byte[] data, Map attributes, boolean isBinary, boolean noJournal) throws GeneralException { return getFeeder(name).process( new FeedDocument(pipelineName, data, attributes, isBinary, noJournal)); } /** * Feed the document according to the name of the feeder. This method constructs * a feed document with the data BUT assumes that the data is NOT binary and * that the journalling is ENABLED. * * @param name feeder name * @param pipelineName name of the pipeline * @param data array of bytes that is the document to process * @param attributes map of attributes * @return * @throws GeneralException */ public Collection process(String name, String pipelineName, byte[] data, Map attributes) throws GeneralException { return getFeeder(name).process( new FeedDocument(pipelineName, data, attributes, false, false)); } /** * Feed the document according to the name of the feeder. This method constructs * a feed document with the data BUT assumes that the data is NOT binary and * that the journalling is ENABLED and NO attributes. * * @param name feeder name * @param pipelineName name of the pipeline * @param data array of bytes that is the document to process * @return * @throws GeneralException */ public Collection process(String name, String pipelineName, byte[] data) throws GeneralException { return getFeeder(name).process( new FeedDocument(pipelineName, data, new HashMap(), false, false)); } } |