You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/12/13 10:11:12 UTC

svn commit: r486552 - in /incubator/tuscany/java/sca: kernel/api/src/main/java/org/apache/tuscany/api/ kernel/core/src/main/java/org/apache/tuscany/core/services/host/ kernel/core/src/test/java/org/apache/tuscany/core/services/host/ kernel/spi/src/main...

Author: jmarino
Date: Wed Dec 13 01:11:07 2006
New Revision: 486552

URL: http://svn.apache.org/viewvc?view=rev&rev=486552
Log:
modify resource resolution algorithm to be based off a registration model; modify JPA extension to use @Resource

Added:
    incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTMServiceHostRegistryTestCase.java   (with props)
Modified:
    incubator/tuscany/java/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistry.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java
    incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/PersistenceUnitTestCase.java
    incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/TestService1.java
    incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/main/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerService.java
    incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerServiceTestCase.java

Modified: incubator/tuscany/java/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java?view=diff&rev=486552&r1=486551&r2=486552
==============================================================================
--- incubator/tuscany/java/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java (original)
+++ incubator/tuscany/java/sca/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java Wed Dec 13 01:11:07 2006
@@ -125,12 +125,16 @@
         if (identifier != null) {
             b.append(" [").append(identifier).append(']');
         }
+        return appendContextStack(b).toString();
+    }
+
+    protected StringBuilder appendContextStack(StringBuilder b) {
         if (contextStack != null) {
             b.append("\nContext stack trace: ");
             for (int i = contextStack.size() - 1; i >= 0; i--) {
                 b.append('[').append(contextStack.get(i)).append(']');
             }
         }
-        return b.toString();
+        return b;
     }
 }

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistry.java?view=diff&rev=486552&r1=486551&r2=486552
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistry.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistry.java Wed Dec 13 01:11:07 2006
@@ -23,9 +23,6 @@
 
 import org.osoa.sca.annotations.Service;
 
-import org.apache.tuscany.spi.annotation.Autowire;
-import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.component.SCAObject;
 import org.apache.tuscany.spi.host.ResourceHost;
 import org.apache.tuscany.spi.host.ResourceHostRegistry;
 import org.apache.tuscany.spi.host.ResourceResolutionException;
@@ -41,29 +38,39 @@
 @Service(interfaces = {ResourceHost.class, ResourceHostRegistry.class})
 public class DelegatingResourceHostRegistry implements ResourceHost, ResourceHostRegistry {
     private static final String SCA_PREFIX = "SCA://";
-    private static final String SCA_LOCALHOST_PREFIX = "SCA://localhost/";
     private Map<String, ResourceHost> resourceHosts = new HashMap<String, ResourceHost>();
-    private CompositeComponent parent;
+    private Map<Class<?>, Object> systemResources = new HashMap<Class<?>, Object>();
+    private Map<Key, Object> mappedSystemResources = new HashMap<Key, Object>();
 
-    /**
-     * Creates a new delegating registry.
-     *
-     * @param parent the composite to resolve SCA resources against
-     */
-    public DelegatingResourceHostRegistry(@Autowire CompositeComponent parent) {
-        this.parent = parent;
+    public DelegatingResourceHostRegistry() {
     }
 
-    public void register(String uri, ResourceHost host) {
+    public void registerResourceHost(String uri, ResourceHost host) {
         resourceHosts.put(uri, host);
     }
 
-    public void unregister(String uri) {
+    public void unregisterResourceHost(String uri) {
         resourceHosts.remove(uri);
     }
 
+    public void registerResource(Class<?> type, Object resource) {
+        systemResources.put(type, resource);
+    }
+
+    public void registerResource(Class<?> type, String name, Object resource) {
+        mappedSystemResources.put(new Key(type, name), resource);
+    }
+
+    public void unregisterResource(Class<?> type, String name) {
+        mappedSystemResources.remove(new Key(type, name));
+    }
+
+    public void unregisterResource(Class<?> type) {
+        systemResources.remove(type);
+    }
+
     public <T> T resolveResource(Class<T> type) throws ResourceResolutionException {
-        T instance = parent.resolveSystemExternalInstance(type);
+        T instance = type.cast(systemResources.get(type));
         if (instance == null) {
             for (ResourceHost host : resourceHosts.values()) {
                 instance = host.resolveResource(type);
@@ -73,30 +80,16 @@
             }
         }
         return instance;
-
     }
 
     public <T> T resolveResource(Class<T> type, String mappedName) throws ResourceResolutionException {
         if (mappedName.startsWith(SCA_PREFIX)) {
-            String name;
-            if (mappedName.startsWith(SCA_LOCALHOST_PREFIX)) {
-                name = mappedName.substring(SCA_LOCALHOST_PREFIX.length());
-            } else {
-                name = mappedName.substring(SCA_PREFIX.length());
-            }
-            // resolve against the composite
-            SCAObject child = parent.getSystemChild(name);
-            // only expose services
-            if (child instanceof org.apache.tuscany.spi.component.Service) {
-                return type.cast(child.getServiceInstance());
-            }
-            return null;
+            String name = mappedName.substring(SCA_PREFIX.length());
+            return type.cast(mappedSystemResources.get(new Key(type, name)));
         } else {
             int pos = mappedName.indexOf("://");
             if (pos == -1) {
-                ResourceResolutionException e = new ResourceResolutionException("Invalid resource URI");
-                e.setIdentifier(mappedName);
-                throw e;
+                return type.cast(mappedSystemResources.get(new Key(type, mappedName)));
             }
             String uri = mappedName.substring(0, pos + 3);
             ResourceHost host = resourceHosts.get(uri);
@@ -106,6 +99,46 @@
                 throw e;
             }
             return host.resolveResource(type, mappedName);
+        }
+    }
+
+    private class Key {
+        private Class<?> clazz;
+        private String name;
+
+        public Key(Class<?> clazz, String name) {
+            this.clazz = clazz;
+            this.name = name;
+        }
+
+        public Key(Class<?> clazz) {
+            this.clazz = clazz;
+        }
+
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+
+            Key key = (Key) o;
+
+            if (clazz != null ? !clazz.equals(key.clazz) : key.clazz != null) {
+                return false;
+            }
+            if (name != null ? !name.equals(key.name) : key.name != null) {
+                return false;
+            }
+            return true;
+        }
+
+        public int hashCode() {
+            int result;
+            result = clazz != null ? clazz.hashCode() : 0;
+            result = 31 * result + (name != null ? name.hashCode() : 0);
+            return result;
         }
     }
 }

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java?view=diff&rev=486552&r1=486551&r2=486552
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java Wed Dec 13 01:11:07 2006
@@ -18,9 +18,6 @@
  */
 package org.apache.tuscany.core.services.host;
 
-import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.component.SCAObject;
-import org.apache.tuscany.spi.component.Service;
 import org.apache.tuscany.spi.host.ResourceHost;
 import org.apache.tuscany.spi.host.ResourceResolutionException;
 
@@ -32,73 +29,39 @@
  */
 public class DelegatingResourceHostRegistryTestCase extends TestCase {
 
+    public void testResolveByType() throws Exception {
+        Object ret = new Object();
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResource(Object.class, ret);
+        assertEquals(ret, registry.resolveResource(Object.class));
+    }
+
     public void testResolveByUri() throws Exception {
-        CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class);
         ResourceHost host = EasyMock.createMock(ResourceHost.class);
         EasyMock.expect(host.resolveResource(String.class, "Foo://foo")).andReturn("result");
         EasyMock.replay(host);
-        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(parent);
-        registry.register("Foo://", host);
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResourceHost("Foo://", host);
         assertEquals("result", registry.resolveResource(String.class, "Foo://foo"));
         EasyMock.verify(host);
     }
 
     public void testResolveBySCAUri() throws Exception {
-        Service child = EasyMock.createMock(Service.class);
-        EasyMock.expect(child.getServiceInstance()).andReturn("result");
-        EasyMock.replay(child);
-        CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
-        EasyMock.expect(parent.getSystemChild("foo")).andReturn(child);
-        EasyMock.replay(parent);
-        ResourceHost host = EasyMock.createMock(ResourceHost.class);
-        EasyMock.replay(host);
-        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(parent);
-        registry.register("Foo://", host);
-        assertEquals("result", registry.resolveResource(String.class, "SCA://foo"));
-        EasyMock.verify(host);
-    }
-
-
-    /**
-     * Tests system components not exposed as services are not visible
-     */
-    public void testResolveNonService() throws Exception {
-        SCAObject child = EasyMock.createMock(SCAObject.class);
-        EasyMock.expect(child.getServiceInstance()).andReturn("result");
-        EasyMock.replay(child);
-        CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
-        EasyMock.expect(parent.getSystemChild("foo")).andReturn(child);
-        EasyMock.replay(parent);
         ResourceHost host = EasyMock.createMock(ResourceHost.class);
         EasyMock.replay(host);
-        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(parent);
-        registry.register("Foo://", host);
-        assertNull(registry.resolveResource(String.class, "SCA://foo"));
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResourceHost("Foo://", host);
+        Object ret = new Object();
+        registry.registerResource(Object.class, "foo", ret);
+        assertEquals(ret, registry.resolveResource(Object.class, "SCA://foo"));
         EasyMock.verify(host);
     }
 
-    public void testResolveBySCALocalHostUri() throws Exception {
-        Service child = EasyMock.createMock(Service.class);
-        EasyMock.expect(child.getServiceInstance()).andReturn("result");
-        EasyMock.replay(child);
-        CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
-        EasyMock.expect(parent.getSystemChild("foo")).andReturn(child);
-        EasyMock.replay(parent);
-        ResourceHost host = EasyMock.createMock(ResourceHost.class);
-        EasyMock.replay(host);
-        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(parent);
-        registry.register("Foo://", host);
-        assertEquals("result", registry.resolveResource(String.class, "SCA://localhost/foo"));
-        EasyMock.verify(host);
-    }
-
-
     public void testResolveByUriNotFound() throws Exception {
-        CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class);
         ResourceHost host = EasyMock.createMock(ResourceHost.class);
         EasyMock.replay(host);
-        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(parent);
-        registry.register("Foo://", host);
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResourceHost("Foo://", host);
         try {
             assertEquals("result", registry.resolveResource(String.class, "Bar://bar"));
             fail();
@@ -108,13 +71,12 @@
         EasyMock.verify(host);
     }
 
-    public void testUnregister() throws Exception {
-        CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class);
+    public void testUnregisterHost() throws Exception {
         ResourceHost host = EasyMock.createMock(ResourceHost.class);
         EasyMock.replay(host);
-        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(parent);
-        registry.register("Foo://", host);
-        registry.unregister("Foo://");
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResourceHost("Foo://", host);
+        registry.unregisterResourceHost("Foo://");
         try {
             registry.resolveResource(String.class, "Foo://foo");
             fail();
@@ -124,16 +86,60 @@
         EasyMock.verify(host);
     }
 
+    public void testUnregisterResource() throws Exception {
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResource(Object.class, new Object());
+        registry.unregisterResource(Object.class);
+        assertNull(registry.resolveResource(Object.class));
+    }
+
+    public void testUnregisterMappedResource() throws Exception {
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResource(Object.class, "foo", new Object());
+        registry.registerResource(Object.class, new Object());
+        registry.unregisterResource(Object.class);
+        assertNull(registry.resolveResource(Object.class));
+        assertNotNull(registry.resolveResource(Object.class, "foo"));
+        registry.unregisterResource(Object.class, "foo");
+        assertNull(registry.resolveResource(Object.class));
+    }
+
+    public void testReolvedByTypeToMappedResource() throws Exception {
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResource(Object.class, "foo", new Object());
+        assertNull(registry.resolveResource(Object.class));
+    }
+
     public void testDelegatingResolveResource() throws Exception {
-        CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
-        EasyMock.expect(parent.resolveSystemExternalInstance(String.class)).andReturn(null);
-        EasyMock.replay(parent);
-        ResourceHost host = EasyMock.createMock(ResourceHost.class);
-        EasyMock.expect(host.resolveResource(String.class)).andReturn("result");
-        EasyMock.replay(host);
-        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(parent);
-        registry.register("Foo://", host);
-        assertEquals("result", registry.resolveResource(String.class));
+        Object ret = new Object();
+        ResourceHost host = EasyMock.createMock(ResourceHost.class);
+        EasyMock.expect(host.resolveResource(Object.class)).andReturn(ret);
+        EasyMock.replay(host);
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResourceHost("Foo://", host);
+        assertEquals(ret, registry.resolveResource(Object.class));
+        EasyMock.verify(host);
+    }
+
+    public void testDelegatingResolveResourceByTypeandName() throws Exception {
+        Object ret = new Object();
+        ResourceHost host = EasyMock.createMock(ResourceHost.class);
+        EasyMock.expect(host.resolveResource(EasyMock.eq(Object.class), EasyMock.eq("Foo://bar"))).andReturn(ret);
+        EasyMock.replay(host);
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResourceHost("Foo://", host);
+        assertEquals(ret, registry.resolveResource(Object.class, "Foo://bar"));
+        EasyMock.verify(host);
+    }
+
+    public void testResolveLocalResourceFirst() throws Exception {
+        Object local = new Object();
+        ResourceHost host = EasyMock.createMock(ResourceHost.class);
+        EasyMock.replay(host);
+        DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+        registry.registerResourceHost("Foo://", host);
+        registry.registerResource(Object.class, local);
+        assertEquals(local, registry.resolveResource(Object.class));
         EasyMock.verify(host);
     }
 

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java?view=diff&rev=486552&r1=486551&r2=486552
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java (original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java Wed Dec 13 01:11:07 2006
@@ -19,7 +19,7 @@
 package org.apache.tuscany.spi.host;
 
 /**
- * Implementations manage a registry of resource hosts in the runtime
+ * Implementations manage a registry of resources and resource hosts in the runtime
  *
  * @version $Rev$ $Date$
  */
@@ -30,10 +30,43 @@
      * @param uri  the uri prefix the host resolves resources for
      * @param host the resource host
      */
-    void register(String uri, ResourceHost host);
+    void registerResourceHost(String uri, ResourceHost host);
 
     /**
-     * Removes a host registered for the given uri prefix
+     * Removes a resource host registered for the given uri prefix
      */
-    void unregister(String uri);
+    void unregisterResourceHost(String uri);
+
+    /**
+     * Register a resource by type
+     *
+     * @param type     the type of the resource
+     * @param resource the resource
+     */
+    void registerResource(Class<?> type, Object resource);
+
+    /**
+     * Register a resource by type and name
+     *
+     * @param type     the type of the resource
+     * @param name     the mapped resource name
+     * @param resource the resource
+     */
+    void registerResource(Class<?> type, String name, Object resource);
+
+    /**
+     * Unregister a resource
+     *
+     * @param type the type the resource was registered with
+     * @param name the mapped name the resource was registered with
+     */
+    void unregisterResource(Class<?> type, String name);
+
+    /**
+     * Unregister a resource
+     *
+     * @param type the type the resource was registered with
+     */
+    void unregisterResource(Class<?> type);
+
 }

Modified: incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/PersistenceUnitTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/PersistenceUnitTestCase.java?view=diff&rev=486552&r1=486551&r2=486552
==============================================================================
--- incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/PersistenceUnitTestCase.java (original)
+++ incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/PersistenceUnitTestCase.java Wed Dec 13 01:11:07 2006
@@ -20,6 +20,7 @@
         
         JavaAtomicComponent cmp = (JavaAtomicComponent)component.getChild("TestService1");
         TestService1 testService1 = (TestService1) cmp.getServiceInstance();
+//        testService1.testMethod();
     }
 
     protected void tearDown() throws Exception {

Modified: incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/TestService1.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/TestService1.java?view=diff&rev=486552&r1=486551&r2=486552
==============================================================================
--- incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/TestService1.java (original)
+++ incubator/tuscany/java/sca/services/persistence/common/src/test/java/org/apache/tuscany/service/persistence/common/TestService1.java Wed Dec 13 01:11:07 2006
@@ -5,11 +5,13 @@
 import javax.persistence.PersistenceUnit;
 import javax.transaction.TransactionManager;
 
+import org.osoa.sca.annotations.Resource;
+
 import org.apache.tuscany.spi.annotation.Autowire;
 
 public class TestService1 {
     
-    @Autowire 
+    @Resource
     protected TransactionManager tx;
     
     @PersistenceUnit(unitName="test")

Modified: incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/main/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/main/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerService.java?view=diff&rev=486552&r1=486551&r2=486552
==============================================================================
--- incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/main/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerService.java (original)
+++ incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/main/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerService.java Wed Dec 13 01:11:07 2006
@@ -35,6 +35,7 @@
 import org.osoa.sca.annotations.Service;
 
 import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.host.ResourceHostRegistry;
 
 import org.apache.geronimo.transaction.ExtendedTransactionManager;
 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
@@ -50,11 +51,14 @@
  */
 @Service(interfaces = {TransactionManager.class, ExtendedTransactionManager.class})
 public class GeronimoTransactionManagerService implements TransactionManager, ExtendedTransactionManager {
+    private ResourceHostRegistry hostRegistry;
     private ExtendedTransactionManager transactionManager;
     private GeronimoTransactionLogService logService;
     private int timeout = 250;
 
-    public GeronimoTransactionManagerService(@Autowire GeronimoTransactionLogService logService) {
+    public GeronimoTransactionManagerService(@Autowire ResourceHostRegistry hostRegistry,
+                                             @Autowire GeronimoTransactionLogService logService) {
+        this.hostRegistry = hostRegistry;
         this.logService = logService;
     }
 
@@ -75,16 +79,17 @@
         this.timeout = timeout;
     }
 
-    @Init
+    @Init(eager = true)
     public void init() throws XAException {
         XidFactoryImpl factory = new XidFactoryImpl();
         // FIXME fix passing in null ResourceManagers for recovery
         transactionManager = new TransactionManagerImpl(timeout, factory, logService.getLog(), null);
+        hostRegistry.registerResource(TransactionManager.class, this);
     }
 
-
     @Destroy
     public void destroy() throws TransactionServiceShutdownException {
+        hostRegistry.unregisterResource(TransactionManager.class);
     }
 
     public void begin() throws NotSupportedException, SystemException {
@@ -105,7 +110,7 @@
     }
 
     public XidImporter getXidImporter() {
-        return (XidImporter)transactionManager;
+        return (XidImporter) transactionManager;
     }
 
     public int getStatus() throws SystemException {

Added: incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTMServiceHostRegistryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTMServiceHostRegistryTestCase.java?view=auto&rev=486552
==============================================================================
--- incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTMServiceHostRegistryTestCase.java (added)
+++ incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTMServiceHostRegistryTestCase.java Wed Dec 13 01:11:07 2006
@@ -0,0 +1,65 @@
+/*
+ * 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.tuscany.transaction.geronimo.jta;
+
+import java.io.File;
+import javax.transaction.TransactionManager;
+
+import org.apache.tuscany.spi.host.ResourceHostRegistry;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.transaction.manager.XidFactoryImpl;
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.transaction.geronimo.TestUtils;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeronimoTMServiceHostRegistryTestCase extends TestCase {
+    private GeronimoTransactionManagerService service;
+    private ResourceHostRegistry registry;
+
+    public void testRegisterUnregister() throws Exception {
+        service.init();
+        service.destroy();
+        EasyMock.verify(registry);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        TestUtils.cleanupLog();
+        registry = EasyMock.createMock(ResourceHostRegistry.class);
+        registry.registerResource(EasyMock.eq(TransactionManager.class), EasyMock.isA(TransactionManager.class));
+        registry.unregisterResource(EasyMock.eq(TransactionManager.class));
+        EasyMock.replay(registry);
+        RuntimeInfo info = EasyMock.createMock(RuntimeInfo.class);
+        EasyMock.expect(info.getInstallDirectory()).andReturn(new File("."));
+        EasyMock.replay(info);
+        GeronimoTransactionLogService logService = new GeronimoTransactionLogService(info, new XidFactoryImpl());
+        service = new GeronimoTransactionManagerService(registry, logService);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        TestUtils.cleanupLog();
+    }
+
+
+}

Propchange: incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTMServiceHostRegistryTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTMServiceHostRegistryTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerServiceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerServiceTestCase.java?view=diff&rev=486552&r1=486551&r2=486552
==============================================================================
--- incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerServiceTestCase.java (original)
+++ incubator/tuscany/java/sca/services/transaction/transaction.geronimo/src/test/java/org/apache/tuscany/transaction/geronimo/jta/GeronimoTransactionManagerServiceTestCase.java Wed Dec 13 01:11:07 2006
@@ -24,6 +24,8 @@
 import javax.transaction.Synchronization;
 import javax.transaction.Transaction;
 
+import org.apache.tuscany.spi.host.ResourceHostRegistry;
+
 import junit.framework.TestCase;
 import org.apache.geronimo.transaction.manager.XidFactoryImpl;
 import org.apache.tuscany.host.RuntimeInfo;
@@ -114,11 +116,13 @@
     protected void setUp() throws Exception {
         super.setUp();
         TestUtils.cleanupLog();
+        ResourceHostRegistry registry = EasyMock.createNiceMock(ResourceHostRegistry.class);
+        EasyMock.replay(registry);
         RuntimeInfo info = EasyMock.createMock(RuntimeInfo.class);
         EasyMock.expect(info.getInstallDirectory()).andReturn(new File("."));
         EasyMock.replay(info);
         GeronimoTransactionLogService logService = new GeronimoTransactionLogService(info, new XidFactoryImpl());
-        service = new GeronimoTransactionManagerService(logService);
+        service = new GeronimoTransactionManagerService(registry, logService);
         service.init();
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org