KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > jndi2 > soap > JndiSoapService


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2003 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
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): Frederic Maistre (INRIA)
22  * Contributor(s): Nicolas Tachker (ScalAgent DT)
23  */

24 package fr.dyade.aaa.jndi2.soap;
25
26 import org.objectweb.util.monolog.api.BasicLevel;
27 import org.objectweb.util.monolog.api.Logger;
28
29 import java.util.Hashtable JavaDoc;
30
31 import javax.naming.Context JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34
35
36 /**
37  * The <code>JndiSoapService</code> class implements a JNDI access through a
38  * SOAP service.
39  * <p>
40  * Actually, this service is a "classical" JNDI client accessing the JNDI
41  * server.
42  */

43 public class JndiSoapService
44 {
45   
46   public static final Logger logger = fr.dyade.aaa.util.Debug.getLogger(
47       JndiSoapService.class.getName());
48   
49   /** The service's <code>Context</code>. */
50   private Context JavaDoc ctx;
51
52   /**
53    * Initializes the <code>JndiSoapService</code>.
54    *
55    * @param jndiHost Host hosting the JNDI server.
56    * @param jndiPort JNDI server's port.
57    *
58    * @exception NamingException If the JNDI server is not reachable or if
59    * the parameters are invalid.
60    */

61   public void init(String JavaDoc jndiHost, int jndiPort) throws NamingException JavaDoc
62   {
63     java.util.Hashtable JavaDoc env = new java.util.Hashtable JavaDoc();
64     env.put("java.naming.factory.initial",
65             "fr.dyade.aaa.jndi2.client.NamingContextFactory");
66     env.put("java.naming.factory.host", jndiHost);
67     env.put("java.naming.factory.port", "" + jndiPort);
68     ctx = new InitialContext JavaDoc(env);
69   }
70
71   /**
72    * Service method: decodes and binds an object.
73    *
74    * @param name Name to use for binding the object.
75    * @param map Coded object.
76    *
77    * @exception NamingException If the binding fails, or if the object could
78    * not be decoded.
79    */

80   public void bind(String JavaDoc name, Hashtable JavaDoc map) throws NamingException JavaDoc
81   {
82     ctx.bind(name, SoapObjectHelper.soapDecode(map));
83   }
84
85   /**
86    * Service method: decodes and rebinds an object.
87    *
88    * @param name Name to use for rebinding the object.
89    * @param map Coded object.
90    *
91    * @exception NamingException If the rebinding fails, or if the object could
92    * not be decoded.
93    */

94   public void rebind(String JavaDoc name, Hashtable JavaDoc map) throws NamingException JavaDoc
95   {
96     ctx.rebind(name, SoapObjectHelper.soapDecode(map));
97   }
98
99   /**
100    * Service method: retrieves an object and returns it coded.
101    *
102    * @exception NamingException If the lookup fails or if the object is not
103    * codable.
104    */

105   public Hashtable JavaDoc lookup(String JavaDoc name) throws NamingException JavaDoc
106   {
107     try {
108     return SoapObjectHelper.soapCode(ctx.lookup(name));
109     } catch (Throwable JavaDoc exc) {
110       if (logger.isLoggable(BasicLevel.DEBUG))
111         logger.log(BasicLevel.DEBUG, "", exc);
112       throw new NamingException JavaDoc(exc.toString());
113     }
114   }
115
116   /**
117    * Service method: unbinds an object.
118    *
119    * @exception NamingException If the unbinding fails.
120    */

121   public void unbind(String JavaDoc name) throws NamingException JavaDoc
122   {
123     ctx.unbind(name);
124   }
125 }
126
Popular Tags