1 15 package org.apache.tapestry.pageload; 16 17 import org.apache.hivemind.ClassResolver; 18 import org.apache.tapestry.IEngine; 19 import org.apache.tapestry.IPage; 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.Tapestry; 22 import org.apache.tapestry.engine.IMonitor; 23 import org.apache.tapestry.engine.IPageLoader; 24 import org.apache.tapestry.engine.IPageSource; 25 import org.apache.tapestry.resolver.PageSpecificationResolver; 26 import org.apache.tapestry.services.ObjectPool; 27 import org.apache.tapestry.util.MultiKey; 28 29 44 45 public class PageSource implements IPageSource 46 { 47 48 private ClassResolver _classResolver; 49 50 51 private PageSpecificationResolver _pageSpecificationResolver; 52 53 54 55 private IPageLoader _loader; 56 57 61 62 private ObjectPool _pool; 63 64 public ClassResolver getClassResolver() 65 { 66 return _classResolver; 67 } 68 69 72 73 protected MultiKey buildKey(IEngine engine, String pageName) 74 { 75 Object [] keys; 76 77 keys = new Object [] 78 { pageName, engine.getLocale() }; 79 80 82 return new MultiKey(keys, false); 83 } 84 85 89 90 protected MultiKey buildKey(IPage page) 91 { 92 Object [] keys; 93 94 keys = new Object [] 95 { page.getPageName(), page.getLocale() }; 96 97 99 return new MultiKey(keys, false); 100 } 101 102 105 106 public IPage getPage(IRequestCycle cycle, String pageName, IMonitor monitor) 107 { 108 IEngine engine = cycle.getEngine(); 109 Object key = buildKey(engine, pageName); 110 IPage result = (IPage) _pool.get(key); 111 112 if (result == null) 113 { 114 monitor.pageCreateBegin(pageName); 115 116 _pageSpecificationResolver.resolve(cycle, pageName); 117 118 result = _loader.loadPage( 119 _pageSpecificationResolver.getSimplePageName(), 120 _pageSpecificationResolver.getNamespace(), 121 cycle, 122 _pageSpecificationResolver.getSpecification()); 123 124 monitor.pageCreateEnd(pageName); 125 } 126 127 return result; 128 } 129 130 133 134 public void releasePage(IPage page) 135 { 136 Tapestry.clearMethodInvocations(); 137 138 page.detach(); 139 140 Tapestry.checkMethodInvocation(Tapestry.ABSTRACTPAGE_DETACH_METHOD_ID, "detach()", page); 141 142 _pool.store(buildKey(page), page); 143 } 144 145 146 147 public void setPool(ObjectPool pool) 148 { 149 _pool = pool; 150 } 151 152 153 154 public void setClassResolver(ClassResolver resolver) 155 { 156 _classResolver = resolver; 157 } 158 159 160 161 public void setPageSpecificationResolver(PageSpecificationResolver resolver) 162 { 163 _pageSpecificationResolver = resolver; 164 } 165 166 167 168 public void setLoader(IPageLoader loader) 169 { 170 _loader = loader; 171 } 172 173 } | Popular Tags |