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/05/07 04:22:42 UTC

svn commit: r535714 - /incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/

Author: jsdelfino
Date: Sun May  6 19:22:42 2007
New Revision: 535714

URL: http://svn.apache.org/viewvc?view=rev&rev=535714
Log:
Cleaned up the sample CRUD component implementation type used in the test cases.

Added:
    incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationFactory.java   (with props)
    incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationImpl.java   (with props)
    incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProvider.java   (with props)
    incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDInvoker.java   (with props)
    incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/DefaultCRUDImplementationFactory.java   (with props)
Removed:
    incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDTargetInvoker.java

Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationFactory.java?view=auto&rev=535714
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationFactory.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationFactory.java Sun May  6 19:22:42 2007
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * A factory for the sample CRUD implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CRUDImplementationFactory {
+    
+    /**
+     * Creates a new CRUD implementation.
+     * 
+     * @return
+     */
+    CRUDImplementation createCRUDImplementation();
+
+}

Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationImpl.java?view=auto&rev=535714
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationImpl.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationImpl.java Sun May  6 19:22:42 2007
@@ -0,0 +1,135 @@
+/*
+ * 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.util.Collections;
+import java.util.List;
+
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.assembly.ConstrainingType;
+import org.apache.tuscany.assembly.Property;
+import org.apache.tuscany.assembly.Reference;
+import org.apache.tuscany.assembly.Service;
+import org.apache.tuscany.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.interfacedef.java.JavaInterfaceFactory;
+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;
+
+/**
+ * The model representing a sample CRUD implementation in an SCA assembly model.
+ * 
+ * @version $$Rev$$ $$Date: 2007-04-23 19:18:54 -0700 (Mon, 23 Apr
+ *          2007) $$
+ */
+public class CRUDImplementationImpl implements CRUDImplementation {
+
+    private Service crudService;
+    private String directory;
+
+    /**
+     * Constructs a new CRUD implementation.
+     */
+    public CRUDImplementationImpl(AssemblyFactory assemblyFactory,
+                              JavaInterfaceFactory javaFactory,
+                              JavaInterfaceIntrospector introspector) {
+
+        // CRUD implementation always provide a single service exposing
+        // the CRUD interface, and have no references and properties
+        crudService = assemblyFactory.createService();
+        crudService.setName("CRUD");
+        JavaInterface javaInterface;
+        try {
+            javaInterface = introspector.introspect(CRUD.class);
+        } catch (InvalidInterfaceException e) {
+            throw new IllegalArgumentException(e);
+        }
+        JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+        interfaceContract.setInterface(javaInterface);
+        crudService.setInterfaceContract(interfaceContract);
+    }
+
+    public String getDirectory() {
+        return directory;
+    }
+
+    public void setDirectory(String directory) {
+        this.directory = directory;
+    }
+
+    public ConstrainingType getConstrainingType() {
+        // The sample CRUD implementation does not support constrainingTypes
+        return null;
+    }
+
+    public List<Property> getProperties() {
+        // The sample CRUD implementation does not support properties
+        return Collections.emptyList();
+    }
+
+    public List<Service> getServices() {
+        // The sample CRUD implementation provides a single fixed CRUD service
+        return Collections.singletonList(crudService);
+    }
+    
+    public List<Reference> getReferences() {
+        // The sample CRUD implementation does not support properties
+        return Collections.emptyList();
+    }
+
+    public String getURI() {
+        // The sample CRUD implementation does not have a URI
+        return null;
+    }
+
+    public void setConstrainingType(ConstrainingType constrainingType) {
+        // The sample CRUD implementation does not support constrainingTypes
+    }
+
+    public void setURI(String uri) {
+        // The sample CRUD implementation does not have a URI
+    }
+
+    public List<PolicySet> getPolicySets() {
+        // The sample CRUD implementation does not support policy sets
+        return Collections.emptyList();
+    }
+
+    public List<Intent> getRequiredIntents() {
+        // The sample CRUD implementation does not support intents
+        return Collections.emptyList();
+    }
+
+    public List<Object> getExtensions() {
+        // The sample CRUD implementation does not support extensions
+        return Collections.emptyList();
+    }
+
+    public boolean isUnresolved() {
+        // The sample CRUD implementation is always resolved
+        return false;
+    }
+
+    public void setUnresolved(boolean unresolved) {
+        // The sample CRUD implementation is always resolved
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProvider.java?view=auto&rev=535714
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProvider.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProvider.java Sun May  6 19:22:42 2007
@@ -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 crud;
+
+import org.apache.tuscany.assembly.AssemblyFactory;
+import org.apache.tuscany.core.ImplementationActivator;
+import org.apache.tuscany.core.ImplementationProvider;
+import org.apache.tuscany.core.RuntimeComponent;
+import org.apache.tuscany.core.RuntimeComponentService;
+import org.apache.tuscany.interfacedef.InterfaceContract;
+import org.apache.tuscany.interfacedef.Operation;
+import org.apache.tuscany.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.interfacedef.java.introspect.JavaInterfaceIntrospector;
+import org.apache.tuscany.invocation.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 CRUDImplementationImpl implements ImplementationProvider,
+    ImplementationActivator {
+
+    /**
+     * Constructs a new CRUD implementation.
+     */
+    public CRUDImplementationProvider(AssemblyFactory assemblyFactory,
+                                      JavaInterfaceFactory javaFactory,
+                                      JavaInterfaceIntrospector introspector) {
+        super(assemblyFactory, javaFactory, introspector);
+    }
+
+    public Interceptor createInterceptor(RuntimeComponent component, RuntimeComponentService service, Operation operation) {
+        CRUDInvoker invoker = new CRUDInvoker(operation, new ResourceManager(getDirectory()));
+        return invoker;
+    }
+
+    public Interceptor createCallbackInterceptor(RuntimeComponent component, Operation operation) {
+        CRUDImplementation impl = (CRUDImplementation)component.getImplementation();
+        CRUDInvoker invoker = new CRUDInvoker(operation, new ResourceManager(impl.getDirectory()));
+        return invoker;
+    }
+
+    public InterfaceContract getImplementationInterfaceContract(RuntimeComponentService 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/modules/host-embedded/src/test/java/crud/CRUDImplementationProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDImplementationProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDInvoker.java?view=auto&rev=535714
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDInvoker.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDInvoker.java Sun May  6 19:22:42 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.invocation.Interceptor;
+import org.apache.tuscany.invocation.InvocationRuntimeException;
+import org.apache.tuscany.invocation.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;
+    
+    public CRUDInvoker(Operation operation, ResourceManager resourceManager) {
+        this.operation = operation;
+        this.resourceManager = resourceManager;
+    }
+    
+    public Message invoke(Message msg) throws InvocationRuntimeException {
+        try {
+            Object[] args = msg.getBody();
+            Object resp = doTheWork(args);
+            msg.setBody(resp);
+        } catch (InvocationTargetException e) {
+            msg.setFaultBody(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 null;
+    }
+
+    public void setNext(Interceptor next) {
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/CRUDInvoker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/DefaultCRUDImplementationFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/DefaultCRUDImplementationFactory.java?view=auto&rev=535714
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/DefaultCRUDImplementationFactory.java (added)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/DefaultCRUDImplementationFactory.java Sun May  6 19:22:42 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.interfacedef.java.introspect.JavaInterfaceIntrospector;
+
+/**
+ * A default factory for the CRUD implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultCRUDImplementationFactory implements CRUDImplementationFactory {
+    
+    private AssemblyFactory assemblyFactory;
+    private JavaInterfaceFactory javaFactory;
+    private JavaInterfaceIntrospector introspector;
+    
+    public DefaultCRUDImplementationFactory(AssemblyFactory assemblyFactory,
+                                            JavaInterfaceFactory javaFactory,
+                                            JavaInterfaceIntrospector introspector) {
+        this.assemblyFactory = assemblyFactory;
+        this.javaFactory = javaFactory;
+        this.introspector = introspector;
+    }
+
+    public CRUDImplementation createCRUDImplementation() {
+        return new CRUDImplementationProvider(assemblyFactory, javaFactory, introspector);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/DefaultCRUDImplementationFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/host-embedded/src/test/java/crud/DefaultCRUDImplementationFactory.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