1 15 package org.apache.tapestry.engine; 16 17 import java.io.IOException ; 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import org.apache.hivemind.ApplicationRuntimeException; 22 import org.apache.hivemind.util.Defense; 23 import org.apache.tapestry.IExternalPage; 24 import org.apache.tapestry.IPage; 25 import org.apache.tapestry.IRequestCycle; 26 import org.apache.tapestry.Tapestry; 27 import org.apache.tapestry.services.LinkFactory; 28 import org.apache.tapestry.services.ResponseRenderer; 29 import org.apache.tapestry.services.ServiceConstants; 30 31 112 113 public class ExternalService implements IEngineService 114 { 115 116 117 private ResponseRenderer _responseRenderer; 118 119 120 private LinkFactory _linkFactory; 121 122 public ILink getLink(IRequestCycle cycle, Object parameter) 123 { 124 Defense.isAssignable(parameter, ExternalServiceParameter.class, "parameter"); 125 126 ExternalServiceParameter esp = (ExternalServiceParameter) parameter; 127 128 Map parameters = new HashMap (); 129 parameters.put(ServiceConstants.SERVICE, Tapestry.EXTERNAL_SERVICE); 130 parameters.put(ServiceConstants.PAGE, esp.getPageName()); 131 parameters.put(ServiceConstants.PARAMETER, esp.getServiceParameters()); 132 133 return _linkFactory.constructLink(cycle, parameters, true); 134 } 135 136 public void service(IRequestCycle cycle) throws IOException 137 { 138 String pageName = cycle.getParameter(ServiceConstants.PAGE); 139 IPage rawPage = cycle.getPage(pageName); 140 141 IExternalPage page = null; 142 143 try 144 { 145 page = (IExternalPage) rawPage; 146 } 147 catch (ClassCastException ex) 148 { 149 throw new ApplicationRuntimeException(EngineMessages.pageNotCompatible( 150 rawPage, 151 IExternalPage.class), rawPage, null, ex); 152 } 153 154 Object [] parameters = _linkFactory.extractListenerParameters(cycle); 155 156 cycle.setListenerParameters(parameters); 157 158 cycle.activate(page); 159 160 page.activateExternalPage(parameters, cycle); 161 162 _responseRenderer.renderResponse(cycle); 163 } 164 165 public String getName() 166 { 167 return Tapestry.EXTERNAL_SERVICE; 168 } 169 170 171 172 public void setResponseRenderer(ResponseRenderer responseRenderer) 173 { 174 _responseRenderer = responseRenderer; 175 } 176 177 178 public void setLinkFactory(LinkFactory linkFactory) 179 { 180 _linkFactory = linkFactory; 181 } 182 } | Popular Tags |