You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2007/02/11 01:43:28 UTC

svn commit: r505813 - in /incubator/tuscany/java/sca/kernel/core/src: main/java/org/apache/tuscany/core/component/scope/ main/java/org/apache/tuscany/core/implementation/ test/java/org/apache/tuscany/core/component/scope/ test/java/org/apache/tuscany/c...

Author: jboynes
Date: Sat Feb 10 16:43:27 2007
New Revision: 505813

URL: http://svn.apache.org/viewvc?view=rev&rev=505813
Log:
refactor InstanceWrapperImpl to separate wrapping from lifecycle control
add strawman for generated factory
add strawman for physical component

Added:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java   (with props)
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java   (with props)
Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperImpl.java
    incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java?view=auto&rev=505813
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java Sat Feb 10 16:43:27 2007
@@ -0,0 +1,52 @@
+/*
+ * 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.core.component.scope;
+
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InstanceWrapperBase<T> implements InstanceWrapper<T> {
+    protected final T instance;
+    private boolean started;
+
+    public InstanceWrapperBase(T instance) {
+        assert instance != null;
+        this.instance = instance;
+    }
+
+    public T getInstance() {
+        assert started;
+        return instance;
+    }
+
+    public boolean isStarted() {
+        return started;
+    }
+
+    public void start() throws TargetInitializationException {
+        started = true;
+    }
+
+    public void stop() throws TargetDestructionException {
+        started = false;
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperImpl.java?view=diff&rev=505813&r1=505812&r2=505813
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperImpl.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperImpl.java Sat Feb 10 16:43:27 2007
@@ -27,37 +27,22 @@
  *
  * @version $$Rev$$ $$Date$$
  */
-public class InstanceWrapperImpl implements InstanceWrapper {
-    private Object instance;
+public class InstanceWrapperImpl extends InstanceWrapperBase<Object> {
     private AtomicComponent component;
-    private boolean started;
 
     public InstanceWrapperImpl(AtomicComponent component, Object instance) {
+        super(instance);
         assert component != null;
-        assert instance != null;
         this.component = component;
-        this.instance = instance;
-    }
-
-    public boolean isStarted() {
-        return started;
-    }
-
-    public Object getInstance() {
-        if (!started) {
-            throw new IllegalStateException("Instance not started");
-        }
-        return instance;
     }
 
     public void start() throws TargetInitializationException {
         component.init(instance);
-        started = true;
+        super.start();
     }
 
     public void stop() throws TargetDestructionException {
+        super.stop();
         component.destroy(instance);
-        started = false;
     }
-
 }

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java?view=auto&rev=505813
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java Sat Feb 10 16:43:27 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.core.implementation;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.extension.AbstractComponentExtension;
+import org.apache.tuscany.core.component.scope.InstanceWrapper;
+import org.apache.tuscany.core.component.InstanceFactory;
+
+/**
+ * Base class for implementations of physical components.
+ *
+ * @version $Rev$ $Date$
+ * @param <T> the type of the physical instance
+ */
+public abstract class PhysicalComponent<T> extends AbstractComponentExtension {
+    private final InstanceFactory<T> factory;
+
+    /**
+     * Constructor specifying the component id.
+     *
+     * @param id the component id
+     * @param factory a factory for physical instances
+     */
+    protected PhysicalComponent(URI id, InstanceFactory<T> factory) {
+        super(id, null);
+        this.factory = factory;
+    }
+
+    public InstanceWrapper<T> createInstance() {
+        return factory.newInstance();
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java?view=auto&rev=505813
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java Sat Feb 10 16:43:27 2007
@@ -0,0 +1,66 @@
+/*
+ * 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.core.component.scope;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.component.TargetInitializationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InstanceWrapperBaseTestClass extends TestCase {
+    private static final Object instance = new Object();
+    private InstanceWrapperBase<Object> wrapper;
+
+    public void testLifecycle() throws Exception {
+        assertFalse(wrapper.isStarted());
+        try {
+            wrapper.getInstance();
+            fail();
+        } catch (AssertionError e) {
+            // expected
+        }
+        wrapper.start();
+        assertTrue(wrapper.isStarted());
+        assertSame(instance, wrapper.getInstance());
+        wrapper.stop();
+        assertFalse(wrapper.isStarted());
+        try {
+            wrapper.getInstance();
+            fail();
+        } catch (AssertionError e) {
+            // expected
+        }
+    }
+
+    public void testNullCheck() {
+        try {
+            new InstanceWrapperBase<Object>(null);
+            fail();
+        } catch (AssertionError e) {
+            // expected
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        wrapper = new InstanceWrapperBase<Object>(instance);
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestClass.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java?view=diff&rev=505813&r1=505812&r2=505813
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java Sat Feb 10 16:43:27 2007
@@ -47,7 +47,7 @@
         try {
             wrapper.getInstance();
             fail();
-        } catch (IllegalStateException e) {
+        } catch (AssertionError e) {
             // expected
         }
     }

Added: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java?view=auto&rev=505813
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java (added)
+++ incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java Sat Feb 10 16:43:27 2007
@@ -0,0 +1,80 @@
+/*
+ * 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.core.implementation;
+
+import junit.framework.TestCase;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+
+import org.apache.tuscany.core.component.InstanceFactory;
+import org.apache.tuscany.core.component.scope.InstanceWrapper;
+import org.apache.tuscany.core.component.scope.InstanceWrapperBase;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PhysicalComponentTestCase extends TestCase {
+    public void testSomething() {
+
+    }
+    
+    /**
+     * This is the class supplied by the user.
+     */
+    public static class UserImplementation {
+        @Init
+        void init() {
+        }
+
+        @Destroy
+        void destroy() {
+        }
+    }
+
+    /**
+     * This is the generated wrapper class.
+     */
+    public static class UserWrapper extends InstanceWrapperBase<UserImplementation> {
+        public UserWrapper(UserImplementation instance) {
+            super(instance);
+        }
+
+        public void start() throws TargetInitializationException {
+            instance.init();
+            super.start();
+        }
+
+        public void stop() throws TargetDestructionException {
+            super.stop();
+            instance.destroy();
+        }
+    }
+
+    /**
+     * This is the generated factory class.
+     */
+    public static class UserFactory implements InstanceFactory<UserImplementation> {
+        public InstanceWrapper<UserImplementation> newInstance() {
+            UserImplementation instance = new UserImplementation();
+            return new UserWrapper(instance);
+        }
+    }
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



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