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.injection;
23:
24: import org.jboss.aop.Advisor;
25: import org.jboss.ejb3.BeanContext;
26: import org.jboss.ejb3.Container;
27: import org.jboss.ejb3.tx.TxUtil;
28: import org.jboss.ejb3.tx.UserTransactionImpl;
29:
30: import javax.ejb.TransactionManagementType;
31: import javax.transaction.UserTransaction;
32: import java.lang.reflect.InvocationTargetException;
33: import java.lang.reflect.Method;
34:
35: /**
36: * Comment
37: *
38: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
39: * @version $Revision: 60233 $
40: * @deprecated use UserTransactionPropertyInjector
41: */
42: public class UserTransactionMethodInjector implements Injector {
43: private Method setMethod;
44:
45: public UserTransactionMethodInjector(Method setMethod,
46: InjectionContainer container) {
47: if (container instanceof Container) {
48: TransactionManagementType type = TxUtil
49: .getTransactionManagementType(((Advisor) container));
50: if (type != TransactionManagementType.BEAN)
51: throw new IllegalStateException(
52: "Container "
53: + ((Container) container).getEjbName()
54: + ": it is illegal to inject UserTransaction into a CMT bean");
55: }
56: this .setMethod = setMethod;
57: setMethod.setAccessible(true);
58: }
59:
60: public void inject(BeanContext ctx) {
61: Object instance = ctx.getInstance();
62: inject(instance);
63: }
64:
65: public void inject(Object instance) {
66: UserTransaction ut = new UserTransactionImpl();
67: Object[] args = { ut };
68: try {
69: setMethod.invoke(instance, args);
70: } catch (IllegalAccessException e) {
71: throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
72: } catch (IllegalArgumentException e) {
73: throw new RuntimeException(
74: "Failed in setting EntityManager on setter method: "
75: + setMethod.toString());
76: } catch (InvocationTargetException e) {
77: throw new RuntimeException(e.getCause()); //To change body of catch statement use Options | File Templates.
78: }
79: }
80:
81: public Class getInjectionClass() {
82: return setMethod.getParameterTypes()[0];
83: }
84: }
|