KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > usermanager > ServerBean


1 package org.jahia.services.usermanager;
2
3 import java.util.Hashtable JavaDoc;
4 import javax.naming.Context JavaDoc;
5
6 /**
7  * <p>Title: Stores server configuration as described in xml router files.</p>
8  * <p>Description: completely specify a server associated to a provider.</p>
9  *
10  * @author EP
11  * @version 3.0
12  */

13 public class ServerBean {
14
15     // Hashtable to store parameters for public context
16
private Hashtable JavaDoc publicParameters;
17     // Hashtable to store parameters for private context
18
private Hashtable JavaDoc privateParameters;
19     
20     // the priority of the server
21
private int priority;
22     // the max tries for reconnection
23
private int maxReconn;
24     // the provider associated to this server
25
private String JavaDoc provider;
26
27     private static final int DEFAULT_PRIORITY = 99;
28     private static final int DEFAULT_RECONN = 1;
29     
30     /**
31      * Constructor.
32      * @param newPriority String, the priority read from xml file.
33      * @param newProvider String, the provider read from xml file.
34      * @param newMaxReconn String, the maximum reconnection tries read from xml file.
35      */

36     public ServerBean (String JavaDoc newPriority, String JavaDoc newProvider, String JavaDoc newMaxReconn) {
37         try {
38             priority = Integer.parseInt (newPriority);
39             } catch (Exception JavaDoc e) {
40                     priority = DEFAULT_PRIORITY;
41             }
42
43         try {
44             maxReconn = Integer.parseInt (newMaxReconn);
45             } catch (Exception JavaDoc e) {
46                     maxReconn = DEFAULT_RECONN;
47             }
48             
49         provider = newProvider;
50         
51         publicParameters = new Hashtable JavaDoc(11);
52         privateParameters = new Hashtable JavaDoc(11);
53     }
54     
55     /**
56      * Return this server priority.
57      * @return String.
58      */

59     public int getPriority() {
60         return priority;
61     }
62
63     /**
64      * Return this server provider.
65      * @return String.
66      */

67     public String JavaDoc getProvider() {
68         return provider;
69     }
70
71     /**
72      * Return this server maximum reconnection tries.
73      * @return int.
74      */

75     public int getMaxReconnection() {
76         return maxReconn;
77     }
78         
79     /**
80      * Set this server factory name.
81      * @param factoryName String, get from xml configuration file.
82      */

83     public void setFactoryName(String JavaDoc factoryName) {
84         if (factoryName != null && factoryName.length() > 0) {
85             publicParameters.put (Context.INITIAL_CONTEXT_FACTORY, factoryName);
86             privateParameters.put (Context.INITIAL_CONTEXT_FACTORY, factoryName);
87         }
88     }
89
90     /**
91      * Set this server url.
92      * @param url String, get from xml configuration file.
93      */

94     public void setServerUrl(String JavaDoc url) {
95         if (url != null && url.length() > 0) {
96             publicParameters.put (Context.PROVIDER_URL, url);
97             privateParameters.put (Context.PROVIDER_URL, url);
98         }
99     }
100     
101     /**
102      * Set this server factory userName.
103      * @param userName String, get from xml configuration file.
104      */

105     public void setUserName(String JavaDoc userName) {
106         if (userName != null && userName.length() > 0)
107             publicParameters.put (Context.SECURITY_PRINCIPAL, userName);
108     }
109     
110     /**
111      * Set this server authentication mode.
112      * @param authenticationMode String, get from xml configuration file.
113      */

114     public void setAuthenticationMode(String JavaDoc authenticationMode) {
115         if (authenticationMode != null && authenticationMode.length() > 0) {
116             publicParameters.put (Context.SECURITY_AUTHENTICATION, authenticationMode);
117             privateParameters.put (Context.SECURITY_AUTHENTICATION, authenticationMode);
118         }
119     }
120     
121     /**
122      * Set this server password.
123      * @param password String, get from xml configuration file.
124      */

125     public void setUserPassword(String JavaDoc password) {
126         if (password != null && password.length() > 0)
127             publicParameters.put (Context.SECURITY_CREDENTIALS, password);
128     }
129     
130     /**
131      * Set this server behavior.
132      * @param behavior String, get from xml configuration file.
133      */

134     public void setReferralBehavior (String JavaDoc behavior) {
135         if (behavior != null && behavior.length() > 0) {
136             publicParameters.put (Context.REFERRAL, behavior);
137             privateParameters.put (Context.REFERRAL, behavior);
138         }
139     }
140     
141     /**
142      * Return the parameters for public connection.
143      * @return Hashtable.
144      */

145     public Hashtable JavaDoc getPublicConnectionParameters() {
146         return publicParameters;
147     }
148
149     /**
150      * Return the parameters for public connection.
151      * @param userName String, the userName for a private connection.
152      * @param password String, the password for a private connection.
153      * @return Hashtable.
154      */

155     public Hashtable JavaDoc getPrivateConnectionParameters(String JavaDoc userName, String JavaDoc password) {
156         privateParameters.put (Context.SECURITY_CREDENTIALS, password);
157         privateParameters.put (Context.SECURITY_PRINCIPAL, userName);
158         
159         return privateParameters;
160     }
161         
162     /**
163      * Return the frinedly description of this object.
164      * @return String.
165      */

166     public String JavaDoc toString() {
167         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("ServerBean[");
168         sb.append(maxReconn);
169         sb.append("::");
170         sb.append(provider);
171         sb.append("::");
172         sb.append(priority);
173         sb.append("::");
174         sb.append(publicParameters);
175         sb.append("]");
176         
177         return sb.toString();
178     }
179 }
Popular Tags