KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > jtests > conform > basic > server > BasicObjectRefFactory


1 /**
2  * Copyright (C) 2002,2005 - INRIA (www.inria.fr)
3  *
4  * CAROL: Common Architecture for RMI ObjectWeb Layer
5  *
6  * This library is developed inside the ObjectWeb Consortium,
7  * http://www.objectweb.org
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22  * USA
23  *
24  * --------------------------------------------------------------------------
25  * $Id: BasicObjectRefFactory.java,v 1.4 2005/02/11 11:02:51 benoitf Exp $
26  * --------------------------------------------------------------------------
27  */

28 package org.objectweb.carol.jtests.conform.basic.server;
29
30 import java.util.Hashtable JavaDoc;
31
32 import javax.naming.Context JavaDoc;
33 import javax.naming.Name JavaDoc;
34 import javax.naming.RefAddr JavaDoc;
35 import javax.naming.Reference JavaDoc;
36 import javax.naming.spi.ObjectFactory JavaDoc;
37
38 /**
39  * Class <code>BasicObjectRefFactory</code> is a Basic referenceable factory
40  * (and serializable) class for testing
41  * @author Guillaume Riviere (Guillaume.Riviere@inrialpes.fr)
42  */

43 public class BasicObjectRefFactory implements ObjectFactory JavaDoc {
44
45     /**
46      * Default constructor
47      */

48     public BasicObjectRefFactory() {
49     }
50
51     /**
52      * Creates an object using the location or reference information specified.
53      * @param obj The possibly null object containing location or reference
54      * information that can be used in creating an object.
55      * @param name The name of this object relative to <code>nameCtx</code>,
56      * or null if no name is specified.
57      * @param nameCtx The context relative to which the <code>name</code>
58      * parameter is specified, or null if <code>name</code> is relative
59      * to the default initial context.
60      * @param environment The possibly null environment that is used in creating
61      * the object.
62      * @return The object created; null if an object cannot be created.
63      * @exception Exception if this object factory encountered an exception
64      * while attempting to create an object, and no other object
65      * factories are to be tried.
66      */

67     public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc environment) throws Exception JavaDoc {
68         if (obj instanceof Reference JavaDoc) {
69             Reference JavaDoc ref = (Reference JavaDoc) obj;
70             if (ref.getClassName().equals(BasicObjectRef.class.getName())) {
71                 RefAddr JavaDoc addr = ref.get("content");
72                 if (addr != null) {
73                     return new BasicObjectRef((String JavaDoc) addr.getContent());
74                 }
75             }
76         }
77         return null;
78     }
79
80 }
Popular Tags