KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > container > access > UserTargetMetaDefFactory


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.container.access;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19
20 import com.jdon.bussinessproxy.TargetMetaDef;
21 import com.jdon.bussinessproxy.config.TargetMetaDefLoader;
22 import com.jdon.container.ContainerWrapper;
23 import com.jdon.container.finder.ComponentKeys;
24 import com.jdon.container.finder.ServletContainerFinder;
25 import com.jdon.container.visitor.ComponentVisitor;
26 import com.jdon.container.visitor.VisitorFactory;
27 import com.jdon.util.Debug;
28
29 /**
30  * @author <a HREF="mailto:banqiao@jdon.com">banq</a>
31  *
32  */

33 public class UserTargetMetaDefFactory {
34     private final static String JavaDoc module = UserTargetMetaDefFactory.class.getName();
35     
36     private static ServletContainerFinder servletContainerFinder = new ServletContainerFinder();
37     
38     public static TargetMetaDef getTargetMetaDef(String JavaDoc name, ContainerWrapper cw){
39         TargetMetaDefLoader targetMetaDefLoader = (TargetMetaDefLoader) cw.lookup(ComponentKeys.SERVICE_METALOADER_NAME);
40         TargetMetaDef targetMetaDef = targetMetaDefLoader.getTargetMetaDef(name);
41         if (targetMetaDef == null){
42             Debug.logError("[JdonFramework] not found service definition in jdonframework.xml for " + name, module);
43             return null;
44         }
45         return targetMetaDef;
46     }
47
48     /**
49      * create a UserTargetMetaDef instance.
50      *
51      * @param containerWrapper
52      * @param targetMetaDef
53      * @param request
54      * @return
55      */

56     public static TargetMetaRequest create(TargetMetaDef targetMetaDef,
57                                            HttpServletRequest JavaDoc request){
58         ContainerWrapper containerWrapper = servletContainerFinder.findContainer(request);
59         TargetMetaRequest targetMetaRequest = new TargetMetaRequest(targetMetaDef);
60         VisitorFactory visitorFactory = (VisitorFactory)containerWrapper.lookup(ComponentKeys.VISITOR_FACTORY);
61         ComponentVisitor cm = visitorFactory.getVisitor(request, targetMetaRequest.getTargetMetaDef());
62         targetMetaRequest.setComponentVisitor(cm);
63         return targetMetaRequest;
64     }
65     
66
67 }
68
Popular Tags