blob: 8c988ab16dd7fa65ed12a12cce39a6a78763ad87 (
plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/* Copyright (C) 2001 Free Software Foundation
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
package javax.naming.ldap;
import javax.naming.*;
import java.util.StringTokenizer;
import java.util.Hashtable;
/**
* @author Tom Tromey <tromey@redhat.com>
* @date June 22, 2001
*/
public abstract class ControlFactory
{
protected ControlFactory ()
{
}
public abstract Control getControlInstance (Control control)
throws NamingException;
public static Control getControlInstance (Control control,
Context ctx,
Hashtable env)
throws NamingException
{
String path = (String) env.get (LdapContext.CONTROL_FACTORIES);
String path2 = null;
if (ctx != null)
path2 = (String) ctx.getEnvironment ().get (LdapContext.CONTROL_FACTORIES);
if (path == null)
path = path2;
else if (path2 != null)
path += ":" + path2;
StringTokenizer tokens = new StringTokenizer (path, ":");
while (tokens.hasMoreTokens ())
{
String name = tokens.nextToken ();
try
{
Class k = Class.forName (name);
ControlFactory cf = (ControlFactory) k.newInstance ();
Control ctrl = cf.getControlInstance (control);
if (ctrl != null)
return ctrl;
}
catch (ClassNotFoundException _1)
{
// Ignore it.
}
catch (ClassCastException _2)
{
// Ignore it.
}
catch (InstantiationException _3)
{
// If we couldn't instantiate the factory we might get
// this.
}
catch (IllegalAccessException _4)
{
// Another possibility when instantiating.
}
}
return control;
}
}
|