KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > jndi2 > msg > ObjectFactory


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Sofiane Chibani
22  * Contributor(s): David Feliot, Nicolas Tachker
23  */

24 package fr.dyade.aaa.jndi2.msg;
25
26 import javax.naming.*;
27 import java.io.*;
28
29 public class ObjectFactory implements javax.naming.spi.ObjectFactory JavaDoc {
30   public final static String JavaDoc ADDRESS_TYPE = "";
31
32   public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name name, Context ctx,
33                                   java.util.Hashtable JavaDoc env) throws Exception JavaDoc {
34     if (obj instanceof Reference) {
35       Reference ref = (Reference)obj;
36       RefAddr addr = ref.get(ADDRESS_TYPE);
37       if (addr instanceof BinaryRefAddr) {
38         BinaryRefAddr binRefAddr = (BinaryRefAddr)addr;
39         byte[] bytes = (byte[])binRefAddr.getContent();
40         ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
41         ObjectInputStream ois = new ObjectInputStream(bais);
42         return ois.readObject();
43       } else {
44         throw new Exception JavaDoc("Binary address expected");
45       }
46     } else {
47       throw new Exception JavaDoc("Reference expected");
48     }
49   }
50 }
51
Popular Tags