blob: 117c51845cf3373773b047c68ebee00c4520cadf [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<!-- $PAGETITLE -->
<TITLE>OpenEJB - EjbContext Whiteboard</TITLE>
<LINK href="http://openejb.apache.org/all.css" rel="stylesheet" type="text/css">
<!--[if IE]><link rel="stylesheet" type="text/css" media="screen, projection" href="openejb.apache.org/ie.css"><![endif]-->
<LINK rel="SHORTCUT ICON" href="http://openejb.apache.org/images/favicon.ico">
<META http-equiv="Content-Type" content="text/html;charset=UTF-8">
<SCRIPT language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></SCRIPT>
<SCRIPT language="javascript" src="http://openejb.apache.org/tweet/jquery.tweet.js" type="text/javascript"></SCRIPT>
<SCRIPT type="text/javascript">
$(document).ready(function(){
$(".tweet").tweet({
avatar_size: 32,
count: 4,
fetch:25,
username: "openejb",
list: "contributors",
template:"{avatar}{text}",
filter: function(t){ return /openejb/i.test(t["tweet_raw_text"]); },
loading_text: "loading list..."
});
});
</SCRIPT>
</HEAD>
<BODY>
<!-- Delay the loading of the external javascript file needed for labels (as it takes too long to load and visibly holds loading of the page body) -->
<!-- To do this without javascript errors over undefined functions, we need to declare stubs here (that are overrided later by the proper implementations) -->
<SCRIPT language="JavaScript" type="text/javascript">
function doAddLabel(hideTextfieldAfterAddParam)
{
// stub
}
function onAddLabel()
{
// stub
}
function showLabelsInput()
{
// stub
}
</SCRIPT>
<A name="top"></A>
<TABLE class="frameTable" cellpadding="0" cellspacing="0" border="0">
<TR class="Row1">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row2">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3" id="breadcrumbs">
<!-- $TOP_NAV_BAR -->
<A href="index.html" title="Index">Home</A> | <A href="news.html" title="News">News</A> | <A href="faq.html" title="FAQ">FAQ</A> | <A href="download.html" title="Download">Download</A> | <A href="mailing-lists.html" title="Mailing Lists">Lists</A> | <A href="http://issues.apache.org/jira/browse/OPENEJB" class="external-link" rel="nofollow">Issues</A>
</TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
<TR class="Row3">
<TD class="Col1"><IMG alt="" class="Row3Img" id="thinLine" src="http://openejb.apache.org/images/line_sm.gif"></TD>
<TD class="Col2"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row4">
<TD class="Col1">
<SPAN id="Navigation">
<H3><A name="Navigation-Overview"></A>Overview</H3>
<UL class="alternate" type="square">
<LI><A href="index.html" title="Index">Home</A></LI>
<LI><A href="news.html" title="News">News</A></LI>
<LI><A href="faq.html" title="FAQ">FAQ</A></LI>
<LI><A href="download.html" title="Download">Download</A></LI>
<LI><A href="../OPENEJBx30/index.html" title="Index">Documentation</A></LI>
<LI><A href="examples.html" title="Examples">Examples</A></LI>
<LI><A href="http://cwiki.apache.org/confluence/display/OPENEJB/Lightening%20Demos" class="external-link" rel="nofollow">Lightning Demos</A></LI>
<LI><A href="mailing-lists.html" title="Mailing Lists">Mailing Lists</A></LI>
<LI><A href="source-code.html" title="Source Code">Source Code</A></LI>
<LI><A href="http://blogs.apache.org/openejb" class="external-link" rel="nofollow">Project Blog</A></LI>
</UL>
<H3><A name="Navigation-Servers"></A>Servers</H3>
<UL class="alternate" type="square">
<LI><A href="local-server.html" title="Local Server">Local</A></LI>
<LI><A href="remote-server.html" title="Remote Server">Remote</A></LI>
</UL>
<H3><A name="Navigation-Integrations"></A>Integrations</H3>
<UL class="alternate" type="square">
<LI><A href="../OPENEJBx30/tomcat.html" title="Tomcat">Tomcat</A></LI>
<LI><A href="geronimo.html" title="Geronimo">Geronimo</A></LI>
<LI><A href="webobjects.html" title="WebObjects">WebObjects</A></LI>
</UL>
<H3><A name="Navigation-Community"></A>Community</H3>
<UL class="alternate" type="square">
<LI><A href="team.html" title="Team">Team</A></LI>
<LI><A href="articles.html" title="Articles">Articles</A></LI>
<LI><A href="http://webchat.freenode.net/?channels=openejb" class="external-link" rel="nofollow">IRC</A></LI>
</UL>
<H3><A name="Navigation-RelatedProjects"></A>Related Projects</H3>
<UL class="alternate" type="square">
<LI><A href="http://activemq.apache.org/" class="external-link" rel="nofollow">ActiveMQ</A></LI>
<LI><A href="http://openjpa.apache.org/" class="external-link" rel="nofollow">OpenJPA</A></LI>
<LI><A href="http://cxf.apache.org/" class="external-link" rel="nofollow">CXF</A></LI>
</UL>
<H3><A name="Navigation-Index"></A>Index</H3>
<UL class="alternate" type="square">
<LI><A href="space-index.html" title="Space Index">Site Index</A></LI>
<LI><A href="../OPENEJBx30/space-index.html" title="Space Index">Doc Index</A></LI>
</UL>
<H3>
<A name="Navigation-Feeds"></A>
Feeds
</H3>
<UL class="feeds">
<LI>
<A href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">Site</A>
</LI>
<LI><A href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">News</A>
</LI>
</UL>
</SPAN>
</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<TABLE id="PageHeader" border="0" width="100%">
<TR>
<TD>
<A href="http://openejb.org/">
<IMG hspace="0" src="http://openejb.apache.org/images/logo_openejb.gif" vspace="0">
</A>
</TD>
<TD align="right">
<A href="http://www.apache.org/">
<IMG src="http://www.apache.org/images/asf-logo.gif" width="258" height="66">
</A>
</TD>
</TR>
<TR>
<TD id="page_title">
<!-- $TITLE -->
EjbContext Whiteboard
</TD>
<TD align="right">
<BR><BR>
<!-- Google CSE Search Box Begins -->
<FORM id="searchbox_010475492895890475512:_t4iqjrgx90" action="http://www.google.com/cse">
<INPUT type="hidden" name="cx" value="010475492895890475512:_t4iqjrgx90">
<INPUT type="hidden" name="cof" value="FORID:0">
<INPUT name="q" type="text" size="25">
<INPUT type="submit" name="sa" value="Search">
</FORM>
<SCRIPT type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_010475492895890475512:_t4iqjrgx90"></SCRIPT>
<!-- Google CSE Search Box Ends -->
</TD>
</TR>
</TABLE>
<P>
<!-- $BODY -->
<DIV id="PageContent">
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>CoreContext.java</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* <SPAN class="code-keyword">this</SPAN> work <SPAN class="code-keyword">for</SPAN> additional information regarding copyright ownership.
* The ASF licenses <SPAN class="code-keyword">this</SPAN> file to You under the Apache License, Version 2.0
* (the <SPAN class="code-quote">&quot;License&quot;</SPAN>); you may not use <SPAN class="code-keyword">this</SPAN> file except in compliance with
* the License. You may obtain a copy of the License at
*
* http:<SPAN class="code-comment">//www.apache.org/licenses/LICENSE-2.0
</SPAN> *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an <SPAN class="code-quote">&quot;AS IS&quot;</SPAN> BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License <SPAN class="code-keyword">for</SPAN> the specific language governing permissions and
* limitations under the License.
*/
<SPAN class="code-keyword">package</SPAN> org.apache.openejb.core;
<SPAN class="code-keyword">import</SPAN> java.util.List;
<SPAN class="code-keyword">import</SPAN> javax.ejb.EJBHome;
<SPAN class="code-keyword">import</SPAN> javax.ejb.EJBLocalHome;
<SPAN class="code-keyword">import</SPAN> javax.ejb.EJBLocalObject;
<SPAN class="code-keyword">import</SPAN> javax.ejb.TimerService;
<SPAN class="code-keyword">import</SPAN> javax.naming.Context;
<SPAN class="code-keyword">import</SPAN> javax.naming.InitialContext;
<SPAN class="code-keyword">import</SPAN> javax.naming.NamingException;
<SPAN class="code-keyword">import</SPAN> javax.transaction.Status;
<SPAN class="code-keyword">import</SPAN> javax.transaction.TransactionManager;
<SPAN class="code-keyword">import</SPAN> javax.transaction.UserTransaction;
<SPAN class="code-keyword">import</SPAN> java.util.List;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.DeploymentInfo;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.InterfaceType;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.RpcContainer;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.InternalErrorException;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.core.ivm.EjbObjectProxyHandler;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.core.ivm.IntraVmProxy;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.spi.SecurityService;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.util.proxy.ProxyManager;
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">abstract</SPAN> class CoreContext <SPAN class="code-keyword">implements</SPAN> java.io.Serializable {
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">static</SPAN> <SPAN class="code-keyword">enum</SPAN> Call {
getEJBHome,
getCallerPrincipal,
getRollbackOnly,
isCallerInRole,
setRollbackOnly,
getEJBObject,
getPrimaryKey,
getUserTransaction
}
<SPAN class="code-keyword">private</SPAN> <SPAN class="code-keyword">final</SPAN> UserTransaction userTransaction;
<SPAN class="code-keyword">private</SPAN> <SPAN class="code-keyword">final</SPAN> SecurityService securityService;
<SPAN class="code-keyword">private</SPAN> <SPAN class="code-keyword">final</SPAN> TransactionManager transactionManager;
<SPAN class="code-keyword">public</SPAN> CoreContext(TransactionManager transactionManager, SecurityService securityService) {
<SPAN class="code-keyword">this</SPAN>.transactionManager = transactionManager;
<SPAN class="code-keyword">this</SPAN>.securityService = securityService;
<SPAN class="code-keyword">this</SPAN>.userTransaction = <SPAN class="code-keyword">new</SPAN> CoreUserTransaction(transactionManager);
}
<SPAN class="code-keyword">protected</SPAN> CoreContext(TransactionManager transactionManager, SecurityService securityService, UserTransaction userTransaction) {
<SPAN class="code-keyword">this</SPAN>.transactionManager = transactionManager;
<SPAN class="code-keyword">this</SPAN>.securityService = securityService;
<SPAN class="code-keyword">this</SPAN>.userTransaction = userTransaction;
}
<SPAN class="code-keyword">private</SPAN> TransactionManager getTransactionManager() {
<SPAN class="code-keyword">return</SPAN> transactionManager;
}
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-keyword">abstract</SPAN> void checkBeanState(Call methodCategory) <SPAN class="code-keyword">throws</SPAN> IllegalStateException;
<SPAN class="code-keyword">public</SPAN> java.security.Principal getCallerPrincipal() {
checkBeanState(Call.getCallerPrincipal);
<SPAN class="code-object">Object</SPAN> securityIdentity = ThreadContext.getThreadContext().getSecurityIdentity();
<SPAN class="code-keyword">return</SPAN> (java.security.Principal) getSecurityService().translateTo(securityIdentity, java.security.Principal.class);
}
<SPAN class="code-keyword">private</SPAN> SecurityService getSecurityService() {
<SPAN class="code-keyword">return</SPAN> securityService;
}
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">boolean</SPAN> isCallerInRole(java.lang.<SPAN class="code-object">String</SPAN> roleName) {
checkBeanState(Call.isCallerInRole);
ThreadContext threadContext = ThreadContext.getThreadContext();
org.apache.openejb.core.CoreDeploymentInfo di = (org.apache.openejb.core.CoreDeploymentInfo) threadContext.getDeploymentInfo();
List&lt;<SPAN class="code-object">String</SPAN>&gt; physicalRoles = di.getPhysicalRole(roleName);
<SPAN class="code-object">Object</SPAN> caller = threadContext.getSecurityIdentity();
<SPAN class="code-keyword">return</SPAN> securityService.isCallerAuthorized(caller, physicalRoles);
}
<SPAN class="code-keyword">public</SPAN> EJBHome getEJBHome() {
checkBeanState(Call.getEJBHome);
ThreadContext threadContext = ThreadContext.getThreadContext();
org.apache.openejb.core.CoreDeploymentInfo di = (org.apache.openejb.core.CoreDeploymentInfo) threadContext.getDeploymentInfo();
<SPAN class="code-keyword">return</SPAN> di.getEJBHome();
}
<SPAN class="code-keyword">public</SPAN> javax.ejb.EJBObject getEJBObject() {
checkBeanState(Call.getEJBObject);
ThreadContext threadContext = ThreadContext.getThreadContext();
org.apache.openejb.DeploymentInfo di = threadContext.getDeploymentInfo();
EjbObjectProxyHandler handler = newEjbObjectHandler((RpcContainer) di.getContainer(), threadContext.getPrimaryKey(), di.getDeploymentID(), InterfaceType.EJB_OBJECT);
<SPAN class="code-object">Object</SPAN> newProxy = <SPAN class="code-keyword">null</SPAN>;
<SPAN class="code-keyword">try</SPAN> {
<SPAN class="code-object">Class</SPAN>[] interfaces = <SPAN class="code-keyword">new</SPAN> <SPAN class="code-object">Class</SPAN>[]{di.getRemoteInterface(), org.apache.openejb.core.ivm.IntraVmProxy.class};
newProxy = ProxyManager.newProxyInstance(interfaces, handler);
} <SPAN class="code-keyword">catch</SPAN> (IllegalAccessException iae) {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> RuntimeException(<SPAN class="code-quote">&quot;Could not create IVM proxy <SPAN class="code-keyword">for</SPAN> &quot;</SPAN> + di.getRemoteInterface() + <SPAN class="code-quote">&quot; <SPAN class="code-keyword">interface</SPAN>&quot;</SPAN>);
}
<SPAN class="code-keyword">return</SPAN> (javax.ejb.EJBObject) newProxy;
}
<SPAN class="code-keyword">public</SPAN> EJBLocalObject getEJBLocalObject() {
ThreadContext threadContext = ThreadContext.getThreadContext();
org.apache.openejb.DeploymentInfo di = threadContext.getDeploymentInfo();
EjbObjectProxyHandler handler = newEjbObjectHandler((RpcContainer) di.getContainer(), threadContext.getPrimaryKey(), di.getDeploymentID(), InterfaceType.EJB_LOCAL);
handler.setLocal(<SPAN class="code-keyword">true</SPAN>);
<SPAN class="code-object">Object</SPAN> newProxy = <SPAN class="code-keyword">null</SPAN>;
<SPAN class="code-keyword">try</SPAN> {
<SPAN class="code-object">Class</SPAN>[] interfaces = <SPAN class="code-keyword">new</SPAN> <SPAN class="code-object">Class</SPAN>[]{di.getLocalInterface(), org.apache.openejb.core.ivm.IntraVmProxy.class};
newProxy = ProxyManager.newProxyInstance(interfaces, handler);
} <SPAN class="code-keyword">catch</SPAN> (IllegalAccessException iae) {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> RuntimeException(<SPAN class="code-quote">&quot;Could not create IVM proxy <SPAN class="code-keyword">for</SPAN> &quot;</SPAN> + di.getLocalInterface() + <SPAN class="code-quote">&quot; <SPAN class="code-keyword">interface</SPAN>&quot;</SPAN>);
}
<SPAN class="code-keyword">return</SPAN> (EJBLocalObject) newProxy;
}
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">Object</SPAN> getBusinessObject(<SPAN class="code-object">Class</SPAN> interfce) {
ThreadContext threadContext = ThreadContext.getThreadContext();
DeploymentInfo di = threadContext.getDeploymentInfo();
InterfaceType interfaceType;
<SPAN class="code-keyword">if</SPAN> (di.getBusinessLocalInterface() != <SPAN class="code-keyword">null</SPAN> &amp;&amp; di.getBusinessLocalInterface().getName().equals(interfce.getName())) {
interfaceType = InterfaceType.BUSINESS_LOCAL;
} <SPAN class="code-keyword">else</SPAN> <SPAN class="code-keyword">if</SPAN> (di.getBusinessRemoteInterface() != <SPAN class="code-keyword">null</SPAN> &amp;&amp; di.getBusinessRemoteInterface().getName().equals(interfce.getName())) {
interfaceType = InterfaceType.BUSINESS_REMOTE;
} <SPAN class="code-keyword">else</SPAN> {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalArgumentException(<SPAN class="code-quote">&quot;Component has no such <SPAN class="code-keyword">interface</SPAN> &quot;</SPAN> + interfce.getName());
}
<SPAN class="code-object">Object</SPAN> newProxy;
<SPAN class="code-keyword">try</SPAN> {
EjbObjectProxyHandler handler = newEjbObjectHandler((RpcContainer) di.getContainer(), threadContext.getPrimaryKey(), di.getDeploymentID(), interfaceType);
<SPAN class="code-object">Class</SPAN>[] interfaces = <SPAN class="code-keyword">new</SPAN> <SPAN class="code-object">Class</SPAN>[]{interfce, IntraVmProxy.class};
newProxy = ProxyManager.newProxyInstance(interfaces, handler);
} <SPAN class="code-keyword">catch</SPAN> (IllegalAccessException iae) {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> InternalErrorException(<SPAN class="code-quote">&quot;Could not create IVM proxy <SPAN class="code-keyword">for</SPAN> &quot;</SPAN> + interfce.getName() + <SPAN class="code-quote">&quot; <SPAN class="code-keyword">interface</SPAN>&quot;</SPAN>, iae);
}
<SPAN class="code-keyword">return</SPAN> newProxy;
}
<SPAN class="code-keyword">public</SPAN> EJBLocalHome getEJBLocalHome() {
ThreadContext threadContext = ThreadContext.getThreadContext();
org.apache.openejb.core.CoreDeploymentInfo di = threadContext.getDeploymentInfo();
<SPAN class="code-keyword">return</SPAN> di.getEJBLocalHome();
}
<SPAN class="code-keyword">public</SPAN> TimerService getTimerService() {
<SPAN class="code-keyword">return</SPAN> <SPAN class="code-keyword">null</SPAN>;
}
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">Object</SPAN> getPrimaryKey() {
/*
* This method is only declared in the EntityContext <SPAN class="code-keyword">interface</SPAN> and is therefor
* unavailable in the SessionContext and doesn't not require a check <SPAN class="code-keyword">for</SPAN> bean kind (Entity vs Session).
*/
checkBeanState(Call.getPrimaryKey);
ThreadContext threadContext = ThreadContext.getThreadContext();
<SPAN class="code-keyword">return</SPAN> threadContext.getPrimaryKey();
}
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">boolean</SPAN> getRollbackOnly() {
ThreadContext threadContext = ThreadContext.getThreadContext();
org.apache.openejb.DeploymentInfo di = threadContext.getDeploymentInfo();
<SPAN class="code-keyword">if</SPAN> (di.isBeanManagedTransaction()) {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalStateException(<SPAN class="code-quote">&quot;bean-managed transaction beans can not access the getRollbackOnly( ) method&quot;</SPAN>);
}
checkBeanState(Call.getRollbackOnly);
<SPAN class="code-keyword">try</SPAN> {
<SPAN class="code-object">int</SPAN> status = getTransactionManager().getStatus();
<SPAN class="code-keyword">if</SPAN> (status == Status.STATUS_MARKED_ROLLBACK || status == Status.STATUS_ROLLEDBACK) {
<SPAN class="code-keyword">return</SPAN> <SPAN class="code-keyword">true</SPAN>;
} <SPAN class="code-keyword">else</SPAN> <SPAN class="code-keyword">if</SPAN> (status == Status.STATUS_NO_TRANSACTION) {
<SPAN class="code-comment">// <SPAN class="code-keyword">this</SPAN> would be <SPAN class="code-keyword">true</SPAN> <SPAN class="code-keyword">for</SPAN> Supports tx attribute where no tx was propagated
</SPAN> <SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalStateException(<SPAN class="code-quote">&quot;No current transaction&quot;</SPAN>);
} <SPAN class="code-keyword">else</SPAN> {
<SPAN class="code-keyword">return</SPAN> <SPAN class="code-keyword">false</SPAN>;
}
} <SPAN class="code-keyword">catch</SPAN> (javax.transaction.SystemException se) {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> RuntimeException(<SPAN class="code-quote">&quot;Transaction service has thrown a SystemException&quot;</SPAN>);
}
}
<SPAN class="code-keyword">public</SPAN> void setRollbackOnly() {
ThreadContext threadContext = ThreadContext.getThreadContext();
org.apache.openejb.DeploymentInfo di = threadContext.getDeploymentInfo();
<SPAN class="code-keyword">if</SPAN> (di.isBeanManagedTransaction()) {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalStateException(<SPAN class="code-quote">&quot;bean-managed transaction beans can not access the setRollbackOnly( ) method&quot;</SPAN>);
}
checkBeanState(Call.setRollbackOnly);
<SPAN class="code-keyword">try</SPAN> {
getTransactionManager().setRollbackOnly();
} <SPAN class="code-keyword">catch</SPAN> (javax.transaction.SystemException se) {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> RuntimeException(<SPAN class="code-quote">&quot;Transaction service has thrown a SystemException&quot;</SPAN>);
}
}
<SPAN class="code-keyword">public</SPAN> javax.transaction.UserTransaction getUserTransaction() {
ThreadContext threadContext = ThreadContext.getThreadContext();
org.apache.openejb.DeploymentInfo di = threadContext.getDeploymentInfo();
<SPAN class="code-keyword">if</SPAN> (di.isBeanManagedTransaction()) {
checkBeanState(Call.getUserTransaction);
<SPAN class="code-keyword">return</SPAN> userTransaction;
} <SPAN class="code-keyword">else</SPAN> {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> java.lang.IllegalStateException(<SPAN class="code-quote">&quot;container-managed transaction beans can not access the UserTransaction&quot;</SPAN>);
}
}
/**
* Lookup a resource within the component's <SPAN class="code-keyword">private</SPAN> naming context.
*
* @param name - Name of the entry (relative to java:comp/env).
* @<SPAN class="code-keyword">return</SPAN> The looked-up object.
* @see http:<SPAN class="code-comment">//java.sun.com/javaee/5/docs/api/javax/ejb/EJBContext.html#lookup(java.lang.<SPAN class="code-object">String</SPAN>)
</SPAN> * @see EJB3.0 <SPAN class="code-quote">&quot;Core Contracts and Requirements&quot;</SPAN>, section 4.5.2, table 2.
*/
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">Object</SPAN> lookup(<SPAN class="code-object">String</SPAN> name) {
Context initialContext = <SPAN class="code-keyword">null</SPAN>;
<SPAN class="code-object">Object</SPAN> object = <SPAN class="code-keyword">null</SPAN>;
<SPAN class="code-keyword">try</SPAN> {
initialContext = <SPAN class="code-keyword">new</SPAN> InitialContext();
object = initialContext.lookup(<SPAN class="code-quote">&quot;java:comp/env/&quot;</SPAN> + name);
} <SPAN class="code-keyword">catch</SPAN> (NamingException nex) {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalArgumentException(nex);
}
<SPAN class="code-keyword">return</SPAN> object;
}
/*----------------------------------------------------*/
/* UNSUPPORTED DEPRICATED METHODS */
/*----------------------------------------------------*/
<SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">boolean</SPAN> isCallerInRole(java.security.Identity role) {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> java.lang.UnsupportedOperationException();
}
<SPAN class="code-keyword">public</SPAN> java.security.Identity getCallerIdentity() {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> java.lang.UnsupportedOperationException();
}
<SPAN class="code-keyword">public</SPAN> java.util.Properties getEnvironment() {
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> java.lang.UnsupportedOperationException();
}
<SPAN class="code-keyword">protected</SPAN> <SPAN class="code-keyword">abstract</SPAN> EjbObjectProxyHandler newEjbObjectHandler(RpcContainer container, <SPAN class="code-object">Object</SPAN> pk, <SPAN class="code-object">Object</SPAN> depID, InterfaceType interfaceType);
}
</PRE>
</DIV></DIV>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>EntityContext.java</B></DIV><DIV class="codeContent panelContent">
<PRE class="code-java">
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* <SPAN class="code-keyword">this</SPAN> work <SPAN class="code-keyword">for</SPAN> additional information regarding copyright ownership.
* The ASF licenses <SPAN class="code-keyword">this</SPAN> file to You under the Apache License, Version 2.0
* (the <SPAN class="code-quote">&quot;License&quot;</SPAN>); you may not use <SPAN class="code-keyword">this</SPAN> file except in compliance with
* the License. You may obtain a copy of the License at
*
* http:<SPAN class="code-comment">//www.apache.org/licenses/LICENSE-2.0
</SPAN> *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an <SPAN class="code-quote">&quot;AS IS&quot;</SPAN> BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License <SPAN class="code-keyword">for</SPAN> the specific language governing permissions and
* limitations under the License.
*/
<SPAN class="code-keyword">package</SPAN> org.apache.openejb.core.entity;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.RpcContainer;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.InterfaceType;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.spi.SecurityService;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.core.ThreadContext;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.core.Operation;
<SPAN class="code-keyword">import</SPAN> org.apache.openejb.core.ivm.EjbObjectProxyHandler;
<SPAN class="code-keyword">import</SPAN> javax.transaction.TransactionManager;
<SPAN class="code-keyword">public</SPAN> class EntityContext <SPAN class="code-keyword">extends</SPAN> org.apache.openejb.core.CoreContext <SPAN class="code-keyword">implements</SPAN> javax.ejb.EntityContext {
<SPAN class="code-keyword">public</SPAN> EntityContext(TransactionManager transactionManager, SecurityService securityService) {
<SPAN class="code-keyword">super</SPAN>(transactionManager, securityService);
}
<SPAN class="code-keyword">public</SPAN> void checkBeanState(Call methodCategory) <SPAN class="code-keyword">throws</SPAN> IllegalStateException {
/*
The <SPAN class="code-keyword">super</SPAN> class, CoreContext determines <SPAN class="code-keyword">if</SPAN> Context.getUserTransaction( ) method
maybe called before invoking <SPAN class="code-keyword">this</SPAN>.checkBeanState( ). Only <SPAN class="code-quote">&quot;bean managed&quot;</SPAN> transaction
beans may access <SPAN class="code-keyword">this</SPAN> method.
The USER_TRANSACTION_METHOD constant will never be a methodCategory
because entity beans are not allowed to have <SPAN class="code-quote">&quot;bean managed&quot;</SPAN> transactions.
USER_TRANSACTION_METHOD:
*/
ThreadContext callContext = ThreadContext.getThreadContext();
org.apache.openejb.DeploymentInfo di = callContext.getDeploymentInfo();
Operation currentOperation = callContext.getCurrentOperation();
<SPAN class="code-keyword">switch</SPAN> (currentOperation) {
<SPAN class="code-keyword">case</SPAN> SET_CONTEXT:
<SPAN class="code-keyword">case</SPAN> UNSET_CONTEXT:
<SPAN class="code-keyword">switch</SPAN>(methodCategory){
<SPAN class="code-keyword">case</SPAN> getCallerPrincipal:
<SPAN class="code-keyword">case</SPAN> getRollbackOnly:
<SPAN class="code-keyword">case</SPAN> isCallerInRole:
<SPAN class="code-keyword">case</SPAN> setRollbackOnly:
<SPAN class="code-keyword">case</SPAN> getEJBObject:
<SPAN class="code-keyword">case</SPAN> getPrimaryKey:
<SPAN class="code-keyword">case</SPAN> getUserTransaction:
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalStateException(methodCategory + <SPAN class="code-quote">&quot;cannot be called in &quot;</SPAN> + currentOperation);
}
<SPAN class="code-keyword">break</SPAN>;
<SPAN class="code-keyword">case</SPAN> CREATE:
<SPAN class="code-keyword">case</SPAN> FIND:
<SPAN class="code-keyword">case</SPAN> HOME:
<SPAN class="code-keyword">switch</SPAN>(methodCategory){
<SPAN class="code-keyword">case</SPAN> getEJBObject:
<SPAN class="code-keyword">case</SPAN> getPrimaryKey:
<SPAN class="code-keyword">case</SPAN> getUserTransaction:
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalStateException(methodCategory + <SPAN class="code-quote">&quot;cannot be called in &quot;</SPAN> + currentOperation);
}
<SPAN class="code-keyword">break</SPAN>;
<SPAN class="code-keyword">case</SPAN> ACTIVATE:
<SPAN class="code-keyword">case</SPAN> PASSIVATE:
<SPAN class="code-keyword">switch</SPAN>(methodCategory){
<SPAN class="code-keyword">case</SPAN> getCallerPrincipal:
<SPAN class="code-keyword">case</SPAN> getRollbackOnly:
<SPAN class="code-keyword">case</SPAN> isCallerInRole:
<SPAN class="code-keyword">case</SPAN> setRollbackOnly:
<SPAN class="code-keyword">case</SPAN> getUserTransaction:
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalStateException(methodCategory + <SPAN class="code-quote">&quot;cannot be called in &quot;</SPAN> + currentOperation);
}
<SPAN class="code-keyword">break</SPAN>;
<SPAN class="code-keyword">case</SPAN> POST_CREATE:
<SPAN class="code-keyword">case</SPAN> REMOVE:
<SPAN class="code-keyword">case</SPAN> LOAD:
<SPAN class="code-keyword">case</SPAN> STORE:
<SPAN class="code-keyword">switch</SPAN>(methodCategory){
<SPAN class="code-keyword">case</SPAN> getUserTransaction:
<SPAN class="code-keyword">throw</SPAN> <SPAN class="code-keyword">new</SPAN> IllegalStateException(methodCategory + <SPAN class="code-quote">&quot;cannot be called in &quot;</SPAN> + currentOperation);
}
<SPAN class="code-keyword">break</SPAN>;
}
}
<SPAN class="code-keyword">protected</SPAN> EjbObjectProxyHandler newEjbObjectHandler(RpcContainer container, <SPAN class="code-object">Object</SPAN> pk, <SPAN class="code-object">Object</SPAN> depID, InterfaceType interfaceType) {
<SPAN class="code-keyword">return</SPAN> <SPAN class="code-keyword">new</SPAN> EntityEjbObjectHandler(container, pk, depID, interfaceType);
}
}
</PRE>
</DIV></DIV>
</DIV>
</P>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">
</TD>
</TR>
<TR class="Row5">
<TD class="Col1">&nbsp;</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<BR>
<BR>
<IMG width="100%" height="1" src="http://openejb.apache.org/images/line_light.gif">
<TABLE width="100%">
<TR>
<TD>
<SPAN class="bodyGrey">
<SMALL>
<NOTICE><!-- $FOOTER -->
Apache OpenEJB is an project of The Apache Software Foundation (ASF)
</NOTICE>
<BR>
Site Powered by
<A href="http://atlassian.com/">Atlassian</A>
<A href="http://atlassian.com/confluence/">Confluence</A>
.
</SMALL>
</SPAN>
</TD>
<TD align="right">
<A style="color:#999;font-size:small;font-weight:normal;" href="https://cwiki.apache.org/confluence/pages/editpage.action?spaceKey=OPENEJB&title=EjbContext%20Whiteboard">[ edit ]</A>
</TD>
</TR>
</TABLE>
<BR>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
</TABLE>
<!-- Needed for composition plugin -->
<!-- delay the loading of large javascript files to the end so that they don't interfere with the loading of page content -->
<SPAN style="display: none">
<SCRIPT type="text/javascript" language="JavaScript" src="http://cwiki.apache.org/confluence/labels-javascript"></SCRIPT>
<SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</SCRIPT>
<SCRIPT type="text/javascript">
_uacct = "UA-2717626-1";
urchinTracker();
</SCRIPT>
</SPAN>
</BODY>
</HTML>