1 16 package com.jdon.controller.service; 17 18 import javax.servlet.http.HttpServletRequest ; 19 20 import com.jdon.container.ContainerWrapper; 21 import com.jdon.container.access.ServiceAccessor; 22 import com.jdon.container.access.TargetMetaRequest; 23 import com.jdon.container.finder.ComponentKeys; 24 import com.jdon.container.finder.ContainerCallback; 25 import com.jdon.container.visitor.ComponentVisitor; 26 import com.jdon.container.visitor.data.SessionContext; 27 import com.jdon.container.visitor.data.SessionContextSetup; 28 29 36 37 public class WebServiceDecorator implements WebServiceAccessor { 38 39 40 private ServiceAccessor serviceAccessor; 41 private ContainerCallback containerCallback; 42 43 46 public WebServiceDecorator(ServiceAccessor serviceAccessor, ContainerCallback containerCallback) { 47 this.serviceAccessor = serviceAccessor; 48 this.containerCallback = containerCallback; 49 } 50 51 58 public Object getService(TargetMetaRequest targetMetaRequest, HttpServletRequest request) { 59 ContainerWrapper cw = containerCallback.getContainerWrapper(); 60 SessionContextSetup sessionContextSetup = (SessionContextSetup)cw.lookup(ComponentKeys.SESSIONCONTEXT_SETUP); 61 62 targetMetaRequest.setVisitableName(ComponentKeys.SESSIONCONTEXT_FACTORY); 63 ComponentVisitor componentVisitor = targetMetaRequest.getComponentVisitor(); 64 SessionContext sessionContext = (SessionContext)componentVisitor.visitSessionContext(targetMetaRequest); 65 66 targetMetaRequest.setSessionContext(sessionContext); 67 sessionContextSetup.setup(sessionContext, request); 68 return serviceAccessor.getService(targetMetaRequest); 69 } 70 71 77 public Object execute(TargetMetaRequest targetMetaRequest, HttpServletRequest request) throws Exception { 78 ContainerWrapper cw = containerCallback.getContainerWrapper(); 79 SessionContextSetup sessionContextSetup = (SessionContextSetup)cw.lookup(ComponentKeys.SESSIONCONTEXT_SETUP); 80 81 targetMetaRequest.setVisitableName(ComponentKeys.SESSIONCONTEXT_FACTORY); 82 ComponentVisitor componentVisitor = targetMetaRequest.getComponentVisitor(); 83 SessionContext sessionContext = (SessionContext)componentVisitor.visitSessionContext(targetMetaRequest); 84 85 targetMetaRequest.setSessionContext(sessionContext); 86 sessionContextSetup.setup(sessionContext, request); 87 return serviceAccessor.executeService(targetMetaRequest, cw); 88 } 89 90 } 91 | Popular Tags |