1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44:
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55:
56:
60: public class DirectoryManager extends NamingManager
61: {
62:
63: DirectoryManager ()
64: {
65: }
66:
67: public static DirContext getContinuationDirContext (CannotProceedException c)
68: throws NamingException
69: {
70: return (DirContext) getContinuationContext (c);
71: }
72:
73:
74:
75: private static Object tryCreateObject (ObjectFactory factory,
76: Object refInfo,
77: Name name,
78: Context nameCtx,
79: Hashtable environment,
80: Attributes attrs)
81: throws Exception
82: {
83: if (factory instanceof DirObjectFactory)
84: {
85: DirObjectFactory dof = (DirObjectFactory) factory;
86: return dof.getObjectInstance (refInfo, name, nameCtx,
87: environment, attrs);
88: }
89: else
90: return factory.getObjectInstance (refInfo, name, nameCtx,
91: environment);
92: }
93:
94: public static Object getObjectInstance (Object refInfo, Name name,
95: Context nameCtx,
96: Hashtable<?, ?> environment,
97: Attributes attrs)
98: throws Exception
99: {
100: ObjectFactory factory = null;
101:
102: if (ofb != null)
103: factory = ofb.createObjectFactory (refInfo, environment);
104: else
105: {
106:
107:
108: Object ref2 = refInfo;
109: if (refInfo instanceof Referenceable)
110: ref2 = ((Referenceable) refInfo).getReference ();
111: if (ref2 instanceof Reference)
112: {
113: Reference ref = (Reference) ref2;
114:
115:
116: String fClass = ref.getFactoryClassName ();
117: if (fClass != null)
118: {
119:
120: Class k = Class.forName (fClass);
121: factory = (ObjectFactory) k.newInstance ();
122: }
123: else
124: {
125:
126:
127:
128: Enumeration e = ref.getAll ();
129: while (e.hasMoreElements ())
130: {
131: RefAddr ra = (RefAddr) e.nextElement ();
132: if (ra instanceof StringRefAddr
133: && "URL".equals (ra.getType ()))
134: {
135: factory
136: = (ObjectFactory) getURLContext (refInfo,
137: name,
138: nameCtx,
139: (String) ra.getContent (),
140: environment);
141: Object obj = tryCreateObject (factory,
142: refInfo,
143: name,
144: nameCtx,
145: environment,
146: attrs);
147: if (obj != null)
148: return obj;
149: }
150: }
151:
152:
153: factory = null;
154: }
155: }
156:
157:
158: if (factory == null)
159: {
160: StringTokenizer tokens = getPlusPath (Context.OBJECT_FACTORIES,
161: environment, nameCtx);
162:
163: while (tokens.hasMoreTokens ())
164: {
165: String klassName = tokens.nextToken ();
166: Class k = Class.forName (klassName);
167: factory = (ObjectFactory) k.newInstance ();
168: Object obj = tryCreateObject (factory, refInfo, name,
169: nameCtx, environment, attrs);
170: if (obj != null)
171: return obj;
172: }
173:
174:
175: return refInfo;
176: }
177: }
178:
179: if (factory == null)
180: return refInfo;
181: Object obj = tryCreateObject (factory, refInfo, name,
182: nameCtx, environment, attrs);
183: return obj == null ? refInfo : obj;
184: }
185:
186: public static DirStateFactory.Result getStateToBind (Object obj,
187: Name name,
188: Context nameCtx,
189: Hashtable<?, ?> environment,
190: Attributes attrs)
191: throws NamingException
192: {
193: StringTokenizer tokens = getPlusPath (Context.STATE_FACTORIES,
194: environment, nameCtx);
195: while (tokens.hasMoreTokens ())
196: {
197: String klassName = tokens.nextToken ();
198: try
199: {
200: Class k = Class.forName (klassName);
201: StateFactory factory = (StateFactory) k.newInstance ();
202:
203: DirStateFactory.Result result = null;
204: if (factory instanceof DirStateFactory)
205: {
206: DirStateFactory dsf = (DirStateFactory) factory;
207: result = dsf.getStateToBind (obj, name, nameCtx, environment,
208: attrs);
209: }
210: else
211: {
212: Object o = factory.getStateToBind (obj, name, nameCtx,
213: environment);
214: if (o != null)
215: result = new DirStateFactory.Result (o, attrs);
216: }
217: if (result != null)
218: return result;
219: }
220: catch (ClassNotFoundException _1)
221: {
222:
223: }
224: catch (ClassCastException _2)
225: {
226:
227:
228:
229: }
230: catch (InstantiationException _3)
231: {
232:
233:
234: }
235: catch (IllegalAccessException _4)
236: {
237:
238: }
239: }
240:
241: return new DirStateFactory.Result (obj, attrs);
242: }
243: }