KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > providers > java > RMIProvider


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

16
17 package org.apache.axis.providers.java;
18
19 import org.apache.axis.Constants;
20 import org.apache.axis.Handler;
21 import org.apache.axis.MessageContext;
22 import org.apache.axis.components.logger.LogFactory;
23 import org.apache.commons.logging.Log;
24
25 import java.rmi.Naming JavaDoc;
26 import java.rmi.RMISecurityManager JavaDoc;
27
28 /**
29  * A basic RMI Provider
30  *
31  * @author Davanum Srinivas (dims@yahoo.com)
32  */

33 public class RMIProvider extends RPCProvider {
34     protected static Log log =
35             LogFactory.getLog(RMIProvider.class.getName());
36
37     // The enterprise category is for stuff that an enterprise product might
38
// want to track, but in a simple environment (like the AXIS build) would
39
// be nothing more than a nuisance.
40
protected static Log entLog =
41             LogFactory.getLog(Constants.ENTERPRISE_LOG_CATEGORY);
42
43     public static final String JavaDoc OPTION_NAMING_LOOKUP = "NamingLookup";
44     public static final String JavaDoc OPTION_INTERFACE_CLASSNAME = "InterfaceClassName";
45
46     /**
47      * Return a object which implements the service.
48      *
49      * @param msgContext the message context
50      * @param clsName The JNDI name of the EJB home class
51      * @return an object that implements the service
52      */

53     protected Object JavaDoc makeNewServiceObject(MessageContext msgContext,
54                                           String JavaDoc clsName)
55             throws Exception JavaDoc {
56         // Read deployment descriptor options
57
String JavaDoc namingLookup = getStrOption(OPTION_NAMING_LOOKUP, msgContext.getService());
58         if (System.getSecurityManager() == null) {
59             System.setSecurityManager(new RMISecurityManager JavaDoc());
60         }
61         Object JavaDoc targetObject = Naming.lookup(namingLookup);
62         return targetObject;
63     }
64
65     /**
66      * Return the option in the configuration that contains the service class
67      * name.
68      */

69     protected String JavaDoc getServiceClassNameOptionName() {
70         return OPTION_INTERFACE_CLASSNAME;
71     }
72
73     /**
74      * Get a String option by looking first in the service options,
75      * and then at the Handler's options. This allows defaults to be
76      * specified at the provider level, and then overriden for particular
77      * services.
78      *
79      * @param optionName the option to retrieve
80      * @return String the value of the option or null if not found in
81      * either scope
82      */

83     protected String JavaDoc getStrOption(String JavaDoc optionName, Handler service) {
84         String JavaDoc value = null;
85         if (service != null)
86             value = (String JavaDoc) service.getOption(optionName);
87         if (value == null)
88             value = (String JavaDoc) getOption(optionName);
89         return value;
90     }
91 }
92
Popular Tags