001 package railo.runtime; 002 003 import java.util.HashMap; 004 import java.util.Map; 005 006 import railo.runtime.dump.DumpUtil; 007 import railo.runtime.exp.ApplicationException; 008 import railo.runtime.exp.PageException; 009 import railo.runtime.op.Caster; 010 import railo.runtime.type.KeyImpl; 011 012 /** 013 * A Page that can produce Components 014 */ 015 public abstract class InterfacePage extends PagePlus { 016 017 private static final railo.runtime.type.Collection.Key METHOD = KeyImpl.intern("method"); 018 private static final railo.runtime.type.Collection.Key COMPONENT = KeyImpl.intern("component"); 019 020 021 /** 022 * @see railo.runtime.Page#call(railo.runtime.PageContext) 023 */ 024 public void call(PageContext pc) throws PageException { 025 try { 026 pc.setSilent(); 027 InterfaceImpl interf = null; 028 try { 029 interf = newInstance(getPageSource().getComponentName(),false,new HashMap()); 030 } 031 finally { 032 pc.unsetSilent(); 033 } 034 035 String qs=pc. getHttpServletRequest().getQueryString(); 036 if(pc.getBasePageSource()==this.getPageSource()) 037 pc.getDebugger().setOutput(false); 038 boolean isPost=pc. getHttpServletRequest().getMethod().equalsIgnoreCase("POST"); 039 040 // POST 041 if(isPost) { 042 // Soap 043 if(ComponentPage.isSoap(pc)) 044 throw new ApplicationException("can not instantiate interface ["+this.getPageSource().getComponentName()+"] as a component"); 045 } 046 // GET 047 else if(qs!=null && qs.trim().equalsIgnoreCase("wsdl")) 048 throw new ApplicationException("can not instantiate interface ["+this.getPageSource().getComponentName()+"] as a component"); 049 050 // WDDX 051 if(pc.urlFormScope().containsKey(METHOD)) 052 throw new ApplicationException("can not instantiate interface ["+this.getPageSource().getComponentName()+"] as a component"); 053 054 // invoking via include 055 if(pc.getTemplatePath().size()>1) { 056 throw new ApplicationException("can not invoke interface ["+this.getPageSource().getComponentName()+"] as a page"); 057 } 058 059 // DUMP 060 //TODO component.setAccess(pc,Component.ACCESS_PUBLIC); 061 String cdf = pc.getConfig().getComponentDumpTemplate(); 062 if(cdf!=null && cdf.trim().length()>0) { 063 pc.variablesScope().set(COMPONENT,interf); 064 pc.doInclude(cdf); 065 } 066 else pc.write(pc.getConfig().getDefaultDumpWriter().toString(pc,interf.toDumpData(pc, 9999,DumpUtil.toDumpProperties()),true)); 067 068 } 069 catch(Throwable t) { 070 throw Caster.toPageException(t);//Exception Handler.castAnd Stack(t, this, pc); 071 } 072 } 073 074 public abstract void initInterface(InterfaceImpl i) 075 throws PageException; 076 077 public abstract InterfaceImpl newInstance(String callPath,boolean isRealPath,Map interfaceUDFs) 078 throws railo.runtime.exp.PageException; 079 080 }