KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > admin > AbstractConnectionFactory


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2007 ScalAgent Distributed Technologies
4  * Copyright (C) 2007 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): ScalAgent Distributed Technologies
22  * Contributor(s):
23  */

24 package org.objectweb.joram.client.jms.admin;
25
26 import javax.naming.*;
27 import javax.jms.JMSException JavaDoc;
28
29 import org.objectweb.joram.client.jms.FactoryParameters;
30
31 import org.objectweb.util.monolog.api.BasicLevel;
32 import org.objectweb.joram.shared.JoramTracing;
33
34 /**
35  * Implements the <code>javax.jms.ConnectionFactory</code> interface.
36  */

37 public abstract class AbstractConnectionFactory extends AdministeredObject {
38   /** Object containing the factory's parameters. */
39   protected FactoryParameters params;
40
41   /** Reliable class name, for exemple use by ssl. */
42   protected String JavaDoc reliableClass = null;
43
44   /**
45    * Constructs a <code>ConnectionFactory</code> dedicated to a given server.
46    *
47    * @param host Name or IP address of the server's host.
48    * @param port Server's listening port.
49    */

50   public AbstractConnectionFactory(String JavaDoc host, int port) {
51     params = new FactoryParameters(host, port);
52
53     if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
54       JoramTracing.dbgClient.log(BasicLevel.DEBUG, this + ": created.");
55   }
56
57   /**
58    * Constructs a <code>ConnectionFactory</code> dedicated to a given server.
59    *
60    * @param url joram ha url.
61    */

62   public AbstractConnectionFactory(String JavaDoc url) {
63     params = new FactoryParameters(url);
64
65     if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
66       JoramTracing.dbgClient.log(BasicLevel.DEBUG, this + ": created.");
67   }
68
69   /**
70    * Constructs an empty <code>ConnectionFactory</code>.
71    */

72   public AbstractConnectionFactory() {
73     params = new FactoryParameters();
74   }
75
76   public void setReliableClass(String JavaDoc reliableClass) {
77     this.reliableClass = reliableClass;
78   }
79
80   /**
81    * Default administrator login name for connection, default value is
82    * "root".
83    * This value can be adjusted through the <tt>JoramDfltRootLogin</tt>
84    * property.
85    */

86   final static String JavaDoc dfltRootLogin = "root";
87   /**
88    * Default administrator login password for connection, default value is
89    * "root".
90    * This value can be adjusted through the <tt>JoramDfltRootPassword</tt>
91    * property.
92    */

93   final static String JavaDoc dfltRootPassword = "root";
94   /**
95    * Default login name for connection, default value is "anonymous".
96    * This value can be adjusted through the <tt>JoramDfltLogin</tt> property.
97    */

98   final static String JavaDoc dfltLogin = "anonymous";
99   /**
100    * Default login password for connection, default value is "anonymous".
101    * This value can be adjusted through the <tt>JoramDfltPassword</tt>
102    * property.
103    */

104   final static String JavaDoc dfltPassword = "anonymous";
105
106   /**
107    * Returns default administrator login name for connection.
108    * Default value "root" can be adjusted by setting the
109    * <tt>JoramDfltRootLogin</tt> property.
110    */

111   public static String JavaDoc getDefaultRootLogin() {
112     return System.getProperty("JoramDfltRootLogin", dfltRootLogin);
113   }
114
115   /**
116    * Returns the default administrator login password for connection.
117    * Default value "root" can be adjusted by setting the
118    * <tt>JoramDfltRootPassword</tt> property.
119    */

120   public static String JavaDoc getDefaultRootPassword() {
121     return System.getProperty("JoramDfltRootPassword", dfltRootPassword);
122   }
123
124   /**
125    * Returns default login name for connection.
126    * Default value "anonymous" can be adjusted by setting the
127    * <tt>JoramDfltLogin</tt> property.
128    */

129   public static String JavaDoc getDefaultLogin() {
130     return System.getProperty("JoramDfltLogin", dfltLogin);
131   }
132
133   /**
134    * Returns the default login password for connection.
135    * Default value "anonymous" can be adjusted by setting the
136    * <tt>JoramDfltPassword</tt> property.
137    */

138   public static String JavaDoc getDefaultPassword() {
139     return System.getProperty("JoramDfltPassword", dfltPassword);
140   }
141
142   /** Returns the factory's configuration parameters. */
143   public FactoryParameters getParameters() {
144     return params;
145   }
146
147   /** Sets the naming reference of an administered object. */
148   public final void toReference(Reference ref) throws NamingException {
149     toReference(ref, "cf");
150   }
151
152   /** Sets the clustered naming reference of a connection factory. */
153   public void toReference(Reference ref, String JavaDoc prefix) {
154     if (prefix == null) prefix = "cf";
155
156     params.toReference(ref, prefix);
157     ref.add(new StringRefAddr(prefix + ".reliableClass", reliableClass));
158   }
159
160   /** Restores the administered object from a naming reference. */
161   public final void fromReference(Reference ref) throws NamingException {
162     fromReference(ref, "cf");
163   }
164
165   /** Restores the administered object from a clustered naming reference. */
166   public void fromReference(Reference ref, String JavaDoc prefix) {
167     if (prefix == null) prefix = "cf";
168
169     reliableClass = (String JavaDoc) ref.get(prefix + ".reliableClass").getContent();
170     params.fromReference(ref, prefix);
171   }
172 }
173
Popular Tags