KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > controller > service > WebServiceDecorator


1 /*
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  */

16 package com.jdon.controller.service;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
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 /**
30  * before accessing container, we can do something and store
31  * some state into UserTargetMetaDef object.
32  *
33  * @author <a HREF="mailto:banqJdon<AT>jdon.com">banq</a>
34  *
35  */

36
37 public class WebServiceDecorator implements WebServiceAccessor {
38
39     
40     private ServiceAccessor serviceAccessor;
41     private ContainerCallback containerCallback;
42         
43     /**
44      * @param serviceAccessor
45      */

46     public WebServiceDecorator(ServiceAccessor serviceAccessor, ContainerCallback containerCallback) {
47         this.serviceAccessor = serviceAccessor;
48         this.containerCallback = containerCallback;
49     }
50     
51     /*
52      * 1. create a SessionContext object in httpsession
53      * 2. save the principle name in the session context.
54      * the principle name the request.getPrincipleNme
55      * you can save more attribute in the SessionContext object by replcaing this class in container.xml
56      *
57      */

58     public Object JavaDoc getService(TargetMetaRequest targetMetaRequest, HttpServletRequest JavaDoc 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     /*
72      * 1. create a SessionContext object in httpsession
73      * 2. save the principle name in the session context.
74      * the principle name the request.getPrincipleNme
75      * you can save more attribute in the SessionContext object by replcaing this class in container.xml
76      */

77     public Object JavaDoc execute(TargetMetaRequest targetMetaRequest, HttpServletRequest JavaDoc request) throws Exception JavaDoc {
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