KickJava   Java API By Example, From Geeks To Geeks.

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


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.ServiceAccessorImp;
22 import com.jdon.container.finder.ComponentKeys;
23 import com.jdon.container.finder.ServletContainerFinder;
24
25 /**
26  * @author <a HREF="mailto:banqJdon<AT>jdon.com">banq</a>
27  *
28  */

29 public class ServiceFacade {
30     
31     private ServiceFactory serviceFactory;
32     private Service service;
33     
34     private ServletContainerFinder servletContainerFinder;
35     
36     public ServiceFacade(){
37         this.servletContainerFinder = new ServletContainerFinder();
38     }
39     
40
41     /**
42      * the applciation' code get the service instance,
43      * such as:
44      * XXXService xxxService = WeAppUtil.getService("xxxService");
45      *
46      * @return Returns the service.
47      */

48     public Service getService(HttpServletRequest JavaDoc request) {
49         ContainerWrapper containerWrapper = servletContainerFinder.findContainer(request);
50         Service service = (Service)containerWrapper.lookup(ComponentKeys.WEBSERVICE);
51         return service;
52     }
53     
54     /**
55      * the model configure in jdonframework.xml will
56      * execute the service directly.
57      *
58      * and the remote servlet will call this method
59      * @return Returns the serviceFactory.
60      */

61     public ServiceFactory getServiceFactory(HttpServletRequest JavaDoc request) {
62         ContainerWrapper containerWrapper = servletContainerFinder.findContainer(request);
63         ServiceFactory serviceFactory = (ServiceFactory)containerWrapper.lookup(ComponentKeys.WEBSERVICE_FACTORY);
64         return serviceFactory;
65     }
66 }
67
Popular Tags