KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > txtimer > TimedObjectInvokerImpl


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * 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.ejb.txtimer;
23
24 // $Id: TimedObjectInvokerImpl.java 37858 2005-11-05 17:06:17Z dimitris $
25

26 import org.jboss.ejb.Container;
27 import org.jboss.invocation.Invocation;
28 import org.jboss.invocation.InvocationKey;
29 import org.jboss.invocation.InvocationType;
30 import org.jboss.invocation.PayloadKey;
31 import org.jboss.security.RunAsIdentity;
32 import org.jboss.metadata.BeanMetaData;
33 import org.jboss.metadata.SecurityIdentityMetaData;
34 import org.jboss.metadata.AssemblyDescriptorMetaData;
35 import org.jboss.metadata.ApplicationMetaData;
36
37 import javax.ejb.TimedObject JavaDoc;
38 import javax.ejb.Timer JavaDoc;
39 import java.lang.reflect.Method JavaDoc;
40 import java.util.Set JavaDoc;
41
42 /**
43  * An implementation of a TimedObjectInvoker, that can invoke deployed
44  * EB, SLSB, and MDB
45  *
46  * @author Thomas.Diesler@jboss.org
47  * @author Scott.Stark@jboss.org
48  * @version $Revision: 37858 $
49  * @since 07-Apr-2004
50  */

51 public class TimedObjectInvokerImpl implements TimedObjectInvoker
52 {
53    private Container container;
54    private TimedObjectId timedObjectId;
55    private Method JavaDoc method;
56
57    public TimedObjectInvokerImpl(TimedObjectId timedObjectId, Container container)
58    {
59       try
60       {
61          this.container = container;
62          this.timedObjectId = timedObjectId;
63          this.method = TimedObject JavaDoc.class.getMethod("ejbTimeout", new Class JavaDoc[]{Timer JavaDoc.class});
64
65       }
66       catch (NoSuchMethodException JavaDoc ignore)
67       {
68       }
69    }
70
71    /**
72     * Invokes the ejbTimeout method on the TimedObject with the given id.
73     *
74     * @param timer The Timer that is passed to ejbTimeout
75     */

76    public void callTimeout(Timer JavaDoc timer)
77            throws Exception JavaDoc
78    {
79       ClassLoader JavaDoc callerClassLoader = SecurityActions.getContextClassLoader();
80       SecurityActions.setContextClassLoader(container.getClassLoader());
81       try
82       {
83          Invocation inv = new Invocation(timedObjectId.getInstancePk(), method, new Object JavaDoc[]{timer}, null, null, null);
84          inv.setValue(InvocationKey.INVOKER_PROXY_BINDING, null, PayloadKey.AS_IS);
85          inv.setType(InvocationType.LOCAL);
86          BeanMetaData bmd = container.getBeanMetaData();
87          SecurityIdentityMetaData ejbTimeoutIdentity = bmd.getEjbTimeoutIdentity();
88          if( ejbTimeoutIdentity != null && ejbTimeoutIdentity.getUseCallerIdentity() == false )
89          {
90             ApplicationMetaData applicationMetaData = bmd.getApplicationMetaData();
91             AssemblyDescriptorMetaData assemblyDescriptor = applicationMetaData.getAssemblyDescriptor();
92             String JavaDoc roleName = ejbTimeoutIdentity.getRunAsRoleName();
93             String JavaDoc principalName = ejbTimeoutIdentity.getRunAsPrincipalName();
94             // the run-as principal might have extra roles mapped in the assembly-descriptor
95
Set JavaDoc extraRoleNames = assemblyDescriptor.getSecurityRoleNamesByPrincipal(principalName);
96             RunAsIdentity runAsIdentity = new RunAsIdentity(roleName, principalName, extraRoleNames);
97             SecurityActions.pushRunAsIdentity(runAsIdentity);
98          }
99          container.invoke(inv);
100       }
101       finally
102       {
103          SecurityActions.popRunAsIdentity();
104          SecurityActions.setContextClassLoader(callerClassLoader);
105       }
106    }
107 }
108
Popular Tags