001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.hivemind.lib.pipeline;
016
017 import java.util.Iterator;
018 import java.util.List;
019
020 import org.apache.hivemind.ErrorLog;
021 import org.apache.hivemind.ServiceImplementationFactory;
022 import org.apache.hivemind.ServiceImplementationFactoryParameters;
023 import org.apache.hivemind.impl.BaseLocatable;
024 import org.apache.hivemind.lib.DefaultImplementationBuilder;
025 import org.apache.hivemind.service.ClassFactory;
026
027 /**
028 * Service factory that builds a pipeline of objects.
029 *
030 * @author Howard Lewis Ship
031 */
032 public class PipelineFactory extends BaseLocatable implements ServiceImplementationFactory
033 {
034 private ClassFactory _classFactory;
035
036 private DefaultImplementationBuilder _defaultImplementationBuilder;
037
038 /** @since 1.1 */
039 private ErrorLog _errorLog;
040
041 public Object createCoreServiceImplementation(
042 ServiceImplementationFactoryParameters factoryParameters)
043 {
044 PipelineParameters pp = (PipelineParameters) factoryParameters.getParameters().get(0);
045
046 PipelineAssembler pa = new PipelineAssembler(_errorLog, factoryParameters.getServiceId(),
047 factoryParameters.getServiceInterface(), pp.getFilterInterface(), _classFactory,
048 _defaultImplementationBuilder);
049
050 Object terminator = pp.getTerminator();
051
052 if (terminator != null)
053 pa.setTerminator(terminator, pp.getLocation());
054
055 List l = pp.getPipelineConfiguration();
056
057 Iterator i = l.iterator();
058 while (i.hasNext())
059 {
060 PipelineContribution c = (PipelineContribution) i.next();
061
062 c.informAssembler(pa);
063 }
064
065 return pa.createPipeline();
066 }
067
068 public void setClassFactory(ClassFactory factory)
069 {
070 _classFactory = factory;
071 }
072
073 public void setDefaultImplementationBuilder(DefaultImplementationBuilder builder)
074 {
075 _defaultImplementationBuilder = builder;
076 }
077
078 /** @since 1.1 */
079 public void setErrorLog(ErrorLog errorLog)
080 {
081 _errorLog = errorLog;
082 }
083 }