You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2008/09/15 23:43:15 UTC
svn commit: r695644 - in /openejb/trunk/openejb3/container/openejb-core/src:
main/java/org/apache/openejb/assembler/classic/
main/java/org/apache/openejb/core/ivm/naming/java/
test/java/org/apache/openejb/core/ivm/naming/
Author: dblevins
Date: Mon Sep 15 14:43:14 2008
New Revision: 695644
URL: http://svn.apache.org/viewvc?rev=695644&view=rev
Log:
OPENEJB-914: Local Client "java:comp/UserTransaction" lookup
OPENEJB-915: Local Client "java:comp/TransactionManager" lookup
OPENEJB-916: Local Client "java:comp/TransactionSynchronizationRegistry" lookup
Added:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/ivm/naming/JavaLookupTest.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/java/javaURLContextFactory.java
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=695644&r1=695643&r2=695644&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Mon Sep 15 14:43:14 2008
@@ -73,6 +73,8 @@
import org.apache.openejb.core.CoreContainerSystem;
import org.apache.openejb.core.CoreDeploymentInfo;
import org.apache.openejb.core.SimpleTransactionSynchronizationRegistry;
+import org.apache.openejb.core.CoreUserTransaction;
+import org.apache.openejb.core.TransactionSynchronizationRegistryWrapper;
import org.apache.openejb.core.transaction.SimpleWorkManager;
import org.apache.openejb.core.transaction.SimpleBootstrapContext;
import org.apache.openejb.core.transaction.TransactionType;
@@ -1235,6 +1237,8 @@
try {
this.containerSystem.getJNDIContext().bind(JAVA_OPENEJB_NAMING_CONTEXT + serviceInfo.service, service);
+ this.containerSystem.getJNDIContext().bind("java:comp/UserTransaction", new CoreUserTransaction((TransactionManager) service));
+ this.containerSystem.getJNDIContext().bind("java:comp/TransactionManager", service);
} catch (NamingException e) {
throw new OpenEJBException("Cannot bind " + serviceInfo.service + " with id " + serviceInfo.id, e);
}
@@ -1262,9 +1266,17 @@
// todo this should be built
synchronizationRegistry = new SimpleTransactionSynchronizationRegistry(transactionManager);
}
+
Assembler.getContext().put(TransactionSynchronizationRegistry.class.getName(), synchronizationRegistry);
SystemInstance.get().setComponent(TransactionSynchronizationRegistry.class, synchronizationRegistry);
+ try {
+ this.containerSystem.getJNDIContext().bind("java:comp/TransactionSynchronizationRegistry", new TransactionSynchronizationRegistryWrapper());
+ } catch (NamingException e) {
+ throw new OpenEJBException("Cannot bind java:comp/TransactionSynchronizationRegistry", e);
+ }
+
+
// JtaEntityManagerRegistry
// todo this should be built
JtaEntityManagerRegistry jtaEntityManagerRegistry = new JtaEntityManagerRegistry(synchronizationRegistry);
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/java/javaURLContextFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/java/javaURLContextFactory.java?rev=695644&r1=695643&r2=695644&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/java/javaURLContextFactory.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/naming/java/javaURLContextFactory.java Mon Sep 15 14:43:14 2008
@@ -29,43 +29,13 @@
import org.apache.openejb.spi.ContainerSystem;
import org.apache.openejb.loader.SystemInstance;
-public class javaURLContextFactory implements ObjectFactory, InitialContextFactory {
+public class javaURLContextFactory implements ObjectFactory {
- public Context getInitialContext(Hashtable env) throws NamingException {
- return getContext();
- }
-
- public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env)
- throws NamingException {
- if (obj == null) {
- /*
- A null obj ref means the NamingManager is requesting
- a Context that can resolve the 'java:' schema
- */
- return getContext();
- } else if (obj instanceof java.lang.String) {
- String string = (String) obj;
- if (string.startsWith("java:comp") || string.startsWith("java:openejb")) {
- /*
- If the obj is a URL String with the 'java:' schema
- resolve the URL in the context of this threads JNDI ENC
- */
- string = string.substring(string.indexOf(':'));
- Context encRoot = getContext();
- return encRoot.lookup(string);
- }
- }
- return null;
- }
-
- public Object getObjectInstance(Object obj, Hashtable env)
- throws NamingException {
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws NamingException {
return getContext();
}
public Context getContext() {
- Context jndiCtx = null;
-
ThreadContext callContext = ThreadContext.getThreadContext();
if (callContext == null) {
ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
Added: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/ivm/naming/JavaLookupTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/ivm/naming/JavaLookupTest.java?rev=695644&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/ivm/naming/JavaLookupTest.java (added)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/ivm/naming/JavaLookupTest.java Mon Sep 15 14:43:14 2008
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.core.ivm.naming;
+
+import junit.framework.TestCase;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.config.ConfigurationFactory;
+
+import javax.naming.InitialContext;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+import javax.transaction.TransactionSynchronizationRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaLookupTest extends TestCase {
+
+ public void test() throws Exception {
+
+ Assembler assembler = new Assembler();
+ ConfigurationFactory config = new ConfigurationFactory();
+
+ assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+ assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+
+ InitialContext context = new InitialContext();
+ assertTrue(context.lookup("java:openejb/TransactionManager") instanceof TransactionManager);
+
+ assertTrue(context.lookup("java:comp/TransactionManager") instanceof TransactionManager);
+
+ assertTrue(context.lookup("java:comp/UserTransaction") instanceof UserTransaction);
+
+ assertTrue(context.lookup("java:comp/TransactionSynchronizationRegistry") instanceof TransactionSynchronizationRegistry);
+ }
+}