1 package org.apache.turbine.modules; 2 3 18 19 import java.util.List ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import org.apache.turbine.Turbine; 25 import org.apache.turbine.TurbineConstants; 26 import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService; 27 import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker; 28 import org.apache.turbine.util.ObjectUtils; 29 import org.apache.turbine.util.RunData; 30 31 39 public class ActionLoader 40 extends GenericLoader 41 { 42 43 private static Log log = LogFactory.getLog(ActionLoader.class); 44 45 46 private static ActionLoader instance = new ActionLoader( 47 Turbine.getConfiguration().getInt(TurbineConstants.ACTION_CACHE_SIZE_KEY, 48 TurbineConstants.ACTION_CACHE_SIZE_DEFAULT)); 49 50 51 private static AssemblerBrokerService ab = TurbineAssemblerBroker.getService(); 52 53 57 private ActionLoader() 58 { 59 super(); 60 } 61 62 66 private ActionLoader(int i) 67 { 68 super(i); 69 } 70 71 77 private void addInstance(String name, Action action) 78 { 79 if (cache()) 80 { 81 this.put(name, (Action) action); 82 } 83 } 84 85 92 public void exec(RunData data, String name) 93 throws Exception 94 { 95 getInstance(name).perform(data); 97 } 98 99 107 public Action getInstance(String name) 108 throws Exception 109 { 110 Action action = null; 111 112 if (cache() && this.containsKey(name)) 114 { 115 action = (Action) this.get(name); 116 log.debug("Found Action " + name + " in the cache!"); 117 } 118 else 119 { 120 log.debug("Loading Action " + name + " from the Assembler Broker"); 121 122 try 123 { 124 action = (Action) ab.getAssembler( 126 AssemblerBrokerService.ACTION_TYPE, name); 127 } 128 catch (ClassCastException cce) 129 { 130 action = null; 134 } 135 136 if (action == null) 137 { 138 List packages = Turbine.getConfiguration() 143 .getList(TurbineConstants.MODULE_PACKAGES); 144 145 ObjectUtils.addOnce(packages, 146 GenericLoader.getBasePackage()); 147 148 throw new ClassNotFoundException ( 149 "\n\n\tRequested Action not found: " + name + 150 "\n\tTurbine looked in the following " + 151 "modules.packages path: \n\t" + packages.toString() + "\n"); 152 } 153 else if (cache()) 154 { 155 addInstance(name, action); 157 } 158 } 159 return action; 160 } 161 162 167 public static ActionLoader getInstance() 168 { 169 return instance; 170 } 171 } 172 | Popular Tags |