KickJava   Java API By Example, From Geeks To Geeks.

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


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.bussinessproxy.TargetMetaDef;
21 import com.jdon.container.ContainerWrapper;
22 import com.jdon.container.access.ServiceAccessor;
23 import com.jdon.container.access.TargetMetaRequest;
24 import com.jdon.container.access.UserTargetMetaDefFactory;
25 import com.jdon.container.finder.ContainerCallback;
26 import com.jdon.container.finder.ServletContainerFinder;
27 import com.jdon.util.Debug;
28
29 /**
30  * the defualt concrete class of ServiceFactory
31  * by this class, we can get a service instance;
32  *
33  *
34  * @author banq
35  * @see {@link ServiceFactory}
36  */

37 public class WebServiceFactory implements ServiceFactory {
38
39     private final static String JavaDoc module = WebServiceFactory.class.getName();
40
41     private ContainerCallback containerCallback;
42     private WebServiceAccessor webServiceAccessor;
43     
44     public WebServiceFactory(WebServiceAccessor webServiceAccessor,
45                              ContainerCallback containerCallback){
46         this.webServiceAccessor = webServiceAccessor;
47         this.containerCallback = containerCallback;
48     }
49
50     public Object JavaDoc getService(String JavaDoc name, HttpServletRequest JavaDoc request) {
51         Debug.logVerbose("<==============================>start: JdonFramework core entrance", module);
52         Debug.logVerbose("<===============>Looking up new service='"+ name + "'", module);
53         ContainerWrapper cw = containerCallback.getContainerWrapper();
54         TargetMetaDef targetMetaDef = UserTargetMetaDefFactory.getTargetMetaDef(name, cw);
55         if (targetMetaDef == null) return null;
56         Debug.logVerbose("[JdonFramework] service=" + name + " found, and now return the service instance", module);
57         Object JavaDoc result = getService(targetMetaDef, request);
58         Debug.logVerbose("<===============>found service='" + name + "' instance and return it successfully!", module);
59         Debug.logVerbose("<==============================>over", module);
60         return result;
61     }
62  
63     /**
64      * get a service instance
65      * the service must have a interface and implements it.
66      *
67      */

68     public Object JavaDoc getService(TargetMetaDef targetMetaDef, HttpServletRequest JavaDoc request) {
69         TargetMetaRequest targetMetaRequest = UserTargetMetaDefFactory.create(targetMetaDef, request);
70         return webServiceAccessor.getService(targetMetaRequest, request);
71     }
72         
73
74 }
75
Popular Tags