1 15 package org.apache.hivemind.lib.chain; 16 17 import java.util.ArrayList ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 import org.apache.hivemind.ServiceImplementationFactory; 23 import org.apache.hivemind.ServiceImplementationFactoryParameters; 24 import org.apache.hivemind.order.Orderer; 25 26 32 public class ChainFactory implements ServiceImplementationFactory 33 { 34 private ChainBuilder _chainBuilder; 35 36 public Object createCoreServiceImplementation( 37 ServiceImplementationFactoryParameters factoryParameters) 38 { 39 Map contributions = (Map ) factoryParameters.getFirstParameter(); 40 41 Orderer orderer = new Orderer(factoryParameters.getErrorLog(), "command"); 42 43 Iterator i = contributions.values().iterator(); 44 while (i.hasNext()) 45 { 46 ChainContribution cc = (ChainContribution) i.next(); 47 orderer.add(cc, cc.getId(), cc.getAfter(), cc.getBefore()); 48 } 49 50 List ordered = orderer.getOrderedObjects(); 51 52 List commands = new ArrayList (ordered.size()); 53 54 i = ordered.iterator(); 55 while (i.hasNext()) 56 { 57 ChainContribution cc = (ChainContribution) i.next(); 58 59 62 commands.add(cc.getCommand()); 63 } 64 65 String toString = "<ChainImplementation for " + factoryParameters.getServiceId() + "(" 66 + factoryParameters.getServiceInterface().getName() + ")>"; 67 68 return _chainBuilder.buildImplementation( 69 factoryParameters.getServiceInterface(), 70 commands, 71 toString); 72 } 73 74 public void setChainBuilder(ChainBuilder chainBuilder) 75 { 76 _chainBuilder = chainBuilder; 77 } 78 } | Popular Tags |