com/scalagent/kjndi/ksoap/ConversionSoapHelper.java

00001 /*
00002  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
00003  * Copyright (C) 2003 - ScalAgent Distributed Technologies
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or any later version.
00009  * 
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00018  * USA.
00019  *
00020  * Initial developer(s): Nicolas Tachker (ScalAgent)
00021  * Contributor(s):
00022  */
00023 package com.scalagent.kjndi.ksoap;
00024 
00025 import java.lang.*;
00026 import java.util.Vector;
00027 import java.util.Hashtable;
00028 
00029 import com.scalagent.ksoap.SoapObject;
00030 
00031 public class ConversionSoapHelper {
00032   
00033   public static final String NAMESPACE = "urn:JndiService";
00034 
00035   public static SoapObject getSoapObject(String action, String name, Object object) {
00036 
00037     SoapObject sO = null;
00038 
00039     if (action.equals("bind")) {
00040       sO = getSoapBind(action,name,object);
00041     } else if (action.equals("lookup")) {
00042       sO = getSoapLookup(action,name,object);
00043     } else if (action.equals("rebind")) {
00044       sO = getSoapRebind(action,name,object);
00045     } else if (action.equals("unbind")) {
00046       sO = getSoapUnbind(action,name,object);
00047     }
00048     return sO;
00049   }
00050 
00051   private static SoapObject getSoapBind(String action, String name, Object obj) {
00052     SoapObject sO = new SoapObject(NAMESPACE, action);
00053 //      sO.addProperty("xxx",xxx);
00054 //      System.out.println("JNDI bind :  xxx = "+ xxx);//NTA tmp
00055     return sO;
00056   }
00057 
00058   private static SoapObject getSoapLookup(String action, String name, Object obj) {
00059     SoapObject sO = new SoapObject(NAMESPACE, action);
00060     sO.addProperty("name",name);
00061     return sO;
00062   }
00063 
00064   private static SoapObject getSoapRebind(String action, String name, Object obj) {
00065     SoapObject sO = new SoapObject(NAMESPACE, action);
00066 //      sO.addProperty("xxx",xxx);
00067 //      System.out.println("JNDI bind :  xxx = "+ xxx);//NTA tmp
00068     return sO;
00069   }
00070 
00071   private static SoapObject getSoapUnbind(String action, String name, Object obj) {
00072     SoapObject sO = new SoapObject(NAMESPACE, action);
00073     sO.addProperty("name",name);
00074     return sO;
00075   }
00076 
00077 
00081   public static Object getObject(SoapObject sO) 
00082     throws Exception {
00083 
00084     Hashtable h = null;
00085     String nameSpace = sO.getNamespace();
00086     String name = sO.getName();
00087 
00088     if (nameSpace.equals(NAMESPACE)) {
00089       if (name.equals("lookupResponse") || 
00090           name.equals("bindResponse") ||
00091           name.equals("unbindResponse") ||
00092           name.equals("rebindResponse")) {
00093         Object o = sO.getProperty("return");
00094         h = (Hashtable) sO.getProperty("return");
00095       } else if (name.equals("sendResponse")) {
00096         return null;
00097       } else {
00098         throw new Exception("SoapObject " + name
00099                             + " can't be converted to a Hashtable.");
00100       }
00101     } else {
00102       throw new Exception("SoapObject " + nameSpace
00103                           + " != urn:JndiService.");
00104     }
00105     
00106     String className = (String) h.get("className");
00107     if (className == null) 
00108       throw new Exception("SoapObject " + name
00109                           + " no className found.");
00110     
00111       if (className.equals("org.objectweb.joram.client.jms.soap.SoapConnectionFactory")) {
00112       return com.scalagent.kjoram.ksoap.SoapConnectionFactory.decode(h);
00113     } else if (className.equals("org.objectweb.joram.client.jms.Queue")){
00114       return com.scalagent.kjoram.Queue.decode(h);
00115     } else if (className.equals("org.objectweb.joram.client.jms.Topic")){
00116       return com.scalagent.kjoram.Topic.decode(h);
00117     } else if (className.equals("org.objectweb.joram.client.jms.TemporaryQueue")){
00118       return com.scalagent.kjoram.TemporaryQueue.decode(h);
00119     } else if (className.equals("org.objectweb.joram.client.jms.TemporaryTopic")){
00120       return com.scalagent.kjoram.TemporaryTopic.decode(h);
00121     }
00122       throw new Exception("SoapObject " + className
00123                           + " can't be converted to an Object.");
00124   }
00125 }

Generated on Tue Sep 16 16:14:23 2008 for joram by  doxygen 1.5.0