KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > ksoap > ClassMap


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  * The present code contributor is ScalAgent Distributed Technologies.
21  *
22  * Initial developer(s): Nicolas Tachker (ScalAgent)
23  * Contributor(s):
24  */

25 package com.scalagent.ksoap;
26
27 import java.io.*;
28 import java.util.Vector JavaDoc;
29 import java.util.Hashtable JavaDoc;
30 import org.kxml.*;
31 import com.scalagent.ksoap.marshal.*;
32
33
34 public class ClassMap {
35   public static final Class JavaDoc OBJECT_CLASS = new Object JavaDoc().getClass();
36   public static final Class JavaDoc STRING_CLASS = "".getClass();
37   public static final Class JavaDoc INTEGER_CLASS = new Integer JavaDoc(0).getClass();
38   public static final Class JavaDoc LONG_CLASS = new Long JavaDoc(0).getClass();
39   public static final Class JavaDoc BOOLEAN_CLASS = new Boolean JavaDoc(true).getClass();
40   public static final Class JavaDoc VECTOR_CLASS = new java.util.Vector JavaDoc().getClass();
41   
42   public static final String JavaDoc xsi = "http://www.w3.org/2001/XMLSchema-instance";
43   public static final String JavaDoc xsd = "http://www.w3.org/2001/XMLSchema";
44   public static final String JavaDoc env = "http://schemas.xmlsoap.org/soap/envelope/";
45   public static final String JavaDoc enc = "http://schemas.xmlsoap.org/soap/encoding/";
46   
47   protected int cnt;
48   public PrefixMap prefixMap;
49   
50   static final MarshalDefault DEFAULT_MARSHAL = new MarshalDefault();
51   protected static Hashtable JavaDoc nameToClass = new Hashtable JavaDoc();
52   protected static Hashtable JavaDoc classToName = new Hashtable JavaDoc();
53   
54   
55   public ClassMap() {
56     PrefixMap basePrefixMap = new PrefixMap(
57       new PrefixMap(PrefixMap.DEFAULT,"SOAP-ENV",env),
58       "SOAP-ENC",enc);
59     prefixMap = new PrefixMap(
60       new PrefixMap(basePrefixMap,"xsd", xsd),
61       "xsi",xsi);
62     
63     DEFAULT_MARSHAL.register(this);
64   }
65   
66   public void addMapping(String JavaDoc namespace, String JavaDoc name,
67                          Class JavaDoc clazz, Marshal marshal) {
68     SoapPrimitive sp = new SoapPrimitive(namespace,name,clazz,marshal);
69     nameToClass.put(sp,sp.getMarshal());
70     classToName.put(clazz.getName(),sp);
71     if (prefixMap.getPrefix(namespace) == null)
72       prefixMap = new PrefixMap(prefixMap, "n"+(cnt++),namespace);
73   }
74
75   public static SoapPrimitive getSoapPrimitive(String JavaDoc className) {
76     if (KSoapTracing.dbg)
77       KSoapTracing.log(KSoapTracing.DEBUG,
78                        "ClassMap.getSoapPrimitive(" + className + ")");
79     return (SoapPrimitive) classToName.get(className);
80   }
81
82   public static Marshal getSoapMarshal(SoapPrimitive sp) {
83     if (KSoapTracing.dbg)
84       KSoapTracing.log(KSoapTracing.DEBUG,
85                        "ClassMap.getSoapPrimitive(" + sp + ")");
86     return (Marshal) nameToClass.get(sp);
87   }
88 }
89
Popular Tags