KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > destination > JBossDestinationFactory


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.destination;
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 /**
17  * A factory for destinations
18  *
19  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
20  * @version $Revision: 1.1 $
21  */

22 public class JBossDestinationFactory
23    implements ObjectFactory JavaDoc
24 {
25    // Constants -----------------------------------------------------
26

27    // Attributes ----------------------------------------------------
28

29    // Static --------------------------------------------------------
30

31    // Constructors --------------------------------------------------
32

33    // Public --------------------------------------------------------
34

35    // ObjectFactory implementation ----------------------------------
36

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

56    /**
57     * Get the name from the reference
58     *
59     * @param reference the reference
60     * @return the name
61     */

62    protected String JavaDoc getName(Reference JavaDoc reference)
63    {
64       return (String JavaDoc) reference.get("Name").getContent();
65    }
66    
67    // Package Private ------------------------------------------------
68

69    // Private --------------------------------------------------------
70

71    // Inner Classes --------------------------------------------------
72

73 }
74
Popular Tags