KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > client > standard > StandardImplementationFactory


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.client.standard;
8
9 import java.util.Hashtable JavaDoc;
10
11 import javax.naming.Context JavaDoc;
12 import javax.naming.Name JavaDoc;
13 import javax.naming.Reference JavaDoc;
14 import javax.naming.spi.ObjectFactory JavaDoc;
15
16 import org.jboss.jms.client.JBossConnectionFactory;
17 import org.jboss.remoting.Client;
18 import org.jboss.remoting.InvokerLocator;
19
20 /**
21  * A factory for standard implementations
22  *
23  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
24  * @version $Revision: 1.1 $
25  */

26 public class StandardImplementationFactory
27    implements ObjectFactory JavaDoc
28 {
29    // Constants -----------------------------------------------------
30

31    // Attributes ----------------------------------------------------
32

33    // Static --------------------------------------------------------
34

35    // Constructors --------------------------------------------------
36

37    // Public --------------------------------------------------------
38

39    // ObjectFactory implementation ----------------------------------
40

41    public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc environment) throws Exception JavaDoc
42    {
43       try
44       {
45          Reference JavaDoc reference = (Reference JavaDoc) obj;
46          String JavaDoc className = reference.getClassName();
47          if (className.equals(JBossConnectionFactory.class.getName()))
48             return new JBossConnectionFactory(getImplementation(reference));
49       }
50       catch (Exception JavaDoc ignored)
51       {
52       }
53       return null;
54    }
55
56    // Protected ------------------------------------------------------
57

58    /**
59     * Get the implementation from the reference
60     *
61     * @param reference the reference
62     * @return the implementation
63     */

64    protected StandardImplementation getImplementation(Reference JavaDoc reference)
65       throws Exception JavaDoc
66    {
67       String JavaDoc locatorURI = (String JavaDoc) reference.get("locatorURI").getContent();
68       InvokerLocator locator = new InvokerLocator(locatorURI);
69       Client client = new Client(locator, "JMS");
70       return new StandardImplementation(client);
71    }
72    
73    // Package Private ------------------------------------------------
74

75    // Private --------------------------------------------------------
76

77    // Inner Classes --------------------------------------------------
78

79 }
80
Popular Tags