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 PageLoader 40 extends GenericLoader 41 implements Loader 42 { 43 44 private static Log log = LogFactory.getLog(PageLoader.class); 45 46 47 private static PageLoader instance = 48 new PageLoader(Turbine.getConfiguration() 49 .getInt(TurbineConstants.PAGE_CACHE_SIZE_KEY, 50 TurbineConstants.PAGE_CACHE_SIZE_DEFAULT)); 51 52 53 private static AssemblerBrokerService ab = TurbineAssemblerBroker.getService(); 54 55 59 private PageLoader() 60 { 61 super(); 62 } 63 64 68 private PageLoader(int i) 69 { 70 super(i); 71 } 72 73 79 private void addInstance(String name, Page page) 80 { 81 if (cache()) 82 { 83 this.put(name, (Page) page); 84 } 85 } 86 87 94 public void exec(RunData data, String name) 95 throws Exception 96 { 97 getInstance(name).build(data); 99 } 100 101 111 public Assembler getAssembler(String name) 112 throws Exception 113 { 114 return getInstance(name); 115 } 116 117 125 public Page getInstance(String name) 126 throws Exception 127 { 128 Page page = null; 129 130 if (cache() && this.containsKey(name)) 132 { 133 page = (Page) this.get(name); 134 log.debug("Found Page " + name + " in the cache!"); 135 } 136 else 137 { 138 log.debug("Loading Page " + name + " from the Assembler Broker"); 139 140 try 141 { 142 if (ab != null) 143 { 144 page = (Page) ab.getAssembler( 146 AssemblerBrokerService.PAGE_TYPE, name); 147 } 148 } 149 catch (ClassCastException cce) 150 { 151 page = null; 155 } 156 157 if (page == null) 158 { 159 List packages = Turbine.getConfiguration() 164 .getList(TurbineConstants.MODULE_PACKAGES); 165 166 ObjectUtils.addOnce(packages, 167 GenericLoader.getBasePackage()); 168 169 throw new ClassNotFoundException ( 170 "\n\n\tRequested Page not found: " + name + 171 "\n\tTurbine looked in the following " + 172 "modules.packages path: \n\t" + packages.toString() + "\n"); 173 } 174 else if (cache()) 175 { 176 addInstance(name, page); 178 } 179 } 180 return page; 181 } 182 183 188 public static PageLoader getInstance() 189 { 190 return instance; 191 } 192 } 193 | Popular Tags |