KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > invocation > iiop > ReferenceData


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 package org.jboss.invocation.iiop;
23
24 import java.io.IOException JavaDoc;
25 import java.io.Serializable JavaDoc;
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: 37459 $
38  */

39 public class ReferenceData
40       implements Serializable JavaDoc
41 {
42    private Object JavaDoc servantId;
43    private Object JavaDoc objectId;
44
45    public static byte[] create(Object JavaDoc servantId, Object JavaDoc objectId)
46    {
47       return Conversion.toByteArray(new ReferenceData(servantId, objectId));
48    }
49
50    public static byte[] create(Object JavaDoc id)
51    {
52       return Conversion.toByteArray(id);
53    }
54
55    public static Object JavaDoc extractServantId(byte[] refData, ClassLoader JavaDoc cl)
56          throws IOException JavaDoc, ClassNotFoundException JavaDoc
57    {
58       Object JavaDoc obj = Conversion.toObject(refData, cl);
59       if (obj != null && obj instanceof ReferenceData)
60          return ((ReferenceData)obj).servantId;
61       else
62          return obj;
63    }
64
65    public static Object JavaDoc extractServantId(byte[] refData)
66          throws IOException JavaDoc, ClassNotFoundException JavaDoc
67    {
68       return extractServantId(refData,
69                               Thread.currentThread().getContextClassLoader());
70    }
71
72    public static Object JavaDoc extractObjectId(byte[] refData, ClassLoader JavaDoc cl)
73          throws IOException JavaDoc, ClassNotFoundException JavaDoc
74    {
75       Object JavaDoc obj = Conversion.toObject(refData, cl);
76       if (obj != null && obj instanceof ReferenceData)
77          return ((ReferenceData)obj).objectId;
78       else
79          return obj;
80    }
81    
82    public static Object JavaDoc extractObjectId(byte[] refData)
83          throws IOException JavaDoc, ClassNotFoundException JavaDoc
84    {
85       return extractObjectId(refData,
86                              Thread.currentThread().getContextClassLoader());
87    }
88    
89    private ReferenceData(Object JavaDoc servantId, Object JavaDoc objectId)
90    {
91       this.servantId = servantId;
92       this.objectId = objectId;
93    }
94    
95 }
96
97
Popular Tags