1    //
2    // SwitchRMI  Framework
3    // Copyright (c) 2000-2002 by Michael J. Henderson & Associates.
4    //
5    // Michael Henderson
6    // http://switchrmi.sf.net
7    // mailto:mikehenderson@dunelm.org.uk
8    //
9    // This library is free software.
10   //
11   // You may redistribute it and/or modify it under the terms of the GNU
12   // Lesser General Public License as published by the Free Software Foundation.
13   //
14   // Version 2.1 of the license should be included with this distribution in
15   // the file LICENSE, as well as License.html. If the license is not
16   // included with this distribution, you may find a copy at the FSF web
17   // site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
18   // Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
19   //
20   // This library is distributed in the hope that it will be useful,
21   // but WITHOUT ANY WARRANTY; without even the implied waranty of
22   // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23   // Lesser General Public License for more details.
24   //
25   // $Id: RmiObjectFactoryBase.java,v 1.1 2002/11/11 22:19:48 mikehenderson Exp $
26   //
27   package com.mjh.switchrmi.jndi;
28   
29   import com.mjh.switchrmi.*;
30   
31   import java.net.*;
32   
33   import java.util.*;
34   
35   import javax.naming.*;
36   
37   import org.apache.log4j.*;
38   
39   public abstract class RmiObjectFactoryBase
40   {
41       private static final Logger log = 
42               Logger.getLogger(RmiObjectFactoryBase.class.getName());
43   
44       protected String getClassName(Name name, Hashtable env)
45       {
46           GenericReferenceable ref = 
47                   (GenericReferenceable) env.get(name.get(name.size() - 1));
48   
49           return ref.getClassName();
50       }
51   
52       protected Class[] getInterfaces(Name name, Hashtable env, 
53                                       ClassLoader loader)
54                                throws ClassNotFoundException
55       {
56           ObjectReferenceable ref = 
57                   (ObjectReferenceable) env.get(name.get(name.size() - 1));
58           String[] strings = ref.getInterfaces();
59           Class[] classes = new Class[strings.length];
60   
61           for (int i = 0; i < strings.length; i++)
62           {
63               classes[i] = loader.loadClass(strings[i]);
64           }
65   
66           return classes;
67       }
68   
69       protected URL[] getCodebase(Name name, Hashtable env)
70                            throws Exception
71       {
72           URL[] result = null;
73           ObjectReferenceable ref = 
74                   (ObjectReferenceable) env.get(name.get(name.size() - 1));
75   
76           if (log.isDebugEnabled())
77           {
78               log.debug("ref = " + ref);
79           }
80   
81           String codebase = ref.getCodebase();
82           List libs = ref.getLibraries();
83   
84           if (log.isDebugEnabled())
85           {
86               log.debug("libs = " + libs);
87           }
88   
89           if (codebase != null)
90           {
91               int numLibs = libs.size();
92   
93               if (log.isDebugEnabled())
94               {
95                   log.debug("numLibs = " + numLibs);
96               }
97   
98               result = new URL[1 + numLibs];
99               result[0] = new URL(codebase);
100  
101              for (int i = 0; i < numLibs; i++)
102              {
103                  String lib = (String) libs.get(i);
104  
105                  result[i + 1] = new URL(lib);
106              }
107          }
108  
109          return result;
110      }
111  
112      protected Object getTypeInfoValue(String typeKey, Name name, Hashtable env)
113      {
114          ObjectReferenceable ref = 
115                  (ObjectReferenceable) env.get(name.get(name.size() - 1));
116  
117          return ref.getTypeValue(typeKey);
118      }
119  }