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: ObjectReferenceable.java,v 1.1 2002/11/11 22:19:48 mikehenderson Exp $
26   //
27   package com.mjh.switchrmi;
28   
29   import java.util.*;
30   
31   import javax.naming.*;
32   
33   public class ObjectReferenceable
34       extends GenericReferenceable
35       implements Referenceable
36   {
37       private static Map types = new HashMap();
38   
39       static
40       {
41           types.put("java", "com.mjh.switchrmi.jndi.RmiJavaObjectFactory");
42           types.put("script", "com.mjh.switchrmi.jndi.RmiScriptObjectFactory");
43           types.put("remote", "com.mjh.switchrmi.jndi.RmiProxyObjectFactory");
44       }
45   
46       public static final String INTERFACE_ADDR = "interface";
47       String name;
48       String scope;
49       List interfaces = new ArrayList();
50       String type;
51       Map typeInfo;
52   
53       public ObjectReferenceable()
54       {
55       }
56   
57       public String toString()
58       {
59           StringBuffer sb = new StringBuffer();
60   
61           sb.append("<ObjectReferenceable\n");
62           appendMembers(sb);
63           sb.append("</ObjectReferenceable>");
64   
65           return sb.toString();
66       }
67   
68       protected void appendMembers(StringBuffer sb)
69       {
70           sb.append("  <name>" + name + "</name>");
71           sb.append("  <scope>" + scope + "</scope>");
72           sb.append("  <type>" + type + "</type>");
73           sb.append("  <typeInfo>" + typeInfo + "</typeInfo>");
74           super.appendMembers(sb);
75       }
76   
77       public void setName(String value)
78       {
79           name = value;
80       }
81   
82       public String getName()
83       {
84           return name;
85       }
86   
87       public void setScope(String value)
88       {
89           scope = value;
90       }
91   
92       public String getScope()
93       {
94           return scope;
95       }
96   
97       public void addInterface(String interfaceName)
98       {
99           interfaces.add(interfaceName);
100      }
101  
102      public void setType(String value)
103      {
104          type = value;
105          super.setFactoryClassName((String) types.get(type));
106      }
107  
108      public void setTypeInfo(Map info)
109      {
110          typeInfo = info;
111      }
112  
113      public String[] getInterfaces()
114      {
115          int size = interfaces.size();
116          String[] strings = new String[size];
117  
118          for (int i = 0; i < size; i++)
119          {
120              strings[i] = (String) interfaces.get(i);
121          }
122  
123          return strings;
124      }
125  
126      public Object getTypeValue(String key)
127      {
128          return typeInfo.get(key);
129      }
130  }