KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > remoting > http > HttpServiceFactory


1 /**
2  * Copyright (c) 2002 Bright Side Factory. All rights
3  * reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * 3. The end-user documentation included with the redistribution,
18  * if any, must include the following acknowledgment:
19  * "This product includes software developed by the
20  * Bright Side Factory (http://www.bs-factory.org/)."
21  * Alternately, this acknowledgment may appear in the software itself,
22  * if and wherever such third-party acknowledgments normally appear.
23  *
24  * 4. The names "Bright Side", "BS Factory" and "Bright Side Factory" must
25  * not be used to endorse or promote products derived from this
26  * software without prior written permission. For written
27  * permission, please contact info@bs-factory.org.
28  *
29  * 5. Products derived from this software may not be called "Bright Side",
30  * nor may "Bright Side" appear in their name, without prior written
31  * permission of the Apache Software Foundation.
32  *
33  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
37  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
40  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
43  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44  * SUCH DAMAGE.
45  * ====================================================================
46  *
47  * This software consists of voluntary contributions made by many
48  * individuals on behalf of the Bright Side Factory. For more
49  * information on the Bright Side Factory, please see
50  * <http://www.bs-factory.org/>.
51  *
52  */

53 package org.bsf.remoting.http;
54
55 import org.bsf.remoting.ServiceFactory;
56 import org.bsf.remoting.EJBDefinition;
57
58 import java.lang.reflect.Proxy JavaDoc;
59 import java.util.Hashtable JavaDoc;
60 import java.util.Map JavaDoc;
61
62
63 /**
64  * This implementation of ServiceFactory makes returns to the client DynamicProxies to
65  * encapsulate the client calls in http protocol. The client sees its "normal" remote interface.
66  * @version@
67  */

68 public class HttpServiceFactory implements ServiceFactory {
69
70     private static Map JavaDoc _serviceCache = new Hashtable JavaDoc();
71
72
73     public HttpServiceFactory() {
74         super();
75     }
76
77     public HttpServiceFactory(String JavaDoc host, int port, String JavaDoc serverContext) {
78         this(null, host, port, serverContext);
79     }
80
81     public HttpServiceFactory(String JavaDoc protocole, String JavaDoc host, int port, String JavaDoc serverContext) {
82         super();
83         this.setProtocol(protocole);
84         this.setHost(host);
85         this.setPort(port);
86         this.setServerContext(serverContext);
87     }
88
89     /**
90      * Uses the ejbDefinition to return a DynamicProxy that will present the
91      * "good face" to the client.
92      */

93     public Object JavaDoc getService(EJBDefinition p_service) {
94
95         HttpServiceInvocationHandler service = null;
96         Object JavaDoc dynamicProxy = null;
97
98         dynamicProxy = _serviceCache.get(p_service);
99         if (dynamicProxy == null) {
100             service = new HttpServiceInvocationHandler(p_service);
101             dynamicProxy = Proxy.newProxyInstance(HttpServiceInvocationHandler.class.getClassLoader(),
102                     new Class JavaDoc[]{p_service.getRemoteClass()}, service);
103             _serviceCache.put(p_service, dynamicProxy);
104         }
105         return dynamicProxy;
106     }
107
108     public void setPort(int port) {
109         HttpSessionClient.getInstance().setPort(port);
110     }
111
112     public void setHost(String JavaDoc host) {
113         HttpSessionClient.getInstance().setHost(host);
114     }
115
116     public void setProtocol(String JavaDoc protocole){
117         HttpSessionClient.getInstance().setProtocol(protocole);
118     }
119
120
121     /**
122      * @deprecated Use setServerContext() instead.
123      * @param file
124      */

125     public void setServerFile(String JavaDoc file) {
126         HttpSessionClient.getInstance().setServerFile(file);
127     }
128
129     /**
130      * Set the context used at deployment time. For instance if the packaging of
131      * the remoting war inside of the ear use the context myApp, you should call
132      * setContext("myApp") on the HttpServiceFactory to reach the server.
133      * @param context
134      */

135     public void setServerContext(String JavaDoc context){
136         HttpSessionClient.getInstance().setContext(context);
137
138     }
139
140     public void setThreadCount(int count) {
141         HttpSessionClient.getInstance().setThreadCount(count);
142     }
143
144     public void setLogin(String JavaDoc login) {
145         HttpSessionClient.getInstance().setLogin(login);
146     }
147
148     public void setPassword(String JavaDoc password){
149         HttpSessionClient.getInstance().setPassword(password);
150     }
151 }
Popular Tags