You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ad...@apache.org on 2008/03/21 04:42:46 UTC

svn commit: r639535 [5/7] - in /incubator/tuscany/sandbox/mobile-android: core-android/ core-android/src/ core-android/src/main/ core-android/src/main/java/ core-android/src/main/java/org/ core-android/src/main/java/org/apache/ core-android/src/main/ja...

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,163 @@
+/*
+ * 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.sca.core.invocation;
+
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.work.WorkScheduler;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Adds non-blocking behavior to an invocation chain
+ *
+ * @version $$Rev: 639271 $$ $$Date: 2008-03-20 05:54:38 -0700 (Thu, 20 Mar 2008) $$
+ */
+public class NonBlockingInterceptor implements Interceptor {
+
+    private static final Message RESPONSE = new ImmutableMessage();
+
+    private WorkScheduler workScheduler;
+    private Invoker next;
+
+    public NonBlockingInterceptor(WorkScheduler workScheduler) {
+        this.workScheduler = workScheduler;
+    }
+
+    public NonBlockingInterceptor(WorkScheduler workScheduler, Interceptor next) {
+        this.workScheduler = workScheduler;
+        this.next = next;
+    }
+
+    /**
+     * Sets desired workScheduler to NonBlockingInterceptor. This is a useful function for the extension framework
+     * to set desired workmanager on the InvocationChain, other than default workmanager which is set per Tuscany runtime.
+     * Using this function, extension framework can set desired workmanager on InvocationChain during post wire processing.
+     * @param workScheduler workScheduler which contains workmanager
+     */
+    public void setWorkScheduler(WorkScheduler workScheduler){
+        this.workScheduler = workScheduler;
+    }
+
+    public Message invoke(final Message msg) {
+        // Schedule the invocation of the next interceptor in a new Work instance
+        try {
+            workScheduler.scheduleWork(new Runnable() {
+                public void run() {
+                    Message context = ThreadMessageContext.setMessageContext(msg);
+                    try {
+                        next.invoke(msg);
+                    } finally {
+                        ThreadMessageContext.setMessageContext(context);
+                    }
+                }
+            });
+        } catch (Exception e) {
+            throw new ServiceRuntimeException(e);
+        }
+        return RESPONSE;
+    }
+
+    public Invoker getNext() {
+        return next;
+    }
+
+    public void setNext(Invoker next) {
+        this.next = next;
+    }
+
+    /**
+     * A dummy message passed back on an invocation
+     */
+    private static class ImmutableMessage implements Message {
+
+        @SuppressWarnings("unchecked")
+        public Object getBody() {
+            return null;
+        }
+
+        public void setBody(Object body) {
+            if (body != null) {
+                throw new UnsupportedOperationException();
+            }
+        }
+
+        public void setCallbackWires(LinkedList<RuntimeWire> wires) {
+
+        }
+
+        public Object getMessageID() {
+            return null;
+        }
+
+        public void setMessageID(Object messageId) {
+            throw new UnsupportedOperationException();
+        }
+
+        public boolean isFault() {
+            return false;
+        }
+
+        public void setFaultBody(Object fault) {
+            throw new UnsupportedOperationException();
+        }
+
+        public EndpointReference getFrom() {
+            return null;
+        }
+
+        public EndpointReference getTo() {
+            return null;
+        }
+
+        public void setFrom(EndpointReference from) {
+            throw new UnsupportedOperationException();
+        }
+
+        public void setTo(EndpointReference to) {
+            throw new UnsupportedOperationException();
+        }
+
+        public Operation getOperation() {
+            return null;
+        }
+
+        public void setOperation(Operation op) {
+            throw new UnsupportedOperationException();
+        }
+
+        /**
+         * @see org.apache.tuscany.sca.invocation.Message#getReplyTo()
+         */
+        public EndpointReference getReplyTo() {
+            return null;
+        }
+
+        public Map<String, Object> getQoSContext() {
+            return null;
+        }
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,247 @@
+/*
+ * 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.sca.core.invocation;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev: 632642 $ $Date: 2008-03-01 10:16:44 -0800 (Sat, 01 Mar 2008) $
+ */
+public class PhaseManager {
+    private static final Logger log = Logger.getLogger(PhaseManager.class.getName());
+
+    public static final String STAGE_REFERENCE = "reference";
+    public static final String STAGE_SERVICE = "service";
+    public static final String STAGE_IMPLEMENTATION = "implementation";
+    private final static String[] SYSTEM_REFERENCE_PHASES =
+        {Phase.REFERENCE, Phase.REFERENCE_INTERFACE, Phase.REFERENCE_POLICY, Phase.REFERENCE_BINDING};
+
+    private final static String[] SYSTEM_SERVICE_PHASES =
+        {Phase.SERVICE_BINDING, Phase.SERVICE_POLICY, Phase.SERVICE_INTERFACE, Phase.SERVICE};
+
+    private final static String[] SYSTEM_IMPLEMENTATION_PHASES = {Phase.IMPLEMENTATION_POLICY, Phase.IMPLEMENTATION};
+
+    private String pattern = Phase.class.getName();
+    private Map<String, Stage> stages;
+    private List<String> phases;
+
+    public class Stage {
+        private String name;
+        private PhaseSorter<String> sorter = new PhaseSorter<String>();
+        private Set<String> firstSet = new HashSet<String>();
+        private Set<String> lastSet = new HashSet<String>();
+        private List<String> phases = new ArrayList<String>();
+
+        public Stage(String name) {
+            super();
+            this.name = name;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public PhaseSorter<String> getSorter() {
+            return sorter;
+        }
+
+        public Set<String> getFirstSet() {
+            return firstSet;
+        }
+
+        public Set<String> getLastSet() {
+            return lastSet;
+        }
+
+        public List<String> getPhases() {
+            return phases;
+        }
+
+        public String toString() {
+            return name + phases;
+        }
+    }
+
+    // For unit test purpose
+    PhaseManager(String pattern) {
+        super();
+        this.pattern = pattern;
+    }
+
+    public PhaseManager() {
+    }
+
+    private List<String> getPhases(String stage) {
+        Stage s = getStages().get(stage);
+        return s == null ? null : s.getPhases();
+    }
+
+    public List<String> getReferencePhases() {
+        return getPhases(STAGE_REFERENCE);
+    }
+
+    public List<String> getServicePhases() {
+        return getPhases(STAGE_SERVICE);
+    }
+
+    public List<String> getImplementationPhases() {
+        return getPhases(STAGE_IMPLEMENTATION);
+    }
+
+    public List<String> getAllPhases() {
+        if (phases == null) {
+            phases = new ArrayList<String>();
+            phases.addAll(getReferencePhases());
+            phases.addAll(getServicePhases());
+            phases.addAll(getImplementationPhases());
+        }
+        return phases;
+    }
+
+    public synchronized Map<String, Stage> getStages() {
+        if (stages != null) {
+            return stages;
+        }
+        init();
+
+        Set<ServiceDeclaration> services;
+        try {
+            services = ServiceDiscovery.getInstance().getServiceDeclarations(pattern);
+        } catch (IOException e) {
+            throw new ServiceRuntimeException(e);
+        }
+
+        for (ServiceDeclaration d : services) {
+            if (log.isLoggable(Level.FINE)) {
+                log.fine(d.getResource() + ": " + d.getAttributes());
+            }
+            String name = d.getAttributes().get("name");
+            if (name == null) {
+                throw new ServiceRuntimeException("Required attribute 'name' is missing.");
+            }
+            String stageName = d.getAttributes().get("stage");
+            if (stageName == null) {
+                throw new ServiceRuntimeException("Required attribute 'stage' is missing.");
+            }
+            Stage stage = stages.get(stageName);
+            if (stage == null) {
+                throw new ServiceRuntimeException("Invalid stage: " + stage);
+            }
+            PhaseSorter<String> graph = stage.getSorter();
+            Set<String> firstSet = stage.getFirstSet(), lastSet = stage.getLastSet();
+
+            String before = d.getAttributes().get("before");
+            String after = d.getAttributes().get("after");
+            if (before != null) {
+                StringTokenizer tokenizer = new StringTokenizer(before);
+                while (tokenizer.hasMoreTokens()) {
+                    String p = tokenizer.nextToken();
+                    if (!"*".equals(p)) {
+                        graph.addEdge(name, p);
+                    } else {
+                        firstSet.add(name);
+                    }
+                }
+            }
+            if (after != null) {
+                StringTokenizer tokenizer = new StringTokenizer(after);
+                while (tokenizer.hasMoreTokens()) {
+                    String p = tokenizer.nextToken();
+                    if (!"*".equals(p)) {
+                        graph.addEdge(p, name);
+                    } else {
+                        lastSet.add(name);
+                    }
+                }
+            }
+            graph.addVertext(name);
+            if(firstSet.size()>1) {
+                log.warning("More than one phases are declared to be first: "+firstSet);
+            }
+            for (String s : firstSet) {
+                for (String v : new HashSet<String>(graph.getVertices().keySet())) {
+                    if (!firstSet.contains(v)) {
+                        graph.addEdge(s, v);
+                    }
+                }
+            }
+            if(lastSet.size()>1) {
+                log.warning("More than one phases are declared to be the last: "+lastSet);
+            }
+            for (String s : lastSet) {
+                for (String v : new HashSet<String>(graph.getVertices().keySet())) {
+                    if (!lastSet.contains(v)) {
+                        graph.addEdge(v, s);
+                    }
+                }
+            }
+
+        }
+
+        for (Stage s : stages.values()) {
+            List<String> phases = s.getSorter().topologicalSort(false);
+            s.getPhases().clear();
+            s.getPhases().addAll(phases);
+        }
+        if (log.isLoggable(Level.FINE)) {
+            log.fine("Stages: " + stages);
+        }
+        return stages;
+    }
+
+    private void init() {
+        stages = new HashMap<String, Stage>();
+
+        Stage referenceStage = new Stage(STAGE_REFERENCE);
+        for (int i = 1; i < SYSTEM_REFERENCE_PHASES.length; i++) {
+            referenceStage.getSorter().addEdge(SYSTEM_REFERENCE_PHASES[i - 1], SYSTEM_REFERENCE_PHASES[i]);
+        }
+        referenceStage.getLastSet().add(Phase.REFERENCE_BINDING);
+        stages.put(referenceStage.getName(), referenceStage);
+
+        Stage serviceStage = new Stage(STAGE_SERVICE);
+        for (int i = 1; i < SYSTEM_SERVICE_PHASES.length; i++) {
+            serviceStage.getSorter().addEdge(SYSTEM_SERVICE_PHASES[i - 1], SYSTEM_SERVICE_PHASES[i]);
+        }
+        stages.put(serviceStage.getName(), serviceStage);
+
+        Stage implementationStage = new Stage(STAGE_IMPLEMENTATION);
+        for (int i = 1; i < SYSTEM_IMPLEMENTATION_PHASES.length; i++) {
+            implementationStage.getSorter().addEdge(SYSTEM_IMPLEMENTATION_PHASES[i - 1],
+                                                    SYSTEM_IMPLEMENTATION_PHASES[i]);
+        }
+        implementationStage.getLastSet().add(Phase.IMPLEMENTATION);
+        stages.put(implementationStage.getName(), implementationStage);
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,234 @@
+/*
+ * 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.sca.core.invocation;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Directed, weighted graph
+ * 
+ * @param <V> The type of vertex object
+ * @param <E> The type of edge object
+ */
+public class PhaseSorter<V> implements Cloneable {
+    private final Map<V, Vertex> vertices = new HashMap<V, Vertex>();
+
+    /**
+     * Vertex of a graph
+     */
+    public final class Vertex {
+        private V value;
+
+        // TODO: Do we want to support multiple edges for a vertex pair? If so,
+        // we should use a List instead of Map
+        private Map<Vertex, Edge> outEdges = new HashMap<Vertex, Edge>();
+        private Map<Vertex, Edge> inEdges = new HashMap<Vertex, Edge>();
+
+        private Vertex(V value) {
+            this.value = value;
+        }
+
+        @Override
+        public String toString() {
+            return "(" + value + ")";
+        }
+
+        public V getValue() {
+            return value;
+        }
+
+        public Map<Vertex, Edge> getOutEdges() {
+            return outEdges;
+        }
+
+        public Map<Vertex, Edge> getInEdges() {
+            return inEdges;
+        }
+
+    }
+
+    /**
+     * An Edge connects two vertices in one direction
+     */
+    public final class Edge {
+        private Vertex sourceVertex;
+
+        private Vertex targetVertex;
+
+        public Edge(Vertex source, Vertex target) {
+            this.sourceVertex = source;
+            this.targetVertex = target;
+        }
+
+        @Override
+        public String toString() {
+            return sourceVertex + "->" + targetVertex;
+        }
+
+        public Vertex getTargetVertex() {
+            return targetVertex;
+        }
+
+        public void setTargetVertex(Vertex vertex) {
+            this.targetVertex = vertex;
+        }
+
+        public Vertex getSourceVertex() {
+            return sourceVertex;
+        }
+
+        public void setSourceVertex(Vertex sourceVertex) {
+            this.sourceVertex = sourceVertex;
+        }
+    }
+
+    public void addEdge(V source, V target) {
+        Vertex s = getVertex(source);
+        if (s == null) {
+            s = new Vertex(source);
+            vertices.put(source, s);
+        }
+        Vertex t = getVertex(target);
+        if (t == null) {
+            t = new Vertex(target);
+            vertices.put(target, t);
+        }
+        Edge edge = new Edge(s, t);
+        s.outEdges.put(t, edge);
+        t.inEdges.put(s, edge);
+    }
+
+    public void addVertext(V source) {
+        Vertex s = getVertex(source);
+        if (s == null) {
+            s = new Vertex(source);
+            vertices.put(source, s);
+        }
+    }
+
+    public Vertex getVertex(V source) {
+        Vertex s = vertices.get(source);
+        return s;
+    }
+
+    public boolean removeEdge(V source, V target) {
+        Vertex s = getVertex(source);
+        if (s == null) {
+            return false;
+        }
+
+        Vertex t = getVertex(target);
+        if (t == null) {
+            return false;
+        }
+
+        return s.outEdges.remove(t) != null && t.inEdges.remove(s) != null;
+
+    }
+
+    public void removeEdge(Edge edge) {
+        edge.sourceVertex.outEdges.remove(edge.targetVertex);
+        edge.targetVertex.inEdges.remove(edge.sourceVertex);
+    }
+
+    public void removeVertex(Vertex vertex) {
+        vertices.remove(vertex.getValue());
+        for (Edge e : new ArrayList<Edge>(vertex.outEdges.values())) {
+            removeEdge(e);
+        }
+        for (Edge e : new ArrayList<Edge>(vertex.inEdges.values())) {
+            removeEdge(e);
+        }
+    }
+
+    public Edge getEdge(Vertex source, Vertex target) {
+        return source.outEdges.get(target);
+    }
+
+    public Edge getEdge(V source, V target) {
+        Vertex sv = getVertex(source);
+        if (sv == null) {
+            return null;
+        }
+        Vertex tv = getVertex(target);
+        if (tv == null) {
+            return null;
+        }
+        return getEdge(getVertex(source), getVertex(target));
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        for (Vertex v : vertices.values()) {
+            sb.append(v.outEdges.values()).append("\n");
+        }
+        return sb.toString();
+    }
+
+    public Map<V, Vertex> getVertices() {
+        return vertices;
+    }
+
+    public void addGraph(PhaseSorter<V> otherGraph) {
+        for (Vertex v : otherGraph.vertices.values()) {
+            for (Edge e : v.outEdges.values()) {
+                addEdge(e.sourceVertex.value, e.targetVertex.value);
+            }
+        }
+    }
+
+    private Vertex getFirst() {
+        for (Vertex v : vertices.values()) {
+            if (v.inEdges.isEmpty()) {
+                return v;
+            }
+        }
+        if (!vertices.isEmpty()) {
+            throw new IllegalArgumentException("Circular ordering has been detected: " + toString());
+        } else {
+            return null;
+        }
+    }
+
+    public List<V> topologicalSort(boolean readOnly) {
+        PhaseSorter<V> graph = (!readOnly) ? this : (PhaseSorter<V>)clone();
+        List<V> list = new ArrayList<V>();
+        while (true) {
+            Vertex v = graph.getFirst();
+            if (v == null) {
+                break;
+            }
+            list.add(v.getValue());
+            graph.removeVertex(v);
+        }
+
+        return list;
+    }
+
+    @Override
+    public Object clone() {
+        PhaseSorter<V> copy = new PhaseSorter<V>();
+        copy.addGraph(this);
+        return copy;
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,48 @@
+/*
+ * 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.sca.core.invocation;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+
+
+/**
+ * Denotes an error creating a proxy
+ *
+ * @version $$Rev: 567617 $$ $$Date: 2007-08-20 02:29:15 -0700 (Mon, 20 Aug 2007) $$
+ */
+public class ProxyCreationException extends ObjectCreationException {
+    private static final long serialVersionUID = 8002454344828513781L;
+
+    public ProxyCreationException() {
+        super();
+    }
+
+    public ProxyCreationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ProxyCreationException(String message) {
+        super(message);
+    }
+
+    public ProxyCreationException(Throwable cause) {
+        super(cause);
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,87 @@
+/*
+ * 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.sca.core.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+
+/**
+ * Creates proxies that implement Java interfaces and invocation handlers for fronting wires
+ *
+ * @version $$Rev: 639271 $$ $$Date: 2008-03-20 05:54:38 -0700 (Thu, 20 Mar 2008) $$
+ */
+
+public interface ProxyFactory {
+
+    /**
+     * Creates a Java proxy for the given wire
+     *
+     * @param interfaze the interface the proxy implements
+     * @param wire      the wire to proxy
+     * @return the proxy
+     * @throws ProxyCreationException
+     */
+    <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws ProxyCreationException;
+
+    /**
+     * Creates a Java proxy for the given CallableReference
+     *
+     * @param callableReference The CallableReference
+     * @return the proxy
+     * @throws ProxyCreationException
+     */
+    <T> T createProxy(CallableReference<T> callableReference) throws ProxyCreationException;
+
+    /**
+     * Creates a Java proxy for the service contract callback
+     *
+     * @param interfaze the interface the proxy should implement
+     * @return the proxy
+     * @throws ProxyCreationException
+     */
+    <T> T createCallbackProxy(Class<T> interfaze, List<RuntimeWire> wires) throws ProxyCreationException;
+
+    /**
+     * Creates a Java proxy for the given callback reference
+     *
+     * @param callableReference The CallableReference
+     * @return the proxy
+     * @throws ProxyCreationException
+     */
+    <T> T createCallbackProxy(CallbackReferenceImpl<T> callbackReference) throws ProxyCreationException;
+
+    /**
+     * Cast a proxy to a CallableReference.
+     *
+     * @param target a proxy generated by this implementation
+     * @return a CallableReference (or subclass) equivalent to this proxy
+     * @throws IllegalArgumentException if the object supplied is not a proxy
+     */
+    <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException;
+    
+    /**
+     * Test if a given class is a generated proxy class by this factory
+     * @param clazz A java class or interface
+     * @return true if the class is a generated proxy class by this factory 
+     */
+    boolean isProxyClass(Class<?> clazz);
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.sca.core.invocation;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+
+/**
+ * The extension point to plug in proxy factories
+ * @version $Rev: 561673 $ $Date: 2007-07-31 23:25:09 -0700 (Tue, 31 Jul 2007) $
+ */
+public interface ProxyFactoryExtensionPoint extends ProxyFactory {
+    /**
+     * Get the proxy factory for java interfaces
+     * @return
+     */
+    ProxyFactory getInterfaceProxyFactory();
+
+    /**
+     * Get the proxy factory for java classes
+     * @return
+     */
+    ProxyFactory getClassProxyFactory();
+
+    /**
+     * Set the proxy factory for java interfaces
+     * @param factory
+     */
+    void setInterfaceProxyFactory(ProxyFactory factory);
+
+    /**
+     * Set the proxy factory for java classes
+     * @param factory
+     */
+    void setClassProxyFactory(ProxyFactory factory);
+    
+    /**
+     * @return the interfaceContractMapper
+     */
+    InterfaceContractMapper getInterfaceContractMapper();
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,245 @@
+/*
+ * 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.sca.core.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.conversation.ConversationState;
+import org.apache.tuscany.sca.core.conversation.ExtendedConversation;
+import org.apache.tuscany.sca.core.scope.Scope;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.core.scope.TargetDestructionException;
+import org.apache.tuscany.sca.core.scope.TargetResolutionException;
+import org.apache.tuscany.sca.interfacedef.ConversationSequence;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ConversationEndedException;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev: 638875 $ $Date: 2008-03-19 08:32:44 -0700 (Wed, 19 Mar 2008) $
+ */
+public class RuntimeWireInvoker {
+    protected ConversationManager conversationManager;
+    protected boolean conversational;
+    protected ExtendedConversation conversation;
+    protected MessageFactory messageFactory;
+    protected Object conversationID;
+    protected Object callbackID;
+    protected Object callbackObject;
+    protected RuntimeWire wire;
+
+    public RuntimeWireInvoker(MessageFactory messageFactory, ConversationManager conversationManager, RuntimeWire wire) {
+        this.messageFactory = messageFactory;
+        this.wire = wire;
+        this.conversationManager = conversationManager;
+        init(wire);
+    }
+
+    protected void init(RuntimeWire wire) {
+        if (wire != null) {
+            ReferenceParameters parameters = wire.getSource().getReferenceParameters();
+            this.callbackID = parameters.getCallbackID();
+            this.callbackObject = parameters.getCallbackReference();
+            this.conversationID = parameters.getConversationID();
+            InterfaceContract contract = wire.getSource().getInterfaceContract();
+            this.conversational = contract.getInterface().isConversational();
+        }
+    }
+
+    public Object invoke(Operation operation, Message msg) throws InvocationTargetException {
+        return invoke(wire, operation, msg);
+    }
+
+    public Object invoke(RuntimeWire wire, Operation operation, Message msg) throws InvocationTargetException {
+        RuntimeWire runtimeWire = wire == null ? this.wire : wire;
+        InvocationChain chain = runtimeWire.getInvocationChain(operation);
+        return invoke(chain, msg, runtimeWire);
+    }
+
+    protected Object invoke(InvocationChain chain, Message msg, RuntimeWire wire) throws InvocationTargetException {
+        EndpointReference from = msg.getFrom();
+        EndpointReference epFrom = wire.getSource();
+        if (from != null) {
+            from.mergeEndpoint(epFrom);
+        } else {
+            msg.setFrom(epFrom);
+        }
+        msg.setTo(wire.getTarget());
+
+        Invoker headInvoker = chain.getHeadInvoker();
+        Operation operation = chain.getTargetOperation();
+        msg.setOperation(operation);
+
+        Message msgContext = ThreadMessageContext.getMessageContext();
+        Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID();
+
+        ThreadMessageContext.setMessageContext(msg);
+        try {
+            conversationPreinvoke(msg);
+            // handleCallback(msg, currentConversationID);
+            // dispatch the wire down the chain and get the response
+            Message resp = headInvoker.invoke(msg);
+            Object body = resp.getBody();
+            if (resp.isFault()) {
+                throw new InvocationTargetException((Throwable)body);
+            }
+            return body;
+        } catch (InvocationTargetException e) {
+            throw e;
+        } catch (Throwable e) {
+            throw new ServiceRuntimeException(e);
+        } finally {
+            try {
+                conversationPostInvoke(msg);
+            } catch (TargetDestructionException e) {
+                throw new ServiceRuntimeException(e);
+            } finally {
+                ThreadMessageContext.setMessageContext(msgContext);
+            }
+        }
+    }
+
+    /**
+     * @param msgContext
+     */
+    protected EndpointReference getCallbackEndpoint(Message msgContext) {
+        EndpointReference from = msgContext.getFrom();
+        return from == null ? null : from.getReferenceParameters().getCallbackReference();
+    }
+
+    /**
+     * Pre-invoke for the conversation handling
+     * @param msg
+     * @throws TargetResolutionException
+     */
+    private void conversationPreinvoke(Message msg) {
+        if (conversational) {
+            ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
+            // in some cases the ConversationID that should be used comes in with the 
+            // message, e.g. when ws binding is in use.
+            Object convID = parameters.getConversationID();
+            if (convID != null) {
+                conversationID = convID;
+            }
+            conversation = conversationManager.getConversation(conversationID);
+            
+            if (conversation == null || conversation.getState() == ConversationState.ENDED) {
+                conversation = conversationManager.startConversation(conversationID);
+                conversation.initializeConversationAttributes(wire.getTarget().getComponent());
+            } else if (conversation.conversationalAttributesInitialized() == false) {
+                conversation.initializeConversationAttributes(wire.getTarget().getComponent());
+            } else if (conversation.isExpired()){
+            	throw new ConversationEndedException("Conversation has expired.");
+            }
+            
+            conversation.updateLastReferencedTime();
+    
+            parameters.setConversationID(conversation.getConversationID());
+        }
+    }
+
+    /**
+     * Post-invoke for the conversation handling
+     * @param wire
+     * @param operation
+     * @throws TargetDestructionException
+     */
+    @SuppressWarnings("unchecked")
+    private void conversationPostInvoke(Message msg) throws TargetDestructionException {
+        if (conversational) {       
+            Operation operation = msg.getOperation();
+            ConversationSequence sequence = operation.getConversationSequence();
+            if (sequence == ConversationSequence.CONVERSATION_END) {
+                // in some cases the ConversationID that should be used comes in with the 
+                // message, e.g. when ws binding is in use. 
+                Object convID = msg.getFrom().getReferenceParameters().getConversationID();
+                if (convID != null) {
+                    conversationID = convID;
+                }
+                conversation = conversationManager.getConversation(conversationID);            
+    
+                // remove conversation id from scope container
+                ScopeContainer scopeContainer = getConversationalScopeContainer(msg);
+    
+                if (scopeContainer != null) {
+                    scopeContainer.remove(conversation.getConversationID());
+                }
+                
+                conversation.end();
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private ScopeContainer getConversationalScopeContainer(Message msg) {
+        ScopeContainer scopeContainer = null;
+
+        RuntimeComponent component = msg.getTo().getComponent();
+
+        if (component instanceof ScopedRuntimeComponent) {
+            ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component;
+            ScopeContainer container = scopedRuntimeComponent.getScopeContainer();
+
+            if ((container != null) && (container.getScope() == Scope.CONVERSATION)) {
+                scopeContainer = container;
+            }
+        }
+
+        return scopeContainer;
+    }
+
+
+    /**
+     * Minimal wrapper for a callback object contained in a ServiceReference
+     */
+    private static class CallbackObjectWrapper<T> implements InstanceWrapper<T> {
+
+        private T instance;
+
+        private CallbackObjectWrapper(T instance) {
+            this.instance = instance;
+        }
+
+        public T getInstance() {
+            return instance;
+        }
+
+        public void start() {
+            // do nothing
+        }
+
+        public void stop() {
+            // do nothing
+        }
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.sca.core.invocation;
+
+/**
+ * Raised when an error is encountered during a target invocation
+ *
+ * @version $Rev: 568826 $ $Date: 2007-08-22 22:27:34 -0700 (Wed, 22 Aug 2007) $
+ */
+public class TargetInvocationException extends Exception {
+
+    private static final long serialVersionUID = -6553427708442761743L;
+
+    public TargetInvocationException() {
+        super();
+    }
+
+    public TargetInvocationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public TargetInvocationException(String message) {
+        super(message);
+    }
+
+    public TargetInvocationException(Throwable cause) {
+        super(cause);
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,72 @@
+/*
+ * 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.sca.core.invocation;
+
+import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * Class for tunnelling a WorkContext through the invocation of a user class.
+ *
+ * @version $Rev: 639271 $ $Date: 2008-03-20 05:54:38 -0700 (Thu, 20 Mar 2008) $
+ */
+public final class ThreadMessageContext {
+
+    private static final ThreadLocal<Message> CONTEXT = new ThreadLocal<Message>() {
+        @Override
+        protected synchronized Message initialValue() {
+            Message msg =  new MessageImpl();
+            msg.setFrom(new EndpointReferenceImpl("/"));
+            return msg;
+        }
+    };
+
+    private ThreadMessageContext() {
+    }
+
+    /**
+     * Set the WorkContext for the current thread.
+     * The current work context is returned and must be restored after the invocation is complete.
+     * Typical usage would be:
+     * <pre>
+     *   WorkContext old = PojoWorkContextTunnel.setThreadWorkContext(newContext);
+     *   try {
+     *      ... invoke user code ...
+     *   } finally {
+     *     PojoWorkContextTunnel.setThreadWorkContext(old);
+     *   }
+     * </pre>
+     * @param context
+     * @return the current work context for the thread; this must be restored after the invocation is made
+     */
+    public static Message setMessageContext(Message context) {
+        Message old = CONTEXT.get();
+        CONTEXT.set(context);
+        return old;
+    }
+
+    /**
+     * Returns the WorkContext for the current thread.
+     *
+     * @return the WorkContext for the current thread
+     */
+    public static Message getMessageContext() {
+        return CONTEXT.get();
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,54 @@
+/*
+ * 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.sca.core.invocation;
+
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+
+/**
+ * Uses a wire to return an object instance
+ * 
+ * @version $Rev: 596162 $ $Date: 2007-11-18 15:50:50 -0800 (Sun, 18 Nov 2007) $
+ */
+public class WireObjectFactory<T> implements ObjectFactory<T> {
+    private Class<T> interfaze;
+    private RuntimeWire wire;
+    private ProxyFactory proxyService;
+    
+    /**
+     * Constructor.
+     * 
+     * @param interfaze the interface to inject on the client
+     * @param wire the backing wire
+     * @param proxyService the wire service to create the proxy
+     * @throws NoMethodForOperationException
+     */
+    public WireObjectFactory(Class<T> interfaze, RuntimeWire wire, ProxyFactory proxyService) {
+        this.interfaze = interfaze;
+        this.wire = wire;
+        this.proxyService = proxyService;
+    }
+
+    public T getInstance() throws ObjectCreationException {
+        return new ServiceReferenceImpl<T>(interfaze, wire, proxyService).getProxy();
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,201 @@
+/*
+ * 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.sca.core.scope;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.event.Event;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Implements functionality common to scope contexts.
+ * 
+ * @version $Rev: 639271 $ $Date: 2008-03-20 05:54:38 -0700 (Thu, 20 Mar 2008) $
+ */
+public abstract class AbstractScopeContainer<KEY> implements ScopeContainer<KEY> {
+    protected Map<KEY, InstanceWrapper<?>> wrappers = new ConcurrentHashMap<KEY, InstanceWrapper<?>>();
+    protected final Scope scope;
+
+    protected RuntimeComponent component;
+    protected volatile int lifecycleState = UNINITIALIZED;
+
+
+    public AbstractScopeContainer(Scope scope, RuntimeComponent component) {
+        this.scope = scope;
+        this.component = component;
+    }
+
+    protected void checkInit() {
+        if (getLifecycleState() != RUNNING) {
+            throw new IllegalStateException("Scope container not running [" + getLifecycleState() + "]");
+        }
+    }
+
+    /**
+     * Creates a new physical instance of a component, wrapped in an
+     * InstanceWrapper.
+     * 
+     * @param component the component whose instance should be created
+     * @return a wrapped instance that has been injected but not yet started
+     * @throws TargetResolutionException if there was a problem creating the
+     *             instance
+     */
+    protected InstanceWrapper createInstanceWrapper() throws TargetResolutionException {
+        ImplementationProvider implementationProvider = component.getImplementationProvider();
+        if (implementationProvider instanceof ScopedImplementationProvider) {
+            return ((ScopedImplementationProvider)implementationProvider).createInstanceWrapper();
+        }
+        return null;
+    }
+
+    public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException {
+        return getWrapper(contextId); // TODO: what is this method supposed to do diff than getWrapper? 
+    }
+
+    public Scope getScope() {
+        return scope;
+    }
+
+    public InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException {
+        return wrappers.get(contextId);
+    }
+    
+    public void addWrapperReference(KEY existingContextId, KEY newContextId) 
+      throws TargetResolutionException 
+    {
+        // do nothing here. the conversational scope container implements this
+    }
+
+    public void registerWrapper(InstanceWrapper wrapper, KEY contextId) throws TargetResolutionException { 
+        // do nothing here. the conversational scope container implements this
+    }
+
+    public void onEvent(Event event) {
+    }
+
+    protected boolean isEagerInit() {
+        ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider();
+        if (implementationProvider instanceof ScopedImplementationProvider) {
+            return ((ScopedImplementationProvider)implementationProvider).isEagerInit();
+        }
+        return false;
+    }
+
+    public void returnWrapper(InstanceWrapper wrapper, KEY contextId) throws TargetDestructionException {
+    }
+    
+    /**
+     * Default implementation of remove which does nothing 
+     * 
+     * @param contextId the identifier of the context to remove. 
+     */
+    public void remove(KEY contextId) 
+        throws TargetDestructionException {
+    }    
+
+    public synchronized void start() {
+        int lifecycleState = getLifecycleState();
+        if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) {
+            throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]");
+        }
+        setLifecycleState(RUNNING);
+    }
+
+    public void startContext(KEY contextId) {
+        if(isEagerInit()) {
+            try {
+                getWrapper(contextId);
+            } catch (TargetResolutionException e) {
+                // 
+            }
+        }
+    }
+
+    public synchronized void stop() {
+        int lifecycleState = getLifecycleState();
+        if (lifecycleState != RUNNING) {
+            throw new IllegalStateException("Scope in wrong state [" + lifecycleState + "]");
+        }
+        setLifecycleState(STOPPED);
+    }
+
+    public void stopContext(KEY contextId) {
+        wrappers.remove(contextId);
+    }
+
+    @Override
+    public String toString() {
+        String s;
+        switch (lifecycleState) {
+            case ScopeContainer.CONFIG_ERROR:
+                s = "CONFIG_ERROR";
+                break;
+            case ScopeContainer.ERROR:
+                s = "ERROR";
+                break;
+            case ScopeContainer.INITIALIZING:
+                s = "INITIALIZING";
+                break;
+            case ScopeContainer.INITIALIZED:
+                s = "INITIALIZED";
+                break;
+            case ScopeContainer.RUNNING:
+                s = "RUNNING";
+                break;
+            case ScopeContainer.STOPPING:
+                s = "STOPPING";
+                break;
+            case ScopeContainer.STOPPED:
+                s = "STOPPED";
+                break;
+            case ScopeContainer.UNINITIALIZED:
+                s = "UNINITIALIZED";
+                break;
+            default:
+                s = "UNKNOWN";
+                break;
+        }
+        return "In state [" + s + ']';
+    }
+
+    public RuntimeComponent getComponent() {
+        return component;
+    }
+
+    public void setComponent(RuntimeComponent component) {
+        this.component = component;
+    }
+
+    public int getLifecycleState() {
+        return lifecycleState;
+    }
+
+    /**
+     * Set the current state of the Lifecycle.
+     *
+     * @param lifecycleState the new state
+     */
+    protected void setLifecycleState(int lifecycleState) {
+        this.lifecycleState = lifecycleState;
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,77 @@
+/*
+ * 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.sca.core.scope;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * A scope context which manages atomic component instances keyed by composite
+ * 
+ * @version $Rev: 571516 $ $Date: 2007-08-31 09:41:22 -0700 (Fri, 31 Aug 2007) $
+ */
+public class CompositeScopeContainer<KEY> extends AbstractScopeContainer<KEY> {
+    private InstanceWrapper<?> wrapper;
+
+    public CompositeScopeContainer(RuntimeComponent component) {
+        super(Scope.COMPOSITE, component);
+    }
+
+    @Override
+    public synchronized void stop() {
+        super.stop();
+        if (wrapper != null) {
+            try {
+                wrapper.stop();
+            } catch (TargetDestructionException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+        wrapper = null;
+    }
+
+    @Override
+    public synchronized InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException {
+        if (wrapper == null) {
+            wrapper = createInstanceWrapper();
+            wrapper.start();
+        }
+        return wrapper;
+    }
+
+    @Override
+    public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException {
+        if (wrapper == null) {
+            throw new TargetNotFoundException(component.getURI());
+        }
+        return wrapper;
+    }
+
+    @Override
+    public synchronized void start() {
+        super.start();
+        if (isEagerInit()) {
+            try {
+                getWrapper(null);
+            } catch (TargetResolutionException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+    }
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,37 @@
+/*
+ * 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.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev: 568826 $ $Date: 2007-08-22 22:27:34 -0700 (Wed, 22 Aug 2007) $
+ */
+public class CompositeScopeContainerFactory implements ScopeContainerFactory {
+
+    public ScopeContainer createScopeContainer(RuntimeComponent component) {
+        return new CompositeScopeContainer(component);
+    }
+
+    public Scope getScope() {
+        return Scope.COMPOSITE;
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,290 @@
+/*
+ * 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.sca.core.scope;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.conversation.ConversationListener;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.conversation.ExtendedConversation;
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.store.Store;
+
+/**
+ * A scope context which manages atomic component instances keyed on ConversationID
+ * 
+ */
+public class ConversationalScopeContainer extends AbstractScopeContainer<Object> implements ConversationListener {
+    private ConversationManager conversationManager;
+    private Map<Object, InstanceLifeCycleWrapper> instanceLifecycleCollection =
+        new ConcurrentHashMap<Object, InstanceLifeCycleWrapper>();
+
+    public ConversationalScopeContainer(Store aStore, RuntimeComponent component) {
+        super(Scope.CONVERSATION, component);
+
+        // Note: aStore is here to preserve the original factory interface. It is not currently used in this 
+        // implementation since we do not support instance persistence.
+
+        // Check System properties to see if timeout values have been specified. All timeout values 
+        // will be specified in seconds.
+        //
+
+    }
+
+
+    protected InstanceWrapper getInstanceWrapper(boolean create, Object contextId) throws TargetResolutionException {
+
+        // we might get a null context if the target service has
+        // conversational scope but only its callback interface 
+        // is conversational. In this case we need to invent a 
+        // conversation Id here to store the service against
+        // and populate the thread context
+        if (contextId == null) {
+            contextId = UUID.randomUUID().toString();
+            Message msgContext = ThreadMessageContext.getMessageContext();
+
+            if (msgContext != null) {
+                msgContext.getFrom().getReferenceParameters().setConversationID(contextId);
+            }
+        }    
+        
+        InstanceLifeCycleWrapper anInstanceWrapper = this.instanceLifecycleCollection.get(contextId);
+
+        if (anInstanceWrapper == null && !create)
+            return null;
+
+        if (anInstanceWrapper == null) {
+            anInstanceWrapper = new InstanceLifeCycleWrapper(contextId);
+            this.instanceLifecycleCollection.put(contextId, anInstanceWrapper);
+        }
+
+        return anInstanceWrapper.getInstanceWrapper(contextId);
+
+    }
+
+    @Override
+    public InstanceWrapper getWrapper(Object contextId) throws TargetResolutionException {
+        return getInstanceWrapper(true, contextId);
+    }
+
+    /**
+     * This method allows a new context id to be registered alongside an existing one. This happens in
+     * one case, when a conversation includes a stateful callback. The client component instance
+ 	 * must be registered against all outgoing conversation ids so that the component instance 
+	 * can be found when the callback arrives
+	 * 
+     * @param existingContextId the context id against which the component is already registered
+     * @param context this should be a conversation object so that the conversation can b stored 
+     *                and reset when the component instance is removed
+     */
+    public void addWrapperReference(Object existingContextId, Object contextId) throws TargetResolutionException {
+       
+        
+        // get the instance wrapper via the existing id
+        InstanceLifeCycleWrapper existingInstanceWrapper = this.instanceLifecycleCollection.get(existingContextId);
+        InstanceLifeCycleWrapper newInstanceWrapper = this.instanceLifecycleCollection.get(contextId);
+
+        // only add the extra reference once
+        if (newInstanceWrapper == null) {
+            // add the id to the list of ids that the wrapper holds. Used for reference
+            // counting and conversation resetting on destruction. 
+            existingInstanceWrapper.addCallbackConversation(contextId);
+
+            // add the reference to the collection
+            this.instanceLifecycleCollection.put(contextId, existingInstanceWrapper);
+        }
+    }
+
+    public void registerWrapper(InstanceWrapper wrapper, Object contextId) throws TargetResolutionException {
+        // if a wrapper for a different instance is already registered for this contextId, remove it
+        InstanceLifeCycleWrapper anInstanceWrapper = this.instanceLifecycleCollection.get(contextId);
+        if (anInstanceWrapper != null) {
+            if (anInstanceWrapper.getInstanceWrapper(contextId).getInstance() != wrapper.getInstance()) {
+                remove(contextId);
+            } else {
+                return;
+            }
+        }
+
+        anInstanceWrapper = new InstanceLifeCycleWrapper(wrapper, contextId);
+        this.instanceLifecycleCollection.put(contextId, anInstanceWrapper);
+    }
+
+    // The remove is invoked when a conversation is explicitly ended. This can occur by using the @EndsConversation or API.  
+    // In this case the instance is immediately removed. A new conversation will be started on the next operation
+    // associated with this conversationId's service reference. 
+    //
+    @Override
+    public void remove(Object contextId) throws TargetDestructionException {
+        if (contextId != null) {
+            if (this.instanceLifecycleCollection.containsKey(contextId)) {
+                InstanceLifeCycleWrapper anInstanceLifeCycleWrapper = this.instanceLifecycleCollection.get(contextId);
+                this.instanceLifecycleCollection.remove(contextId);
+                anInstanceLifeCycleWrapper.removeInstanceWrapper(contextId);
+            }
+        }
+    }
+
+    /*
+     *  This is an inner class that keeps track of the lifecycle of a conversation scoped 
+	 *  implementation instance. 
+	 * 
+	 */
+
+    private class InstanceLifeCycleWrapper {
+        private Object clientConversationId;
+        private List<Object> callbackConversations = new ArrayList<Object>();
+
+        private InstanceLifeCycleWrapper(Object contextId) throws TargetResolutionException {
+            this.clientConversationId = contextId;
+            this.createInstance(contextId);
+        }
+
+        private InstanceLifeCycleWrapper(InstanceWrapper wrapper, Object contextId) throws TargetResolutionException {
+            this.clientConversationId = contextId;
+            wrappers.put(contextId, wrapper);
+        }
+
+
+        // Associates a callback conversation with this instance. Each time the scope container
+        // is asked to remove an object given a ontextId an associated conversation object will 
+        // have its conversationId reset to null. When the list of ids is empty the component instance
+        // will be removed from the scope container
+        private void addCallbackConversation(Object conversationID) {
+            InstanceWrapper ctx = getInstanceWrapper(clientConversationId);
+            callbackConversations.add(conversationID);
+            wrappers.put(conversationID, ctx);
+        }
+
+        //
+        // Return the backing implementation instance  
+        //
+        private InstanceWrapper getInstanceWrapper(Object contextId) {
+            InstanceWrapper ctx = wrappers.get(contextId);
+            return ctx;
+        }
+
+        private void removeInstanceWrapper(Object contextId) throws TargetDestructionException {
+            InstanceWrapper ctx = getInstanceWrapper(contextId);
+            wrappers.remove(contextId);
+
+            // find out if we are dealing with the original client conversation id
+            // and reset accordingly
+            if ( ( clientConversationId != null ) && ( clientConversationId.equals(contextId)) ) {
+                clientConversationId = null;
+            } else {
+                // reset the conversationId in the conversation object if present 
+                // so that and ending callback causes the conversation in the originating
+                // service reference in the client to be reset
+                callbackConversations.remove(contextId);
+            }
+
+            // stop the component if this removes the last reference
+            if (clientConversationId == null && callbackConversations.isEmpty()) {
+                ctx.stop();
+            }
+        }
+
+        private void createInstance(Object contextId) throws TargetResolutionException {
+            InstanceWrapper instanceWrapper = createInstanceWrapper();
+            instanceWrapper.start();
+            wrappers.put(contextId, instanceWrapper);
+        }
+
+    }
+
+    /**
+	  * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationEnded(org.apache.tuscany.sca.core.conversation.ExtendedConversation)
+	  */
+    public void conversationEnded(ExtendedConversation conversation) {
+        try {
+            remove(conversation.getConversationID());
+        } catch (Exception ex) {
+            
+        }
+    }
+
+    /**
+	  * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationExpired(org.apache.tuscany.sca.core.conversation.ExtendedConversation)
+	  */
+    public void conversationExpired(ExtendedConversation conversation) {
+    	
+    	Object conversationId = conversation.getConversationID();
+    	InstanceLifeCycleWrapper ilcw = instanceLifecycleCollection.get(conversationId);
+    	if (ilcw != null)
+    	{
+    		// cycle through all the references to this instance and
+    		// remove them from the underlying wrappers collection and
+    		// from the lifecycle wrappers collection
+    		
+    		for (Object conversationID : ilcw.callbackConversations) {
+    			try{
+        			ilcw.removeInstanceWrapper(conversationID);
+    				remove(conversationID);
+    			}
+    			catch(TargetDestructionException tde){
+    				System.out.println("Could not remove conversation id " + conversationID);
+    			}
+    		}
+    			
+    		
+    		if (ilcw.clientConversationId != null) {
+    			try{
+        			ilcw.removeInstanceWrapper(ilcw.clientConversationId);
+    				remove(ilcw.clientConversationId);
+    			}
+    			catch(TargetDestructionException tde){
+    				System.out.println("Could not remove conversation id " + ilcw.clientConversationId);
+    			}
+    		}
+    		
+        }
+    	
+    }
+
+    /**
+	  * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationStarted(org.apache.tuscany.sca.core.conversation.ExtendedConversation)
+	  */
+    public void conversationStarted(ExtendedConversation conversation) {
+        startContext(conversation.getConversationID());
+    }
+
+    /**
+	  * @return the conversationManager
+	  */
+    public ConversationManager getConversationManager() {
+        return conversationManager;
+    }
+
+    /**
+	  * @param conversationManager the conversationManager to set
+	  */
+    public void setConversationManager(ConversationManager conversationManager) {
+        this.conversationManager = conversationManager;
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,44 @@
+/*
+ * 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.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.store.Store;
+
+/**
+ * @version $Rev: 568826 $ $Date: 2007-08-22 22:27:34 -0700 (Wed, 22 Aug 2007) $
+ */
+public class ConversationalScopeContainerFactory implements ScopeContainerFactory {
+    private Store store;
+
+    public ConversationalScopeContainerFactory(Store store) {
+        super();
+        this.store = store;
+    }
+
+    public ScopeContainer createScopeContainer(RuntimeComponent component) {
+        return new ConversationalScopeContainer(store, component);
+    }
+
+    public Scope getScope() {
+        return Scope.CONVERSATION;
+    }
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,83 @@
+/*
+ * 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.sca.core.scope;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.event.HttpSessionEnd;
+import org.apache.tuscany.sca.event.Event;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * A scope context which manages atomic component instances keyed on HTTP
+ * session
+ * 
+ * @version $Rev: 568826 $ $Date: 2007-08-22 22:27:34 -0700 (Wed, 22 Aug 2007) $
+ */
+public class HttpSessionScopeContainer extends AbstractScopeContainer<Object> {
+
+    public HttpSessionScopeContainer(RuntimeComponent component) {
+        super(Scope.SESSION, component);
+    }
+
+    @Override
+    public void onEvent(Event event) {
+        checkInit();
+        if (event instanceof HttpSessionEnd) {
+            //FIXME key is not used
+            //Object key = ((HttpSessionEnd)event).getSessionID();
+            // FIXME: Remove the session id
+        }
+    }
+
+    @Override
+    public synchronized void start() {
+        if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) {
+            throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]");
+        }
+        lifecycleState = RUNNING;
+    }
+
+    @Override
+    public synchronized void stop() {
+        lifecycleState = STOPPED;
+    }
+
+    protected InstanceWrapper getInstanceWrapper(boolean create) throws TargetResolutionException {
+//        Object key = workContext.getIdentifier(Scope.SESSION);
+        // FIXME: Need to fix this
+        Object key ="http-session-id";
+        assert key != null : "HTTP session key not bound in work context";
+        InstanceWrapper ctx = wrappers.get(key);
+        if (ctx == null && !create) {
+            return null;
+        }
+        if (ctx == null) {
+            ctx = super.createInstanceWrapper();
+            ctx.start();
+            wrappers.put(key, ctx);
+        }
+        return ctx;
+    }
+    
+    @Override
+    public InstanceWrapper getWrapper(Object contextId) throws TargetResolutionException {
+        return getInstanceWrapper(true);
+    }    
+
+}

Added: incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java?rev=639535&view=auto
==============================================================================
--- incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java (added)
+++ incubator/tuscany/sandbox/mobile-android/core-android/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java Thu Mar 20 20:42:35 2008
@@ -0,0 +1,41 @@
+/*
+ * 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.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev: 568826 $ $Date: 2007-08-22 22:27:34 -0700 (Wed, 22 Aug 2007) $
+ */
+public class HttpSessionScopeContainerFactory implements ScopeContainerFactory {
+
+    public HttpSessionScopeContainerFactory() {
+        super();
+    }
+
+    public ScopeContainer createScopeContainer(RuntimeComponent component) {
+        return new HttpSessionScopeContainer(component);
+    }
+
+    public Scope getScope() {
+        return Scope.SESSION;
+    }
+
+}



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