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.ecs.ConcreteElement; 25 26 import org.apache.turbine.Turbine; 27 import org.apache.turbine.TurbineConstants; 28 import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService; 29 import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker; 30 import org.apache.turbine.util.ObjectUtils; 31 import org.apache.turbine.util.RunData; 32 33 41 public class NavigationLoader 42 extends GenericLoader 43 implements Loader 44 { 45 46 private static Log log = LogFactory.getLog(NavigationLoader.class); 47 48 49 private static NavigationLoader instance = 50 new NavigationLoader(Turbine.getConfiguration() 51 .getInt(TurbineConstants.NAVIGATION_CACHE_SIZE_KEY, 52 TurbineConstants.NAVIGATION_CACHE_SIZE_DEFAULT)); 53 54 55 private static AssemblerBrokerService ab = TurbineAssemblerBroker.getService(); 56 57 61 private NavigationLoader() 62 { 63 super(); 64 } 65 66 70 private NavigationLoader(int i) 71 { 72 super(i); 73 } 74 75 81 private void addInstance(String name, Navigation navigation) 82 { 83 if (cache()) 84 { 85 this.put(name, (Navigation) navigation); 86 } 87 } 88 89 100 public ConcreteElement eval(RunData data, String name) 101 throws Exception 102 { 103 return getInstance(name).build(data); 105 } 106 107 114 public void exec(RunData data, String name) 115 throws Exception 116 { 117 this.eval(data, name); 118 } 119 120 130 public Assembler getAssembler(String name) 131 throws Exception 132 { 133 return getInstance(name); 134 } 135 136 144 public Navigation getInstance(String name) 145 throws Exception 146 { 147 Navigation navigation = null; 148 149 if (cache() && this.containsKey(name)) 151 { 152 navigation = (Navigation) this.get(name); 153 log.debug("Found Navigation " + name + " in the cache!"); 154 } 155 else 156 { 157 log.debug("Loading Navigation " + name + " from the Assembler Broker"); 158 159 try 160 { 161 if (ab != null) 162 { 163 navigation = (Navigation) ab.getAssembler( 165 AssemblerBrokerService.NAVIGATION_TYPE, name); 166 } 167 } 168 catch (ClassCastException cce) 169 { 170 navigation = null; 174 } 175 176 if (navigation == null) 177 { 178 List packages = Turbine.getConfiguration() 183 .getList(TurbineConstants.MODULE_PACKAGES); 184 185 ObjectUtils.addOnce(packages, 186 GenericLoader.getBasePackage()); 187 188 throw new ClassNotFoundException ( 189 "\n\n\tRequested Navigation not found: " + name + 190 "\n\tTurbine looked in the following " + 191 "modules.packages path: \n\t" + packages.toString() + "\n"); 192 } 193 else if (cache()) 194 { 195 addInstance(name, navigation); 197 } 198 } 199 return navigation; 200 } 201 202 207 public static NavigationLoader getInstance() 208 { 209 return instance; 210 } 211 } 212 | Popular Tags |