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.
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.
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.
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.
23
package org.jboss.remoting.marshal;
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;
31
import java.util.HashMap;
35
* This class is used to load marshaller and unmarshallers from remote server.
37
* @author <a href="mailto:tom@jboss.org">Tom Elrod</a>
39
public class MarshallerLoaderClient implements MarshallerLoaderConstants
41
protected final static Logger log = Logger.getLogger(MarshallerLoaderClient.class);
44
* Will call on marshall loader server to load marshaller for given data type.
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.
51
public static Marshaller getMarshaller(InvokerLocator loaderLocator, String dataType, ClassLoader classByteLoader)
54
Marshaller marshaller = null;
57
SerializableMarshaller loaderMarshaller = new SerializableMarshaller();
58
SerializableUnMarshaller loaderUnMarshaller = new SerializableUnMarshaller();
59
loaderUnMarshaller.setClassLoader(classByteLoader);
61
String serializationType = "java";
62
Map parameters = loaderLocator.getParameters();
63
if (parameters != null)
65
Object o = parameters.get(InvokerLocator.SERIALIZATIONTYPE);
68
o = parameters.get(InvokerLocator.SERIALIZATIONTYPE_CASED);;
72
serializationType = (String) o;
75
loaderMarshaller.setSerializationType(serializationType);
76
loaderUnMarshaller.setSerializationType(serializationType);
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);
87
obj = loaderClient.invoke(marshallerMethodName, metadata);
90
marshaller = (Marshaller) obj;
96
log.error("Error creating remoting client to connect to marhsaller loader.", e);
98
if(marshaller == null)
100
log.error("Can not load marshall for loader locator " + loaderLocator + ".");
107
* Will call on marshall loader server to load unmarshaller for given data type.
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.
114
public static UnMarshaller getUnMarshaller(InvokerLocator loaderLocator, String dataType, ClassLoader classByteLoader)
117
UnMarshaller unmarshaller = null;
121
SerializableMarshaller loaderMarshaller = new SerializableMarshaller();
122
SerializableUnMarshaller loaderUnMarshaller = new SerializableUnMarshaller();
123
loaderUnMarshaller.setClassLoader(classByteLoader);
125
String serializationType = "java";
126
Map parameters = loaderLocator.getParameters();
127
if (parameters != null)
129
Object o = parameters.get(InvokerLocator.SERIALIZATIONTYPE);
132
o = parameters.get(InvokerLocator.SERIALIZATIONTYPE_CASED);;
136
serializationType = (String) o;
139
loaderMarshaller.setSerializationType(serializationType);
140
loaderUnMarshaller.setSerializationType(serializationType);
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);
152
obj = loaderClient.invoke(marshallerMethodName, metadata);
155
unmarshaller = (UnMarshaller) obj;
160
log.error("Error creating remoting client to connecto to marhsaller loader.", e);
162
if(unmarshaller == null)
164
log.error("Can not load unmarshaller for loader locator " + loaderLocator + ".");