1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package com.mjh.switchrmi;
28
29 import java.util.*;
30
31 import javax.naming.*;
32
33 import org.apache.log4j.*;
34
35 public class GenericReferenceable
36 implements Referenceable
37 {
38 private static final Logger log =
39 Logger.getLogger(GenericReferenceable.class.getName());
40 private String className = "java.lang.Object";
41 private String codebase;
42 private List libs = new ArrayList();
43 private String description;
44 private String factoryClassName =
45 "com.mjh.switchrmi.jndi.ObjectFactoryImpl";
46
47 public GenericReferenceable()
48 {
49 }
50
51 public GenericReferenceable(String name)
52 {
53 className = name;
54 }
55
56 public String toString()
57 {
58 StringBuffer sb = new StringBuffer();
59
60 sb.append("<GenericReferenceable\n");
61 appendMembers(sb);
62 sb.append("</GenericReferenceable>");
63
64 return sb.toString();
65 }
66
67 protected void appendMembers(StringBuffer sb)
68 {
69 sb.append(" <className>" + className + "</className>");
70 sb.append(" <codebase>" + codebase + "</codebase>");
71 sb.append(" <description>" + description + "</description>");
72 sb.append(" <factoryClassName>" + factoryClassName
73 + "</factoryClassName>");
74 sb.append(" <libs>" + libs + "</libs>");
75 }
76
77 public void setClassName(String value)
78 {
79 className = value;
80 }
81
82 public String getClassName()
83 {
84 return className;
85 }
86
87 public void setCodebase(String value)
88 {
89 codebase = value;
90 }
91
92 public String getCodebase()
93 {
94 return codebase;
95 }
96
97 public void addLibrary(String value)
98 {
99 libs.add(value);
100 }
101
102 public List getLibraries()
103 {
104 return libs;
105 }
106
107 public void setDescription(String value)
108 {
109 description = value;
110 }
111
112 public String getDescription()
113 {
114 return description;
115 }
116
117 public void setFactoryClassName(String value)
118 {
119 factoryClassName = value;
120 }
121
122 public String getFactoryClassName()
123 {
124 return factoryClassName;
125 }
126
127 public Reference getReference()
128 throws NamingException
129 {
130 return new Reference(className, factoryClassName,
131 buildClasspath(codebase, libs));
132 }
133
134 private String buildClasspath(String baseUrl, List libs)
135 {
136 String path = null;
137
138 if (baseUrl != null)
139 {
140 if (!baseUrl.endsWith("/"))
141 {
142 baseUrl += "/";
143 }
144
145 StringBuffer sb = new StringBuffer();
146
147 sb.append(baseUrl);
148
149 if (libs.size() > 0)
150 {
151 sb.append(" ");
152 }
153
154 Iterator iter = libs.iterator();
155
156 while (iter.hasNext())
157 {
158 String lib = (String) iter.next();
159
160 while (lib.startsWith("/"))
161 {
162 lib = lib.substring(1);
163 }
164
165 sb.append(baseUrl);
166 sb.append(lib);
167
168 if (iter.hasNext())
169 {
170 sb.append(" ");
171 }
172 }
173
174 path = sb.toString();
175 }
176
177 if (log.isDebugEnabled())
178 {
179 log.debug("path = " + path);
180 }
181
182 return path;
183 }
184 }