1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.ldap.server.configuration;
20
21 import java.io.Serializable;
22 import java.util.Hashtable;
23
24 import org.apache.ldap.server.jndi.ContextFactoryService;
25
26 /***
27 * A configuration that provides required, optional, or default properties
28 * to configure {@link ContextFactoryService}.
29 *
30 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
31 * @version $Rev: 264732 $, $Date: 2005-08-30 04:04:51 -0400 (Tue, 30 Aug 2005) $
32 */
33 public abstract class Configuration implements Cloneable, Serializable
34 {
35 /***
36 * A JNDI environment key that configuration instance is put on.
37 */
38 public static final String JNDI_KEY = Configuration.class.getName();
39
40 /***
41 * The default ID of {@link ContextFactoryService} that is used
42 * when no instance ID is specified.
43 */
44 public static final String DEFAULT_INSTANCE_ID = "default";
45
46 /***
47 * Gets {@link Configuration} instance from the specified JNDI environment
48 * {@link Hashtable}.
49 *
50 * @throws ConfigurationException if the specified environment doesn't
51 * contain the configuration instance.
52 */
53 public static Configuration toConfiguration( Hashtable jndiEnvironment )
54 {
55 Object value = jndiEnvironment.get( JNDI_KEY );
56 if( value == null || !( value instanceof Configuration ) )
57 {
58 throw new ConfigurationException( "Not an ApacheDS configuration: " + value );
59 }
60
61 return ( Configuration ) value;
62 }
63
64 private String instanceId = DEFAULT_INSTANCE_ID;
65
66 /***
67 * Creates a new instance.
68 */
69 protected Configuration()
70 {
71 }
72
73 /***
74 * Returns the ID of {@link ContextFactoryService} instance to configure.
75 */
76 public String getInstanceId()
77 {
78 return instanceId;
79 }
80
81 /***
82 * Sets the ID of {@link ContextFactoryService} instance to configure.
83 */
84 protected void setInstanceId( String instanceId )
85 {
86 instanceId = instanceId.trim();
87 this.instanceId = instanceId;
88 }
89
90 /***
91 * Validates this configuration.
92 * @throws ConfigurationException if this configuration is not valid
93 */
94 public void validate()
95 {
96 }
97
98 /***
99 * Converts this configuration to JNDI environment {@link Hashtable}.
100 * This method simple returns a {@link Hashtable} that contains an entry
101 * whose key is {@link #JNDI_KEY} and whose value is <tt>this</tt>.
102 */
103 public Hashtable toJndiEnvironment()
104 {
105 Hashtable env = new Hashtable();
106 env.put( JNDI_KEY, this );
107 return env;
108 }
109
110 public Object clone()
111 {
112 try
113 {
114 return super.clone();
115 }
116 catch( CloneNotSupportedException e )
117 {
118 throw new InternalError();
119 }
120 }
121 }