KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > naming > LinkRefPairObjectFactory


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.naming;
23
24 import java.util.Hashtable JavaDoc;
25
26 import javax.naming.Context JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.naming.Name JavaDoc;
29 import javax.naming.spi.ObjectFactory JavaDoc;
30
31 import org.jboss.logging.Logger;
32 import org.jboss.util.id.GUID;
33
34 /**
35  * An object factory that allows different objects to be used
36  * in the local virtual machine versus remote virtual machines
37  *
38  * @author Adrian Brock (adrian@jboss.com)
39  * @version $Revision: 37459 $
40  */

41 public class LinkRefPairObjectFactory implements ObjectFactory JavaDoc
42 {
43    // Constants -----------------------------------------------------
44

45    /** The logger */
46    private static final Logger log = Logger.getLogger(LinkRefPairObjectFactory.class);
47    
48    /** Our class name */
49    static final String JavaDoc className = LinkRefPairObjectFactory.class.getName();
50    
51    /** The guid used to determine whether we in the same VM */
52    static final String JavaDoc guid = new GUID().asString();
53    
54    // Attributes ----------------------------------------------------
55

56    // Static --------------------------------------------------------
57

58    // Constructors --------------------------------------------------
59

60    // Public --------------------------------------------------------
61

62    // ObjectFactory implementation ----------------------------------
63

64    public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc environment) throws Exception JavaDoc
65    {
66       LinkRefPair pair = (LinkRefPair) obj;
67       String JavaDoc jndiName;
68       
69       // Local or remote?
70
boolean local = false;
71       if (guid.equals(pair.getGUID()))
72       {
73          jndiName = pair.getLocalLinkName();
74          local = true;
75       }
76       else
77          jndiName = pair.getRemoteLinkName();
78       
79       InitialContext JavaDoc ctx;
80       if (local || environment == null)
81          ctx = new InitialContext JavaDoc();
82       else
83          ctx = new InitialContext JavaDoc(environment);
84       
85       return ctx.lookup(jndiName);
86    }
87    
88    // Y overrides ---------------------------------------------------
89

90    // Package protected ---------------------------------------------
91

92    // Protected -----------------------------------------------------
93

94    // Private -------------------------------------------------------
95

96    // Inner classes -------------------------------------------------
97
}
98
Popular Tags