1 package org.appfuse.webapp.action; 2 3 import org.apache.tapestry.IPage; 4 import org.apache.tapestry.engine.RequestCycle; 5 import org.apache.tapestry.html.BasePage; 6 import org.apache.tapestry.test.Creator; 7 8 public class MockRequestCycle extends RequestCycle { 9 private String pkg; 10 11 public MockRequestCycle() { 12 super(); 13 } 14 15 public MockRequestCycle(String pkg) { 16 super(); 17 this.pkg = pkg; 18 } 19 20 public IPage getPage(final String name) { 21 char first = Character.toUpperCase(name.charAt(0)); 23 String className = first + name.substring(1); 24 25 if (className.endsWith("s")) { 27 className = className.substring(0, className.length() - 1) + "List"; 28 } 29 30 if (pkg != null) { 31 className = pkg + "." + className; 32 } else { 33 className = MockRequestCycle.class.getPackage().getName() + "." + className; 34 } 35 36 IPage page; 37 38 try { 39 page = (IPage) new Creator().newInstance(Class.forName(className)); 40 } catch (Exception e) { 41 try { 43 page = (IPage) new Creator().newInstance(BasePage.class); 44 } catch (Exception e2) { 45 e.printStackTrace(); 46 throw new RuntimeException ("Unable to instantiate '" + className + "'"); 47 } 48 } 49 50 page.setPageName(name); 51 return page; 52 } 53 } 54 | Popular Tags |