01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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: package org.jboss.invocation.iiop;
23:
24: import java.io.IOException;
25: import java.io.Serializable;
26: import org.jboss.util.Conversion;
27:
28: /**
29: * Helper class used to create a byte array ("reference data") to be embedded
30: * into a CORBA reference and to extract object/servant identification info
31: * from this byte array. If this info consists simply of an
32: * <code>objectId</code>, this id is serialized into the byte array. If this
33: * info consists of a pair (servantId, objectId), a <code>ReferenceData</code>
34: * instance containing the pair is is serialized into the byte array.
35: *
36: * @author <a href="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
37: * @version $Revision: 57194 $
38: */
39: public class ReferenceData implements Serializable {
40: static final long serialVersionUID = 2024043833676010079L;
41:
42: private Object servantId;
43: private Object objectId;
44:
45: public static byte[] create(Object servantId, Object objectId) {
46: return Conversion.toByteArray(new ReferenceData(servantId,
47: objectId));
48: }
49:
50: public static byte[] create(Object id) {
51: return Conversion.toByteArray(id);
52: }
53:
54: public static Object extractServantId(byte[] refData, ClassLoader cl)
55: throws IOException, ClassNotFoundException {
56: Object obj = Conversion.toObject(refData, cl);
57: if (obj != null && obj instanceof ReferenceData)
58: return ((ReferenceData) obj).servantId;
59: else
60: return obj;
61: }
62:
63: public static Object extractServantId(byte[] refData)
64: throws IOException, ClassNotFoundException {
65: return extractServantId(refData, Thread.currentThread()
66: .getContextClassLoader());
67: }
68:
69: public static Object extractObjectId(byte[] refData, ClassLoader cl)
70: throws IOException, ClassNotFoundException {
71: Object obj = Conversion.toObject(refData, cl);
72: if (obj != null && obj instanceof ReferenceData)
73: return ((ReferenceData) obj).objectId;
74: else
75: return obj;
76: }
77:
78: public static Object extractObjectId(byte[] refData)
79: throws IOException, ClassNotFoundException {
80: return extractObjectId(refData, Thread.currentThread()
81: .getContextClassLoader());
82: }
83:
84: private ReferenceData(Object servantId, Object objectId) {
85: this.servantId = servantId;
86: this.objectId = objectId;
87: }
88:
89: }
|