KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > marshal > MarshallerLoaderClient


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.remoting.marshal;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11 import org.jboss.logging.Logger;
12 import org.jboss.remoting.Client;
13 import org.jboss.remoting.InvokerLocator;
14 import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
15 import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
16
17 /**
18  * This class is used to load marshaller and unmarshallers from remote server.
19  *
20  * @author <a HREF="mailto:tom@jboss.org">Tom Elrod</a>
21  */

22 public class MarshallerLoaderClient implements MarshallerLoaderConstants
23 {
24    protected final static Logger log = Logger.getLogger(MarshallerLoaderClient.class);
25
26    /**
27     * Will call on marshall loader server to load marshaller for given data type.
28     *
29     * @param loaderLocator converted locator indicating which marhaller loader to call upon.
30     * @param dataType indicates which marshaller to get.
31     * @param classByteLoader is the class loader that the new marshaller and related classes get loaed into.
32     * @return
33     */

34    public static Marshaller getMarshaller(InvokerLocator loaderLocator, String JavaDoc dataType, ClassLoader JavaDoc classByteLoader)
35    {
36
37       Marshaller marshaller = null;
38       try
39       {
40          Marshaller loaderMarshaller = new SerializableMarshaller();
41          UnMarshaller loaderUnMarshaller = new SerializableUnMarshaller();
42          loaderUnMarshaller.setClassLoader(classByteLoader);
43
44          String JavaDoc marshallerMethodName = GET_MARSHALLER_METHOD;
45          Map JavaDoc metadata = new HashMap JavaDoc();
46          metadata.put(InvokerLocator.DATATYPE, dataType);
47          Client loaderClient = new Client(loaderLocator);
48          loaderClient.setMarshaller(loaderMarshaller);
49          loaderClient.setUnMarshaller(loaderUnMarshaller);
50
51          Object JavaDoc obj = null;
52          obj = loaderClient.invoke(marshallerMethodName, metadata);
53          if(obj != null)
54          {
55             marshaller = (Marshaller) obj;
56          }
57
58       }
59       catch(Throwable JavaDoc e)
60       {
61          log.error("Error creating remoting client to connect to marhsaller loader.", e);
62       }
63       if(marshaller == null)
64       {
65          log.error("Can not load marshall for loader locator " + loaderLocator + ".");
66       }
67
68       return marshaller;
69    }
70
71    /**
72     * Will call on marshall loader server to load unmarshaller for given data type.
73     *
74     * @param loaderLocator converted locator indicating which marhaller loader to call upon.
75     * @param dataType indicates which unmarshaller to get.
76     * @param classByteLoader is the class loader that the new unmarshaller and related classes get loaed into.
77     * @return
78     */

79    public static UnMarshaller getUnMarshaller(InvokerLocator loaderLocator, String JavaDoc dataType, ClassLoader JavaDoc classByteLoader)
80    {
81
82       UnMarshaller unmarshaller = null;
83
84       try
85       {
86          SerializableMarshaller loaderMarshaller = new SerializableMarshaller();
87          SerializableUnMarshaller loaderUnMarshaller = new SerializableUnMarshaller();
88          loaderUnMarshaller.setClassLoader(classByteLoader);
89
90          String JavaDoc marshallerMethodName = GET_UNMARSHALLER_METHOD;
91          Map JavaDoc metadata = new HashMap JavaDoc();
92          metadata.put(InvokerLocator.DATATYPE, dataType);
93          Client loaderClient = new Client(loaderLocator);
94          loaderClient.setMarshaller(loaderMarshaller);
95          loaderClient.setUnMarshaller(loaderUnMarshaller);
96
97          Object JavaDoc obj = null;
98
99          obj = loaderClient.invoke(marshallerMethodName, metadata);
100          if(obj != null)
101          {
102             unmarshaller = (UnMarshaller) obj;
103          }
104       }
105       catch(Throwable JavaDoc e)
106       {
107          log.error("Error creating remoting client to connecto to marhsaller loader.", e);
108       }
109       if(unmarshaller == null)
110       {
111          log.error("Can not load unmarshaller for loader locator " + loaderLocator + ".");
112       }
113       return unmarshaller;
114    }
115 }
116
Popular Tags