tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r534699 - in /incubator/tuscany/java/sca/samples: binding-echo/src/main/java/echo/ implementation-crud/src/main/java/crud/
Date Thu, 03 May 2007 03:29:39 GMT
Author: jsdelfino
Date: Wed May  2 20:29:38 2007
New Revision: 534699

URL: http://svn.apache.org/viewvc?view=rev&rev=534699
Log:
Separating the pure model part from the runtime provider part in the crud and echo binding
samples.

Added:
    incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java
  (with props)
    incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProvider.java
  (with props)
    incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java
  (with props)
Removed:
    incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDTargetInvoker.java
Modified:
    incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/DefaultEchoBindingFactory.java
    incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingImpl.java
    incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java
    incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProcessor.java

Modified: incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/DefaultEchoBindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/DefaultEchoBindingFactory.java?view=diff&rev=534699&r1=534698&r2=534699
==============================================================================
--- incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/DefaultEchoBindingFactory.java
(original)
+++ incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/DefaultEchoBindingFactory.java
Wed May  2 20:29:38 2007
@@ -27,7 +27,7 @@
 public class DefaultEchoBindingFactory implements EchoBindingFactory {
 
     public EchoBinding createEchoBinding() {
-        return new EchoBindingImpl();
+        return new EchoBindingProvider();
     }
 
 }

Modified: incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingImpl.java?view=diff&rev=534699&r1=534698&r2=534699
==============================================================================
--- incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingImpl.java
(original)
+++ incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingImpl.java
Wed May  2 20:29:38 2007
@@ -19,65 +19,59 @@
 
 package echo;
 
-import java.net.URI;
+import java.util.Collections;
+import java.util.List;
 
-import org.apache.tuscany.assembly.Component;
-import org.apache.tuscany.assembly.ComponentReference;
-import org.apache.tuscany.assembly.ComponentService;
-import org.apache.tuscany.assembly.impl.BindingImpl;
-import org.apache.tuscany.core.ReferenceBindingActivator;
-import org.apache.tuscany.core.ReferenceBindingProvider;
-import org.apache.tuscany.core.ServiceBindingActivator;
-import org.apache.tuscany.core.ServiceBindingProvider;
-import org.apache.tuscany.interfacedef.InterfaceContract;
-import org.apache.tuscany.interfacedef.Operation;
-import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.policy.Intent;
+import org.apache.tuscany.policy.PolicySet;
 
 /**
  * Implementation of the Echo binding model.
  *
  * @version $Rev$ $Date$
  */
-public class EchoBindingImpl extends BindingImpl implements EchoBinding, ReferenceBindingActivator,
-    ReferenceBindingProvider, ServiceBindingActivator, ServiceBindingProvider {
+public class EchoBindingImpl implements EchoBinding {
+    
+    private String name;
+    private String uri;
 
-    public Interceptor createInterceptor(Component component,
-                                         ComponentReference reference,
-                                         Operation operation,
-                                         boolean isCallback) {
-        if (isCallback) {
-            throw new UnsupportedOperationException();
-        } else {
-            return new EchoBindingInterceptor();
-        }
+    public String getName() {
+        return name;
     }
 
-    public InterfaceContract getBindingInterfaceContract(ComponentReference reference) {
-        return reference.getInterfaceContract();
+    public String getURI() {
+        return uri;
     }
 
-    public void start(Component component, ComponentReference reference) {
+    public void setName(String name) {
+        this.name = name;
     }
 
-    public void stop(Component component, ComponentReference reference) {
+    public void setURI(String uri) {
+        this.uri = uri;
     }
 
-    public InterfaceContract getBindingInterfaceContract(ComponentService service) {
-        return service.getInterfaceContract();
+    public List<PolicySet> getPolicySets() {
+        // The sample binding does not support policies
+        return Collections.emptyList();
     }
 
-    public void start(Component component, ComponentService service) {
-        URI uri = URI.create(component.getURI() + "#" + service.getName());
-        // Register with the hosting server
-        EchoServer.getServer().register(new EchoService(uri), uri);
+    public List<Intent> getRequiredIntents() {
+        // The sample binding does not support policies
+        return Collections.emptyList();
+    }
+    
+    public List<Object> getExtensions() {
+        // The sample binding does not support extensions
+        return Collections.emptyList();
     }
 
-    public void stop(Component component, ComponentService service) {
-        // Register with the hosting server
-        EchoServer.getServer().unregister(URI.create(component.getURI() + "#" + service.getName()));
+    public boolean isUnresolved() {
+        return false;
     }
 
-    public Object clone() {
-        return this;
+    public void setUnresolved(boolean unresolved) {
+        // The sample binding is always resolved
     }
+
 }

Added: incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java?view=auto&rev=534699
==============================================================================
--- incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java
(added)
+++ incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java
Wed May  2 20:29:38 2007
@@ -0,0 +1,82 @@
+/*
+ * 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 echo;
+
+import java.net.URI;
+
+import org.apache.tuscany.assembly.Component;
+import org.apache.tuscany.assembly.ComponentReference;
+import org.apache.tuscany.assembly.ComponentService;
+import org.apache.tuscany.core.ReferenceBindingActivator;
+import org.apache.tuscany.core.ReferenceBindingProvider;
+import org.apache.tuscany.core.ServiceBindingActivator;
+import org.apache.tuscany.core.ServiceBindingProvider;
+import org.apache.tuscany.interfacedef.InterfaceContract;
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+
+/**
+ * Implementation of the Echo binding provider.
+ *
+ * @version $Rev$ $Date$
+ */
+public class EchoBindingProvider extends EchoBindingImpl implements ReferenceBindingActivator,
+    ReferenceBindingProvider, ServiceBindingActivator, ServiceBindingProvider {
+
+    public Interceptor createInterceptor(Component component,
+                                         ComponentReference reference,
+                                         Operation operation,
+                                         boolean isCallback) {
+        if (isCallback) {
+            throw new UnsupportedOperationException();
+        } else {
+            return new EchoBindingInterceptor();
+        }
+    }
+
+    public InterfaceContract getBindingInterfaceContract(ComponentReference reference) {
+        return reference.getInterfaceContract();
+    }
+
+    public void start(Component component, ComponentReference reference) {
+    }
+
+    public void stop(Component component, ComponentReference reference) {
+    }
+
+    public InterfaceContract getBindingInterfaceContract(ComponentService service) {
+        return service.getInterfaceContract();
+    }
+
+    public void start(Component component, ComponentService service) {
+        URI uri = URI.create(component.getURI() + "#" + service.getName());
+        // Register with the hosting server
+        EchoServer.getServer().register(new EchoService(uri), uri);
+    }
+
+    public void stop(Component component, ComponentService service) {
+        // Register with the hosting server
+        EchoServer.getServer().unregister(URI.create(component.getURI() + "#" + service.getName()));
+    }
+
+    public Object clone() {
+        return this;
+    }
+}

Propchange: incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/samples/binding-echo/src/main/java/echo/EchoBindingProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java?view=diff&rev=534699&r1=534698&r2=534699
==============================================================================
--- incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java
(original)
+++ incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java
Wed May  2 20:29:38 2007
@@ -22,26 +22,18 @@
 import java.util.List;
 
 import org.apache.tuscany.assembly.AssemblyFactory;
-import org.apache.tuscany.assembly.ComponentService;
 import org.apache.tuscany.assembly.ConstrainingType;
 import org.apache.tuscany.assembly.Implementation;
 import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.assembly.Reference;
 import org.apache.tuscany.assembly.Service;
-import org.apache.tuscany.assembly.impl.ComponentTypeImpl;
-import org.apache.tuscany.core.ImplementationActivator;
-import org.apache.tuscany.core.ImplementationProvider;
-import org.apache.tuscany.core.RuntimeComponent;
-import org.apache.tuscany.interfacedef.InterfaceContract;
 import org.apache.tuscany.interfacedef.InvalidInterfaceException;
-import org.apache.tuscany.interfacedef.Operation;
 import org.apache.tuscany.interfacedef.java.JavaFactory;
 import org.apache.tuscany.interfacedef.java.JavaInterface;
 import org.apache.tuscany.interfacedef.java.JavaInterfaceContract;
 import org.apache.tuscany.interfacedef.java.introspect.JavaInterfaceIntrospector;
 import org.apache.tuscany.policy.Intent;
 import org.apache.tuscany.policy.PolicySet;
-import org.apache.tuscany.spi.Scope;
-import org.apache.tuscany.spi.wire.Interceptor;
 
 /**
  * The model representing a sample CRUD implementation in an SCA assembly model.
@@ -55,14 +47,11 @@
  * @version $$Rev$$ $$Date: 2007-04-23 19:18:54 -0700 (Mon, 23 Apr
  *          2007) $$
  */
-public class CRUDImplementation extends ComponentTypeImpl implements Implementation, ImplementationProvider,
-    ImplementationActivator {
+public class CRUDImplementation implements Implementation {
 
     private Service crudService;
     private String directory;
 
-    private AssemblyFactory assemblyFactory;
-
     /**
      * Constructs a new CRUD implementation.
      */
@@ -83,8 +72,6 @@
         JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
         interfaceContract.setInterface(javaInterface);
         crudService.setInterfaceContract(interfaceContract);
-        this.assemblyFactory = assemblyFactory;
-        // createSelfReferences();
     }
 
     /**
@@ -119,6 +106,11 @@
         // CRUD implementations provide a single fixed CRUD service
         return Collections.singletonList(crudService);
     }
+    
+    public List<Reference> getReferences() {
+        // CRUD implementations do not support properties
+        return Collections.emptyList();
+    }
 
     public String getURI() {
         // CRUD implementations don't have a URI
@@ -155,31 +147,6 @@
 
     public void setUnresolved(boolean unresolved) {
         // CRUD implementations are always resolved
-    }
-
-    public Interceptor createInterceptor(RuntimeComponent component,
-                                         ComponentService service,
-                                         Operation operation,
-                                         boolean isCallback) {
-        CRUDImplementation impl = (CRUDImplementation)component.getImplementation();
-        CRUDTargetInvoker invoker = new CRUDTargetInvoker(operation, new ResourceManager(impl.getDirectory()));
-        return invoker;
-    }
-
-    public InterfaceContract getImplementationInterfaceContract(ComponentService service)
{
-        return service.getInterfaceContract();
-    }
-
-    public void start(RuntimeComponent component) {
-        System.out.println("Starting " + component.getName());
-    }
-
-    public void stop(RuntimeComponent component) {
-        System.out.println("Stopping " + component.getName());
-    }
-
-    public void configure(RuntimeComponent component) {
-        System.out.println("Configuring " + component.getName());
     }
 
 }

Modified: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProcessor.java?view=diff&rev=534699&r1=534698&r2=534699
==============================================================================
--- incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProcessor.java
(original)
+++ incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProcessor.java
Wed May  2 20:29:38 2007
@@ -56,7 +56,7 @@
         this.assemblyFactory = assemblyFactory;
         this.javaFactory = javaFactory;
         this.introspector = introspector;
-    } 
+    }
 
     public QName getArtifactType() {
         // Returns the qname of the XML element processed by this processor
@@ -78,7 +78,7 @@
             String directory = reader.getAttributeValue(null, "directory");
 
             // Create an initialize the CRUD implementation model
-            CRUDImplementation implementation = new CRUDImplementation(assemblyFactory, javaFactory,
introspector);
+            CRUDImplementation implementation = new CRUDImplementationProvider(assemblyFactory,
javaFactory, introspector);
             implementation.setDirectory(directory);
             
             // Skip to end element

Added: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProvider.java?view=auto&rev=534699
==============================================================================
--- incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProvider.java
(added)
+++ incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProvider.java
Wed May  2 20:29:38 2007
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package crud;
+
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.assembly.ComponentService;
+import org.apache.tuscany.core.ImplementationActivator;
+import org.apache.tuscany.core.ImplementationProvider;
+import org.apache.tuscany.core.RuntimeComponent;
+import org.apache.tuscany.interfacedef.InterfaceContract;
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.interfacedef.java.JavaFactory;
+import org.apache.tuscany.interfacedef.java.introspect.JavaInterfaceIntrospector;
+import org.apache.tuscany.spi.wire.Interceptor;
+
+/**
+ * The model representing a sample CRUD implementation in an SCA assembly model.
+ * The sample CRUD implementation is not a full blown implementation, it only
+ * supports a subset of what a component implementation can support: - a single
+ * fixed service (as opposed to a list of services typed by different
+ * interfaces) - a directory attribute used to specify where a CRUD component is
+ * going to persist resources - no references or properties - no policy intents
+ * or policy sets
+ * 
+ * @version $$Rev$$ $$Date: 2007-04-23 19:18:54 -0700 (Mon, 23 Apr
+ *          2007) $$
+ */
+public class CRUDImplementationProvider extends CRUDImplementation implements ImplementationProvider,
+    ImplementationActivator {
+
+    /**
+     * Constructs a new CRUD implementation.
+     */
+    public CRUDImplementationProvider(AssemblyFactory assemblyFactory,
+                              JavaFactory javaFactory,
+                              JavaInterfaceIntrospector introspector) {
+        super(assemblyFactory, javaFactory, introspector);
+    }
+
+    public Interceptor createInterceptor(RuntimeComponent component,
+                                         ComponentService service,
+                                         Operation operation,
+                                         boolean isCallback) {
+        CRUDInvoker invoker = new CRUDInvoker(operation, new ResourceManager(getDirectory()));
+        return invoker;
+    }
+
+    public InterfaceContract getImplementationInterfaceContract(ComponentService service)
{
+        return service.getInterfaceContract();
+    }
+
+    public void start(RuntimeComponent component) {
+        System.out.println("Starting " + component.getName());
+    }
+
+    public void stop(RuntimeComponent component) {
+        System.out.println("Stopping " + component.getName());
+    }
+
+    public void configure(RuntimeComponent component) {
+        System.out.println("Configuring " + component.getName());
+    }
+
+}

Propchange: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java?view=auto&rev=534699
==============================================================================
--- incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java
(added)
+++ incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java
Wed May  2 20:29:38 2007
@@ -0,0 +1,89 @@
+/*
+ * 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 crud;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+
+/**
+ * Implements a target invoker for CRUD component implementations.
+ * 
+ * The target invoker is responsible for dispatching invocations to the particular
+ * component implementation logic. In this example we are simply delegating the
+ * CRUD operation invocations to the corresponding methods on our fake
+ * resource manager.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class CRUDInvoker implements Interceptor {
+    private Operation operation;
+    private ResourceManager resourceManager;
+    private Interceptor next;
+    
+    public CRUDInvoker(Operation operation, ResourceManager resourceManager) {
+        this.operation = operation;
+        this.resourceManager = resourceManager;
+    }
+    
+    public Message invoke(Message msg) throws InvocationRuntimeException {
+        try {
+            Object resp = doTheWork((Object[])msg.getBody());
+            msg.setBody(resp);
+        } catch (InvocationTargetException e) {
+            msg.setBodyWithFault(e.getCause());
+        }
+        return msg;
+    }
+
+    public Object doTheWork(Object[] args) throws InvocationTargetException {
+        if (operation.getName().equals("create")) {
+            return resourceManager.createResource(args[0]);
+            
+        } else if (operation.getName().equals("retrieve")) {
+            return resourceManager.retrieveResource((String)args[0]);
+            
+        } else if (operation.getName().equals("update")) {
+            return resourceManager.updateResource((String)args[0], args[1]);
+            
+        } else if (operation.getName().equals("delete")) {
+            resourceManager.deleteResource((String)args[0]);
+            return null;
+            
+        } else {
+            return null;
+        }
+    }
+
+    public boolean isOptimizable() {
+        return false;
+    }
+
+    public Interceptor getNext() {
+        return next;
+    }
+
+    public void setNext(Interceptor next) {
+        this.next = next;
+    }
+}

Propchange: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.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


Mime
View raw message