KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > kjndi > ksoap > ConversionSoapHelper


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

23 package com.scalagent.kjndi.ksoap;
24
25 import java.lang.*;
26 import java.util.Vector JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import com.scalagent.ksoap.SoapObject;
30
31 public class ConversionSoapHelper {
32   
33   public static final String JavaDoc NAMESPACE = "urn:JndiService";
34
35   public static SoapObject getSoapObject(String JavaDoc action, String JavaDoc name, Object JavaDoc object) {
36
37     SoapObject sO = null;
38
39     if (action.equals("bind")) {
40       sO = getSoapBind(action,name,object);
41     } else if (action.equals("lookup")) {
42       sO = getSoapLookup(action,name,object);
43     } else if (action.equals("rebind")) {
44       sO = getSoapRebind(action,name,object);
45     } else if (action.equals("unbind")) {
46       sO = getSoapUnbind(action,name,object);
47     }
48     return sO;
49   }
50
51   private static SoapObject getSoapBind(String JavaDoc action, String JavaDoc name, Object JavaDoc obj) {
52     SoapObject sO = new SoapObject(NAMESPACE, action);
53 // sO.addProperty("xxx",xxx);
54
// System.out.println("JNDI bind : xxx = "+ xxx);//NTA tmp
55
return sO;
56   }
57
58   private static SoapObject getSoapLookup(String JavaDoc action, String JavaDoc name, Object JavaDoc obj) {
59     SoapObject sO = new SoapObject(NAMESPACE, action);
60     sO.addProperty("name",name);
61     return sO;
62   }
63
64   private static SoapObject getSoapRebind(String JavaDoc action, String JavaDoc name, Object JavaDoc obj) {
65     SoapObject sO = new SoapObject(NAMESPACE, action);
66 // sO.addProperty("xxx",xxx);
67
// System.out.println("JNDI bind : xxx = "+ xxx);//NTA tmp
68
return sO;
69   }
70
71   private static SoapObject getSoapUnbind(String JavaDoc action, String JavaDoc name, Object JavaDoc obj) {
72     SoapObject sO = new SoapObject(NAMESPACE, action);
73     sO.addProperty("name",name);
74     return sO;
75   }
76
77
78   /**
79    * convert a SoapObject to Object
80    */

81   public static Object JavaDoc getObject(SoapObject sO)
82     throws Exception JavaDoc {
83
84     Hashtable JavaDoc h = null;
85     String JavaDoc nameSpace = sO.getNamespace();
86     String JavaDoc name = sO.getName();
87
88     if (nameSpace.equals(NAMESPACE)) {
89       if (name.equals("lookupResponse") ||
90           name.equals("bindResponse") ||
91           name.equals("unbindResponse") ||
92           name.equals("rebindResponse")) {
93         Object JavaDoc o = sO.getProperty("return");
94         h = (Hashtable JavaDoc) sO.getProperty("return");
95       } else if (name.equals("sendResponse")) {
96         return null;
97       } else {
98         throw new Exception JavaDoc("SoapObject " + name
99                             + " can't be converted to a Hashtable.");
100       }
101     } else {
102       throw new Exception JavaDoc("SoapObject " + nameSpace
103                           + " != urn:JndiService.");
104     }
105     
106     String JavaDoc className = (String JavaDoc) h.get("className");
107     if (className == null)
108       throw new Exception JavaDoc("SoapObject " + name
109                           + " no className found.");
110     
111       if (className.equals("org.objectweb.joram.client.jms.soap.SoapConnectionFactory")) {
112       return com.scalagent.kjoram.ksoap.SoapConnectionFactory.decode(h);
113     } else if (className.equals("org.objectweb.joram.client.jms.Queue")){
114       return com.scalagent.kjoram.Queue.decode(h);
115     } else if (className.equals("org.objectweb.joram.client.jms.Topic")){
116       return com.scalagent.kjoram.Topic.decode(h);
117     } else if (className.equals("org.objectweb.joram.client.jms.TemporaryQueue")){
118       return com.scalagent.kjoram.TemporaryQueue.decode(h);
119     } else if (className.equals("org.objectweb.joram.client.jms.TemporaryTopic")){
120       return com.scalagent.kjoram.TemporaryTopic.decode(h);
121     }
122       throw new Exception JavaDoc("SoapObject " + className
123                           + " can't be converted to an Object.");
124   }
125 }
126
Popular Tags