~ubuntu-branches/ubuntu/oneiric/libjboss-remoting-java/oneiric

« back to all changes in this revision

Viewing changes to src/org/jboss/remoting/marshal/MarshallerLoaderClient.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
* JBoss, Home of Professional Open Source
3
 
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
 
* by the @authors tag. See the copyright.txt in the distribution for a
5
 
* full listing of individual contributors.
6
 
*
7
 
* This is free software; you can redistribute it and/or modify it
8
 
* under the terms of the GNU Lesser General Public License as
9
 
* published by the Free Software Foundation; either version 2.1 of
10
 
* the License, or (at your option) any later version.
11
 
*
12
 
* This software is distributed in the hope that it will be useful,
13
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
 
* Lesser General Public License for more details.
16
 
*
17
 
* You should have received a copy of the GNU Lesser General Public
18
 
* License along with this software; if not, write to the Free
19
 
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
 
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21
 
*/
22
 
 
23
 
package org.jboss.remoting.marshal;
24
 
 
25
 
import org.jboss.logging.Logger;
26
 
import org.jboss.remoting.Client;
27
 
import org.jboss.remoting.InvokerLocator;
28
 
import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
29
 
import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
30
 
 
31
 
import java.util.HashMap;
32
 
import java.util.Map;
33
 
 
34
 
/**
35
 
 * This class is used to load marshaller and unmarshallers from remote server.
36
 
 *
37
 
 * @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
38
 
 */
39
 
public class MarshallerLoaderClient implements MarshallerLoaderConstants
40
 
{
41
 
   protected final static Logger log = Logger.getLogger(MarshallerLoaderClient.class);
42
 
 
43
 
   /**
44
 
    * Will call on marshall loader server to load marshaller for given data type.
45
 
    *
46
 
    * @param loaderLocator   converted locator indicating which marhaller loader to call upon.
47
 
    * @param dataType        indicates which marshaller to get.
48
 
    * @param classByteLoader is the class loader that the new marshaller and related classes get loaed into.
49
 
    * @return
50
 
    */
51
 
   public static Marshaller getMarshaller(InvokerLocator loaderLocator, String dataType, ClassLoader classByteLoader)
52
 
   {
53
 
 
54
 
      Marshaller marshaller = null;
55
 
      try
56
 
      {
57
 
         SerializableMarshaller loaderMarshaller = new SerializableMarshaller();
58
 
         SerializableUnMarshaller loaderUnMarshaller = new SerializableUnMarshaller();
59
 
         loaderUnMarshaller.setClassLoader(classByteLoader);
60
 
         
61
 
         String serializationType = "java";
62
 
         Map parameters = loaderLocator.getParameters();
63
 
         if (parameters != null)
64
 
         {
65
 
            Object o = parameters.get(InvokerLocator.SERIALIZATIONTYPE);
66
 
            if (o == null)
67
 
            {
68
 
               o = parameters.get(InvokerLocator.SERIALIZATIONTYPE_CASED);;
69
 
            }
70
 
            if (o != null)
71
 
            {
72
 
               serializationType = (String) o;
73
 
            }
74
 
         }
75
 
         loaderMarshaller.setSerializationType(serializationType);
76
 
         loaderUnMarshaller.setSerializationType(serializationType);
77
 
         
78
 
         String marshallerMethodName = GET_MARSHALLER_METHOD;
79
 
         Map metadata = new HashMap();
80
 
         metadata.put(InvokerLocator.DATATYPE, dataType);
81
 
         Client loaderClient = new Client(loaderLocator);
82
 
         loaderClient.connect();
83
 
         loaderClient.setMarshaller(loaderMarshaller);
84
 
         loaderClient.setUnMarshaller(loaderUnMarshaller);
85
 
 
86
 
         Object obj = null;
87
 
         obj = loaderClient.invoke(marshallerMethodName, metadata);
88
 
         if(obj != null)
89
 
         {
90
 
            marshaller = (Marshaller) obj;
91
 
         }
92
 
 
93
 
      }
94
 
      catch(Throwable e)
95
 
      {
96
 
         log.error("Error creating remoting client to connect to marhsaller loader.", e);
97
 
      }
98
 
      if(marshaller == null)
99
 
      {
100
 
         log.error("Can not load marshall for loader locator " + loaderLocator + ".");
101
 
      }
102
 
 
103
 
      return marshaller;
104
 
   }
105
 
 
106
 
   /**
107
 
    * Will call on marshall loader server to load unmarshaller for given data type.
108
 
    *
109
 
    * @param loaderLocator   converted locator indicating which marhaller loader to call upon.
110
 
    * @param dataType        indicates which unmarshaller to get.
111
 
    * @param classByteLoader is the class loader that the new unmarshaller and related classes get loaed into.
112
 
    * @return
113
 
    */
114
 
   public static UnMarshaller getUnMarshaller(InvokerLocator loaderLocator, String dataType, ClassLoader classByteLoader)
115
 
   {
116
 
 
117
 
      UnMarshaller unmarshaller = null;
118
 
 
119
 
      try
120
 
      {
121
 
         SerializableMarshaller loaderMarshaller = new SerializableMarshaller();
122
 
         SerializableUnMarshaller loaderUnMarshaller = new SerializableUnMarshaller();
123
 
         loaderUnMarshaller.setClassLoader(classByteLoader);
124
 
         
125
 
         String serializationType = "java";
126
 
         Map parameters = loaderLocator.getParameters();
127
 
         if (parameters != null)
128
 
         {
129
 
            Object o = parameters.get(InvokerLocator.SERIALIZATIONTYPE);
130
 
            if (o == null)
131
 
            {
132
 
               o = parameters.get(InvokerLocator.SERIALIZATIONTYPE_CASED);;
133
 
            }
134
 
            if (o != null)
135
 
            {
136
 
               serializationType = (String) o;
137
 
            }
138
 
         }
139
 
         loaderMarshaller.setSerializationType(serializationType);
140
 
         loaderUnMarshaller.setSerializationType(serializationType);
141
 
 
142
 
         String marshallerMethodName = GET_UNMARSHALLER_METHOD;
143
 
         Map metadata = new HashMap();
144
 
         metadata.put(InvokerLocator.DATATYPE, dataType);
145
 
         Client loaderClient = new Client(loaderLocator);
146
 
         loaderClient.connect();
147
 
         loaderClient.setMarshaller(loaderMarshaller);
148
 
         loaderClient.setUnMarshaller(loaderUnMarshaller);
149
 
 
150
 
         Object obj = null;
151
 
 
152
 
         obj = loaderClient.invoke(marshallerMethodName, metadata);
153
 
         if(obj != null)
154
 
         {
155
 
            unmarshaller = (UnMarshaller) obj;
156
 
         }
157
 
      }
158
 
      catch(Throwable e)
159
 
      {
160
 
         log.error("Error creating remoting client to connecto to marhsaller loader.", e);
161
 
      }
162
 
      if(unmarshaller == null)
163
 
      {
164
 
         log.error("Can not load unmarshaller for loader locator " + loaderLocator + ".");
165
 
      }
166
 
      return unmarshaller;
167
 
   }
168
 
}