KickJava   Java API By Example, From Geeks To Geeks.

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


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 fr.dyade.aaa.jndi2.client.NamingContextFactory;
27
28 import javax.naming.CompositeName JavaDoc;
29 import javax.naming.Context JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31
32 import java.util.Hashtable JavaDoc;
33
34 /**
35  * Extends the <code>NamingContextFactory</code> for allowing clients to
36  * access JNDI through a SOAP service.
37  */

38 public class SoapExt_NamingContextFactory extends NamingContextFactory
39 {
40   /**
41    * Extended method returning when requested a JNDI initial context for
42    * accessing a SOAP service.
43    *
44    * @param env Contains the configuration parameters.
45    *
46    * @exception NamingException Thrown if the parameters are invalid.
47    */

48   public Context JavaDoc getInitialContext(Hashtable JavaDoc env) throws NamingException JavaDoc
49   {
50     String JavaDoc soapHost = (String JavaDoc) env.get("java.naming.factory.soapservice.host");
51
52     // No SOAP service described in the configuration, building a "classical"
53
// tcp context:
54
if (soapHost == null)
55       return super.getInitialContext(env);
56
57     int soapPort;
58     String JavaDoc jndiHost;
59     int jndiPort;
60
61     try {
62       Object JavaDoc soapPortObj = env.get("java.naming.factory.soapservice.port");
63       soapPort = Integer.parseInt((String JavaDoc) soapPortObj);
64     }
65     catch (Exception JavaDoc exc) {
66       NamingException JavaDoc nEx =
67         new NamingException JavaDoc("Invalid java.naming.factory.soapservice.port"
68                             + " parameter.");
69       nEx.setRootCause(exc);
70       throw nEx;
71     }
72
73     jndiHost = (String JavaDoc) env.get("java.naming.factory.host");
74     if (jndiHost == null)
75       throw new NamingException JavaDoc("Missing java.naming.factory.host parameter.");
76
77     try {
78       Object JavaDoc jndiPortObj = env.get("java.naming.factory.port");
79       jndiPort = Integer.parseInt((String JavaDoc) jndiPortObj);
80     }
81     catch (Exception JavaDoc exc) {
82       NamingException JavaDoc nEx =
83         new NamingException JavaDoc("Invalid java.naming.factory.port parameter.");
84       nEx.setRootCause(exc);
85       throw nEx;
86     }
87
88     return new SoapExt_NamingContextImpl(soapHost, soapPort,
89                                          jndiHost, jndiPort);
90   }
91 }
92
Popular Tags