From 82df55ba981ff028bdf376f333d6e1e2cfee3644 Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 30 Sep 2009 11:14:44 +0000 Subject: Tag for 1.5.1-RC3 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@820247 13f79535-47bb-0310-9956-ffa450edef68 --- .../samples/implementation-crud-extension/README | 83 +++++++++++++++ .../implementation-crud-extension/build.xml | 51 +++++++++ .../samples/implementation-crud-extension/pom.xml | 77 ++++++++++++++ .../src/main/java/crud/CRUD.java | 54 ++++++++++ .../src/main/java/crud/CRUDImplementation.java | 50 +++++++++ .../main/java/crud/CRUDImplementationFactory.java | 37 +++++++ .../main/java/crud/backend/ResourceManager.java | 90 ++++++++++++++++ .../crud/impl/CRUDImplementationFactoryImpl.java | 47 +++++++++ .../java/crud/impl/CRUDImplementationImpl.java | 117 +++++++++++++++++++++ .../crud/provider/CRUDImplementationInvoker.java | 79 ++++++++++++++ .../crud/provider/CRUDImplementationProvider.java | 75 +++++++++++++ .../CRUDImplementationProviderFactory.java | 51 +++++++++ .../services/crud.CRUDImplementationFactory | 19 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 ++++ ...any.sca.contribution.processor.ValidationSchema | 19 ++++ ...cany.sca.provider.ImplementationProviderFactory | 19 ++++ .../main/resources/sample-implementation-crud.xsd | 38 +++++++ .../src/test/java/crud/CRUDTestCase.java | 60 +++++++++++ .../src/test/resources/crud.composite | 30 ++++++ 19 files changed, 1015 insertions(+) create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/README create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/build.xml create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/pom.xml create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUD.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationFactoryImpl.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationInvoker.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/crud.CRUDImplementationFactory create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/sample-implementation-crud.xsd create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java create mode 100644 tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/test/resources/crud.composite (limited to 'tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension') diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/README b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/README new file mode 100644 index 0000000000..5e8190648f --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/README @@ -0,0 +1,83 @@ +Implementation CRUD Sample +========================== +This sample demonstrates how new implementation types are constructed for +Apache Tuscany SCA. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you want to try out the CRUD implementation type that this sample provides +please see the implementation-crud sample that provides the necessary client +code to bring up an application that uses this implementation extension. + +Sample Overview +--------------- +This sample contains a CRUD implementation type as an example of how to create +new implementation types. Components using this implementation type always +expose the same Create, Retrieve, Update and Delete interface. This sample +uses a singleton ResourceManager to perform the CRUD operations but of course +a real component would provide a real implementation. + +implementation-crud-extension/ + src/ + main/ + java/ + crud/ - implementation model interfaces + backend/ - fake component implementation + impl/ - implementations of the model interfaces + provider/ - runtime implementation + resources/ + META-INF/ + services/ - declares the extension + test/ + java/ + crud/ + CRUDTestCase.java - JUnit test case + resources/ + crud.composite - the SCA assembly used during unit testing + + build.xml - the Ant build file + pom.xml - the Maven build file + +Building The Sample Extension Using Ant +----------------------------------------- +With the binary distribution the sample extension can be built using Ant as +follows + +cd implementation-crud-extension +ant compile + +See the implementation-crud sample to run a sample that uses this +implementation extension. + +Building The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built +using Maven as follows. + +cd implementation-crud-extension +mvn + +Maven will also test that the sample extension built properly. You should see +the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running crud.CRUDTestCase +Starting CRUDServiceComponent +create(ABC) in tmp +retrieve(0) +update(0) +retrieve(0) +delete(0) +retrieve(0) +Stopping CRUDServiceComponent +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.212 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/build.xml b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/build.xml new file mode 100644 index 0000000000..88d308e6fc --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/pom.xml b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/pom.xml new file mode 100644 index 0000000000..fcf046ae55 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/pom.xml @@ -0,0 +1,77 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.5.1 + ../../pom.xml + + sample-implementation-crud-extension + Apache Tuscany SCA Sample CRUD Implementation Extension + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-assembly + 1.5.1 + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 1.5.1 + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.5.1 + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.5.1 + test + + + + junit + junit + 4.5 + test + + + + + + ${artifactId} + + + diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUD.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUD.java new file mode 100644 index 0000000000..b23d85887b --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUD.java @@ -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 crud; + +/** + * The service interface of the single CRUD service provided by CRUD components. + */ +public interface CRUD { + + /** + * Create a new resource. + * @param resource + * @return + */ + String create(Object resource); + + /** + * Retrieve a resource. + * @param id + * @return + */ + Object retrieve(String id); + + /** + * Update a resource. + * @param id + * @param resource + * @return + */ + Object update(String id, Object resource); + + /** + * Delete a resource. + * @param id + */ + void delete(String id); + +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java new file mode 100644 index 0000000000..49be844f93 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java @@ -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 crud; + +import org.apache.tuscany.sca.assembly.Implementation; + +/** + * 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 + */ +public interface CRUDImplementation extends Implementation { + + /** + * Returns the directory used by CRUD implementations to persist resources. + * + * @return the directory used to persist resources + */ + public String getDirectory(); + + /** + * Sets the directory used by CRUD implementations to persist resources. + * + * @param directory the directory used to persist resources + */ + public void setDirectory(String directory); + +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java new file mode 100644 index 0000000000..fa83c63c1b --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java @@ -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 crud; + +import crud.CRUDImplementation; + + +/** + * A factory for the sample CRUD implementation model. + */ +public interface CRUDImplementationFactory { + + /** + * Creates a new CRUD implementation. + * + * @return + */ + CRUDImplementation createCRUDImplementation(); + +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java new file mode 100644 index 0000000000..cc0795a735 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java @@ -0,0 +1,90 @@ +/* + * 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.backend; + +import java.util.HashMap; +import java.util.Map; + +/** + * A fake resource manager implementation used as a backend by the sample + * CRUD component implementation. + */ +public class ResourceManager { + private static int counter; + private static final Map store = new HashMap(); + private String directory; + + /** + * Constructs a new resource manager. + * + * @param directory the directory where to persist resources + */ + public ResourceManager(String directory) { + super(); + this.directory = directory; + } + + /** + * Creates a new resource. + * + * @param resource + * @return + */ + public String createResource(Object resource) { + System.out.println("create(" + resource + ") in " + directory); + String key = String.valueOf(counter++); + store.put(key, resource); + return key; + } + + /** + * Deletes a resource. + * + * @param id + */ + public void deleteResource(String id) { + System.out.println("delete(" + id + ")"); + store.remove(id); + } + + /** + * Retrieves a resource. + * + * @param id + * @return + */ + public Object retrieveResource(String id) { + System.out.println("retrieve(" + id + ")"); + return store.get(id); + } + + /** + * Updates a resource. + * + * @param id + * @param resource + * @return + */ + public Object updateResource(String id, Object resource) { + System.out.println("update(" + id + ")"); + return store.put(id, resource); + } + +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationFactoryImpl.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationFactoryImpl.java new file mode 100644 index 0000000000..2f1e5fcba8 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationFactoryImpl.java @@ -0,0 +1,47 @@ +/* + * 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.impl; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + +import crud.CRUDImplementation; +import crud.CRUDImplementationFactory; + + +/** + * A factory for the CRUD implementation model. + */ +public class CRUDImplementationFactoryImpl implements CRUDImplementationFactory { + + private AssemblyFactory assemblyFactory; + private JavaInterfaceFactory javaFactory; + + public CRUDImplementationFactoryImpl(ModelFactoryExtensionPoint modelFactories) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + } + + public CRUDImplementation createCRUDImplementation() { + return new CRUDImplementationImpl(assemblyFactory, javaFactory); + } + +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java new file mode 100644 index 0000000000..383a035e69 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java @@ -0,0 +1,117 @@ +/* + * 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.impl; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + +import crud.CRUD; +import crud.CRUDImplementation; + + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + */ +class CRUDImplementationImpl implements CRUDImplementation { + + private Service crudService; + private String directory; + + /** + * Constructs a new CRUD implementation. + */ + CRUDImplementationImpl(AssemblyFactory assemblyFactory, + JavaInterfaceFactory javaFactory) { + + // 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 = javaFactory.createJavaInterface(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 getProperties() { + // The sample CRUD implementation does not support properties + return Collections.emptyList(); + } + + public List getServices() { + // The sample CRUD implementation provides a single fixed CRUD service + return Collections.singletonList(crudService); + } + + public List 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 boolean isUnresolved() { + // The sample CRUD implementation is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample CRUD implementation is always resolved + } + +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationInvoker.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationInvoker.java new file mode 100644 index 0000000000..b212ee3c9b --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationInvoker.java @@ -0,0 +1,79 @@ +/* + * 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.provider; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import crud.backend.ResourceManager; + + +/** + * Implements an invoker for CRUD component implementations. + * + * The invoker is responsible for handling invocations of a business operation. + * Input business data is passed to the invoke method in a Message object. + * The invoke method is responsible for handling the invocation and returning a Message with + * the output business data. + * + * In this example we are simply delegating the CRUD operation invocations to the + * corresponding methods on our fake resource manager class. + * + * More sophisticated invokers can delegate the invocation to an implementation artifact directly + * (for example a Java class using reflection as in the implementation-pojo sample) or call a runtime + * engine like a BPEL engine or an XQuery engine for example (this is what the Tuscany + * implementation-bpel and implementation-xquery extensions do). + */ +class CRUDImplementationInvoker implements Invoker { + private Operation operation; + private ResourceManager resourceManager; + + CRUDImplementationInvoker(Operation operation, ResourceManager resourceManager) { + this.operation = operation; + this.resourceManager = resourceManager; + } + + public Message invoke(Message msg) { + try { + Object[] args = msg.getBody(); + Object resp = null; + + if (operation.getName().equals("create")) { + resp = resourceManager.createResource(args[0]); + + } else if (operation.getName().equals("retrieve")) { + resp = resourceManager.retrieveResource((String)args[0]); + + } else if (operation.getName().equals("update")) { + resp = resourceManager.updateResource((String)args[0], args[1]); + + } else if (operation.getName().equals("delete")) { + resourceManager.deleteResource((String)args[0]); + } + + msg.setBody(resp); + } catch (Exception e) { + msg.setFaultBody(e.getCause()); + } + return msg; + } + +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java new file mode 100644 index 0000000000..8f11f9d910 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java @@ -0,0 +1,75 @@ +/* + * 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.provider; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +import crud.CRUDImplementation; +import crud.backend.ResourceManager; + + +/** + * An implementation provider for sample CRUD implementations. + * + * The implementation provider is responsible for handling the lifecycle of a component + * implementation and creating operation invokers for the service operations provided + * by the implementation. + * + * The start() and stop() methods are called when a component is started + * and stopped. + * + * The createInvoker method is called for each operation provided by the component + * implementation. The implementation provider can create an invoker and initialize it + * at that time to minimize the amount of work to be performed on each invocation. + */ +class CRUDImplementationProvider implements ImplementationProvider { + + private RuntimeComponent component; + private CRUDImplementation implementation; + + /** + * Constructs a new CRUD implementation. + */ + CRUDImplementationProvider(RuntimeComponent component, CRUDImplementation implementation) { + this.component = component; + this.implementation = implementation; + } + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + CRUDImplementationInvoker invoker = new CRUDImplementationInvoker(operation, new ResourceManager(implementation.getDirectory())); + return invoker; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + System.out.println("Starting " + component.getName()); + } + + public void stop() { + System.out.println("Stopping " + component.getName()); + } + +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java new file mode 100644 index 0000000000..4566cb7155 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java @@ -0,0 +1,51 @@ +/* + * 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.provider; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +import crud.CRUDImplementation; +import crud.provider.CRUDImplementationProvider; + + +/** + * A factory for CRUD implementation providers. + * + * The factory is called to create an implementation provider for each component using + * the CRUD implementation. + */ +public class CRUDImplementationProviderFactory implements ImplementationProviderFactory { + + /** + * Constructs a new CRUD implementation. + */ + public CRUDImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { + } + + public ImplementationProvider createImplementationProvider(RuntimeComponent component, CRUDImplementation implementation) { + return new CRUDImplementationProvider(component, implementation); + } + + public Class getModelType() { + return CRUDImplementation.class; + } +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/crud.CRUDImplementationFactory b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/crud.CRUDImplementationFactory new file mode 100644 index 0000000000..3cf5de5fa1 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/crud.CRUDImplementationFactory @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the implementation model factory +crud.impl.CRUDImplementationFactoryImpl diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..17c98cf706 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://crud#implementation.crud,model=crud.CRUDImplementation,factory=crud.CRUDImplementationFactory diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema new file mode 100644 index 0000000000..527c626418 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema @@ -0,0 +1,19 @@ +# 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. + +# URI of the XML schema to be used for validation +sample-implementation-crud.xsd diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..6ce605197a --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -0,0 +1,19 @@ +# 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. + +# Implementation class for the implementation extension +crud.provider.CRUDImplementationProviderFactory;model=crud.CRUDImplementation diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/sample-implementation-crud.xsd b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/sample-implementation-crud.xsd new file mode 100644 index 0000000000..447e31bf93 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/main/resources/sample-implementation-crud.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java new file mode 100644 index 0000000000..0bb5cfc361 --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java @@ -0,0 +1,60 @@ +/* + * 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 junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import crud.CRUD; + +/** + * Tests the CRUD implementation extension. + */ +public class CRUDTestCase extends TestCase { + + private SCADomain scaDomain; + private CRUD crudService; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("crud.composite"); + crudService = scaDomain.getService(CRUD.class, "CRUDServiceComponent"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testCRUD() throws Exception { + String id = crudService.create("ABC"); + Object result = crudService.retrieve(id); + assertEquals("ABC", result); + + crudService.update(id, "EFG"); + result = crudService.retrieve(id); + assertEquals("EFG", result); + + crudService.delete(id); + result = crudService.retrieve(id); + assertNull(result); + } +} diff --git a/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/test/resources/crud.composite b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/test/resources/crud.composite new file mode 100644 index 0000000000..18745033bb --- /dev/null +++ b/tags/java/sca/1.5.1-RC3/samples/implementation-crud-extension/src/test/resources/crud.composite @@ -0,0 +1,30 @@ + + + + + + + + + -- cgit v1.2.3