01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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.mq.referenceable;
23:
24: import org.jboss.logging.Logger;
25: import org.jboss.mq.GenericConnectionFactory;
26:
27: /**
28: * This class is used to create instances of of: SpyTopicConnectionFactory
29: * SpyQueueConnectionFactory SpyXATopicConnectionFactory SpyXAQueueConnectionFactory
30: * classes from a javax.naming.Reference instance.
31: *
32: * @author Hiram Chirino (Cojonudo14@hotmail.com)
33: * @created August 16, 2001
34: * @version $Revision: 57198 $
35: */
36: public class SpyConnectionFactoryObjectFactory implements
37: javax.naming.spi.ObjectFactory {
38:
39: static Logger cat = Logger
40: .getLogger(SpyConnectionFactoryObjectFactory.class);
41:
42: /**
43: * getObjectInstance method.
44: *
45: * @param reference Description of Parameter
46: * @param name Description of Parameter
47: * @param contex Description of Parameter
48: * @param properties Description of Parameter
49: * @return The ObjectInstance value
50: * @exception java.lang.Exception Description of Exception
51: */
52: public java.lang.Object getObjectInstance(
53: java.lang.Object reference, javax.naming.Name name,
54: javax.naming.Context contex, java.util.Hashtable properties)
55: throws java.lang.Exception {
56:
57: boolean debug = cat.isDebugEnabled();
58: if (debug)
59: cat.debug("Extracting SpyConnectionFactory from reference");
60: try {
61:
62: javax.naming.Reference ref = (javax.naming.Reference) reference;
63: GenericConnectionFactory dcf = (GenericConnectionFactory) ObjectRefAddr
64: .extractObjectRefFrom(ref, "DCF");
65:
66: if (debug)
67: cat.debug("The GenericConnectionFactory is: " + dcf);
68:
69: if (ref.getClassName().equals(
70: "org.jboss.mq.SpyConnectionFactory")) {
71: return new org.jboss.mq.SpyConnectionFactory(dcf);
72: } else if (ref.getClassName().equals(
73: "org.jboss.mq.SpyXAConnectionFactory")) {
74: return new org.jboss.mq.SpyXAConnectionFactory(dcf);
75: }
76: } catch (Throwable ignore) {
77: ignore.printStackTrace();
78: // This method should not throw an exception since
79: // It would prevent another ObjectFactory from attempting
80: // to create an instance of the object.
81: }
82: return null;
83: }
84: }
|