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

svn commit: r505801 - in /incubator/tuscany/branches/sca-java-integration: sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ spec/sca-api-r1.0/src/main/java/org/osoa/sca/

Author: jsdelfino
Date: Sat Feb 10 16:04:29 2007
New Revision: 505801

URL: http://svn.apache.org/viewvc?view=rev&rev=505801
Log:
Added a few old classes from the pre-spec-changes branch to get the test fwk working

Added:
    incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java   (with props)
    incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CompositeContext.java   (with props)
    incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CurrentCompositeContext.java   (with props)

Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java?view=auto&rev=505801
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java Sat Feb 10 16:04:29 2007
@@ -0,0 +1,120 @@
+/*
+ * 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.composite;
+
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.ServiceRuntimeException;
+
+import org.apache.tuscany.spi.QualifiedName;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.WireService;
+
+/**
+ * Base implementation of the {@link org.osoa.sca.CompositeContext}
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractCompositeContext implements CompositeContext {
+    protected final CompositeComponent composite;
+    protected final WireService wireService;
+
+    public AbstractCompositeContext(final CompositeComponent composite, final WireService wireService) {
+        this.composite = composite;
+        this.wireService = wireService;
+    }
+
+    public String getName() {
+        return composite.getName();
+    }
+
+    public String getURI() {
+        throw new UnsupportedOperationException();
+    }
+
+    public <T> T locateService(Class<T> serviceInterface, String serviceName) throws ServiceRuntimeException {
+        QualifiedName qName = new QualifiedName(serviceName);
+        if (qName.getPortName() == null) {
+            String name = serviceInterface.getName();
+            qName = new QualifiedName(qName.getPartName(), name);
+        }
+        SCAObject child = composite.getChild(qName.getPartName());
+        InboundWire wire = getInboundWire(child, qName);
+        if (wire.isOptimizable()
+            && wire.getServiceContract().getInterfaceClass() != null
+            && serviceInterface.isAssignableFrom(wire.getServiceContract().getInterfaceClass())) {
+            try {
+                return serviceInterface.cast(wire.getTargetService());
+            } catch (TargetResolutionException e) {
+                throw new ServiceRuntimeException(e);
+            }
+        }
+        return wireService.createProxy(serviceInterface, wire);
+    }
+
+    protected InboundWire getInboundWire(SCAObject child, QualifiedName qName) {
+        InboundWire wire = null;
+        if (child instanceof Component) {
+            wire = ((Component) child).getInboundWire(qName.getPortName());
+            if (wire == null) {
+                throw new ServiceRuntimeException("Service not found [" + qName + "]");
+            }
+        } else if (child instanceof Service) {
+            Service service = (Service) child;
+            for (ServiceBinding binding : service.getServiceBindings()) {
+                if (Wire.LOCAL_BINDING.equals(binding.getInboundWire().getBindingType())) {
+                    wire = binding.getInboundWire();
+                    break;
+                }
+            }
+            if (wire == null) {
+                throw new ServiceRuntimeException("Local binding for service not found [" + qName + "]");
+            }
+        } else if (child instanceof Reference) {
+            Reference service = (Reference) child;
+            if (service.getReferenceBindings().isEmpty()) {
+                throw new ServiceRuntimeException("No binding for reference [" + qName + "]");
+            }
+            for (ReferenceBinding binding : service.getReferenceBindings()) {
+                if (Wire.LOCAL_BINDING.equals(binding.getInboundWire().getBindingType())) {
+                    wire = binding.getInboundWire();
+                    break;
+                }
+            }
+            if (wire == null) {
+                // pick the first one
+                wire = service.getReferenceBindings().get(0).getInboundWire();
+            }
+        } else if (child == null) {
+            throw new ServiceRuntimeException("Service not found [" + qName + "]");
+        } else {
+            throw new ServiceRuntimeException("Invalid service type [" + child.getClass().getName() + "]");
+        }
+        return wire;
+    }
+
+}

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

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

Added: incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CompositeContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CompositeContext.java?view=auto&rev=505801
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CompositeContext.java (added)
+++ incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CompositeContext.java Sat Feb 10 16:04:29 2007
@@ -0,0 +1,93 @@
+/*
+ * 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.osoa.sca;
+
+
+/**
+ * Interface used by SCA Components to access their context
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CompositeContext {
+
+    /**
+     * Returns the name of the parent composite.
+     *
+     * @return the name of the module
+     */
+    String getName();
+
+    /**
+     * Returns the absolute URI of the composite component.
+     *
+     * @return the absolute URI of the module component
+     */
+    String getURI();
+
+    /**
+     * Returns the request context that corresponds to the last remotable service invocation. If this is
+     * invoked from outside an SCA component then <tt>null</tt> is returned.
+     *
+     * @return the current request context
+     */
+    RequestContext getRequestContext();
+
+    /**
+     * Returns an object implementing the interface defined for the named service.
+     *
+     * @param serviceName the name of another service in the current module
+     * @return an object that implements the service's interface
+     */
+    <T> T locateService(Class<T> serviceType, String serviceName);
+
+    /**
+     * Create a reference to the supplied component. The component must define only one service.
+     *
+     * @param self the component to be referenced
+     * @return a reference to the component
+     */
+    ServiceReference createServiceReferenceForSession(Object self);
+
+    /**
+     * Create a reference to the named service implemented by the supplied component.
+     *
+     * @param self        the component to be referenced
+     * @param serviceName the service to be referenced
+     * @return a reference to the service
+     */
+    ServiceReference createServiceReferenceForSession(Object self, String serviceName);
+
+    /**
+     * Create a new session for stateful interaction with the named service.
+     *
+     * @param serviceName the name of the service to interact with
+     * @return a reference to the service
+     */
+    ServiceReference newSession(String serviceName);
+
+    /**
+     * Create a new session for stateful interaction with the named service using an application-supplied
+     * session identifier.
+     *
+     * @param serviceName the name of the service to interact with
+     * @param sessionId   a token that identifies this session
+     * @return a reference to the service
+     */
+    ServiceReference newSession(String serviceName, Object sessionId);
+}

Propchange: incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CompositeContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CompositeContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CurrentCompositeContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CurrentCompositeContext.java?view=auto&rev=505801
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CurrentCompositeContext.java (added)
+++ incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CurrentCompositeContext.java Sat Feb 10 16:04:29 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.osoa.sca;
+
+/**
+ * Class providing access to the current CompositeComponent.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class CurrentCompositeContext {
+    private static final ThreadLocal<CompositeContext> CURRENT_COMPONENT =
+        new InheritableThreadLocal<CompositeContext>();
+
+    /**
+     * Returns the current composite context associated with this thread.
+     *
+     * @return the current composite context
+     */
+    public static CompositeContext getContext() {
+        return CURRENT_COMPONENT.get();
+    }
+
+    /**
+     * Sets the composite context that is associated with this thread.
+     *
+     * @param context the context to associated with this thread; may be null
+     * @return the context previously associated with this thread; may be null
+     */
+    public static CompositeContext setContext(CompositeContext context) {
+        CompositeContext current = CURRENT_COMPONENT.get();
+        CURRENT_COMPONENT.set(context);
+        return current;
+    }
+}

Propchange: incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CurrentCompositeContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/spec/sca-api-r1.0/src/main/java/org/osoa/sca/CurrentCompositeContext.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