KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > lib > pipeline > PipelineFactory


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.lib.pipeline;
16
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.apache.hivemind.ErrorLog;
21 import org.apache.hivemind.ServiceImplementationFactory;
22 import org.apache.hivemind.ServiceImplementationFactoryParameters;
23 import org.apache.hivemind.impl.BaseLocatable;
24 import org.apache.hivemind.lib.DefaultImplementationBuilder;
25 import org.apache.hivemind.service.ClassFactory;
26
27 /**
28  * Service factory that builds a pipeline of objects.
29  *
30  * @author Howard Lewis Ship
31  */

32 public class PipelineFactory extends BaseLocatable implements ServiceImplementationFactory
33 {
34     private ClassFactory _classFactory;
35
36     private DefaultImplementationBuilder _defaultImplementationBuilder;
37
38     /** @since 1.1 */
39     private ErrorLog _errorLog;
40
41     public Object JavaDoc createCoreServiceImplementation(
42             ServiceImplementationFactoryParameters factoryParameters)
43     {
44         PipelineParameters pp = (PipelineParameters) factoryParameters.getFirstParameter();
45
46         PipelineAssembler pa = new PipelineAssembler(_errorLog, factoryParameters.getServiceId(),
47                 factoryParameters.getServiceInterface(), pp.getFilterInterface(), _classFactory,
48                 _defaultImplementationBuilder);
49
50         Object JavaDoc terminator = pp.getTerminator();
51
52         if (terminator != null)
53             pa.setTerminator(terminator, pp.getLocation());
54
55         List JavaDoc l = pp.getPipelineConfiguration();
56
57         Iterator JavaDoc i = l.iterator();
58         while (i.hasNext())
59         {
60             PipelineContribution c = (PipelineContribution) i.next();
61
62             c.informAssembler(pa);
63         }
64
65         return pa.createPipeline();
66     }
67
68     public void setClassFactory(ClassFactory factory)
69     {
70         _classFactory = factory;
71     }
72
73     public void setDefaultImplementationBuilder(DefaultImplementationBuilder builder)
74     {
75         _defaultImplementationBuilder = builder;
76     }
77
78     /** @since 1.1 */
79     public void setErrorLog(ErrorLog errorLog)
80     {
81         _errorLog = errorLog;
82     }
83 }
Popular Tags