1 package org.enhydra.shark.toolagent; 2 3 4 import org.enhydra.shark.api.internal.toolagent.*; 5 import org.enhydra.shark.api.SharkTransaction; 6 import org.enhydra.shark.api.RootException; 7 import org.enhydra.shark.api.internal.working.CallbackUtilities; 8 9 import java.util.*; 10 11 17 public class ToolAgentFactoryImpl implements ToolAgentFactory { 18 private final static String TOOL_AGENT_PREFIX="ToolAgent."; 19 private List toolAgents=new ArrayList(); 20 21 private CallbackUtilities cus; 22 public void configure (CallbackUtilities cus) throws RootException { 23 this.cus=cus; 24 createToolAgentList(); 25 } 26 27 30 public List getDefinedToolAgents (SharkTransaction t) throws RootException { 31 return Collections.unmodifiableList(toolAgents); 32 } 33 34 35 public ToolAgent createToolAgent(SharkTransaction t,String className) throws RootException { 36 try { 37 Class cls=Class.forName(className); 38 ToolAgent ta=(ToolAgent)cls.newInstance(); 39 ta.configure(cus); 40 return ta; 41 } catch (Exception ex) { 42 throw new RootException("Failed to create tool agent for class "+className,ex); 43 } 44 } 45 46 private void createToolAgentList () { 47 String taName=null; 48 String className=null; 49 Properties props= cus.getProperties(); 50 51 Iterator it=props.entrySet().iterator(); 52 while (it.hasNext()) { 53 try { 54 Map.Entry me=(Map.Entry)it.next(); 55 taName=me.getKey().toString(); 56 if (taName.startsWith(TOOL_AGENT_PREFIX)) { 57 taName=taName.substring(TOOL_AGENT_PREFIX.length()); 58 className=me.getValue().toString(); 59 toolAgents.add(className); 60 } 61 } catch (Throwable ex) { 62 cus.error("ToolAgentFactoryImpl -> Error when retrieving list of tool agents from properties!!!"); 64 } 65 } 66 } 67 68 } 69 | Popular Tags |