~ubuntu-branches/ubuntu/utopic/tomcat8/utopic

« back to all changes in this revision

Viewing changes to java/org/apache/naming/factory/TransactionFactory.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Emmanuel Bourg, tony mancill
  • Date: 2014-06-24 21:28:37 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140624212837-w4w84z61r59u5ped
Tags: 8.0.9-1
[ Emmanuel Bourg ]
* New upstream release
  - Refreshed the patches
* Search for OpenJDK 8 and Oracle JDKs when starting the server
* Removed the dependency on the non existent java-7-runtime package
* Fixed a link still pointing to the Tomcat 7 documentation in README.Debian
* Updated the version required for libtcnative-1 (>= 1.1.30)

[ tony mancill ]
* Update README.Debian with information about migration guides.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 * See the License for the specific language governing permissions and
15
15
 * limitations under the License.
16
16
 */
17
 
 
18
 
 
19
17
package org.apache.naming.factory;
20
18
 
21
 
import java.util.Hashtable;
22
 
 
23
 
import javax.naming.Context;
24
 
import javax.naming.Name;
25
 
import javax.naming.NamingException;
26
 
import javax.naming.RefAddr;
27
19
import javax.naming.Reference;
28
20
import javax.naming.spi.ObjectFactory;
29
21
 
34
26
 *
35
27
 * @author Remy Maucherat
36
28
 */
37
 
public class TransactionFactory
38
 
    implements ObjectFactory {
39
 
 
40
 
 
41
 
    // ----------------------------------------------------------- Constructors
42
 
 
43
 
 
44
 
    // -------------------------------------------------------------- Constants
45
 
 
46
 
 
47
 
    // ----------------------------------------------------- Instance Variables
48
 
 
49
 
 
50
 
    // --------------------------------------------------------- Public Methods
51
 
 
52
 
 
53
 
    // -------------------------------------------------- ObjectFactory Methods
54
 
 
55
 
 
56
 
    /**
57
 
     * Create a new User transaction instance.
58
 
     *
59
 
     * @param obj The reference object describing the DataSource
60
 
     */
61
 
    @Override
62
 
    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
63
 
                                    Hashtable<?,?> environment)
64
 
        throws Exception {
65
 
 
66
 
        if (obj instanceof TransactionRef) {
67
 
            Reference ref = (Reference) obj;
68
 
            ObjectFactory factory = null;
69
 
            RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
70
 
            if (factoryRefAddr != null) {
71
 
                // Using the specified factory
72
 
                String factoryClassName =
73
 
                    factoryRefAddr.getContent().toString();
74
 
                // Loading factory
75
 
                ClassLoader tcl =
76
 
                    Thread.currentThread().getContextClassLoader();
77
 
                Class<?> factoryClass = null;
78
 
                if (tcl != null) {
79
 
                    try {
80
 
                        factoryClass = tcl.loadClass(factoryClassName);
81
 
                    } catch(ClassNotFoundException e) {
82
 
                        NamingException ex = new NamingException
83
 
                            ("Could not load resource factory class");
84
 
                        ex.initCause(e);
85
 
                        throw ex;
86
 
                    }
87
 
                } else {
88
 
                    try {
89
 
                        factoryClass = Class.forName(factoryClassName);
90
 
                    } catch(ClassNotFoundException e) {
91
 
                        NamingException ex = new NamingException
92
 
                            ("Could not load resource factory class");
93
 
                        ex.initCause(e);
94
 
                        throw ex;
95
 
                    }
96
 
                }
97
 
                if (factoryClass != null) {
98
 
                    try {
99
 
                        factory = (ObjectFactory) factoryClass.newInstance();
100
 
                    } catch(Throwable t) {
101
 
                        if (t instanceof NamingException)
102
 
                            throw (NamingException) t;
103
 
                        NamingException ex = new NamingException
104
 
                            ("Could not create resource factory instance");
105
 
                        ex.initCause(t);
106
 
                        throw ex;
107
 
                    }
108
 
                }
109
 
            }
110
 
            if (factory != null) {
111
 
                return factory.getObjectInstance
112
 
                    (obj, name, nameCtx, environment);
113
 
            } else {
114
 
                throw new NamingException
115
 
                    ("Cannot create resource instance");
116
 
            }
117
 
 
118
 
        }
119
 
 
120
 
        return null;
121
 
 
122
 
    }
123
 
 
124
 
 
 
29
public class TransactionFactory extends FactoryBase {
 
30
 
 
31
    @Override
 
32
    protected boolean isReferenceTypeSupported(Object obj) {
 
33
        return obj instanceof TransactionRef;
 
34
    }
 
35
 
 
36
    @Override
 
37
    protected ObjectFactory getDefaultFactory(Reference ref) {
 
38
        // No default factory supported.
 
39
        return null;
 
40
    }
 
41
 
 
42
    @Override
 
43
    protected Object getLinked(Reference ref) {
 
44
        // Not supported
 
45
        return null;
 
46
    }
125
47
}
126