From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../implementation-crud-extension/DISCLAIMER | 8 + .../samples/implementation-crud-extension/LICENSE | 205 +++++++++++++++++++++ .../samples/implementation-crud-extension/NOTICE | 6 + .../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 | 48 +++++ .../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 | 71 +++++++ .../crud/provider/CRUDImplementationProvider.java | 70 +++++++ .../CRUDImplementationProviderFactory.java | 54 ++++++ .../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 | 67 +++++++ .../src/test/resources/crud.composite | 30 +++ 22 files changed, 1229 insertions(+) create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/DISCLAIMER create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/LICENSE create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/NOTICE create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/README create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/build.xml create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/pom.xml create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUD.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationFactoryImpl.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationInvoker.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/META-INF/services/crud.CRUDImplementationFactory create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/sample-implementation-crud.xsd create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java create mode 100644 branches/sca-java-1.0.1/samples/implementation-crud-extension/src/test/resources/crud.composite (limited to 'branches/sca-java-1.0.1/samples/implementation-crud-extension') diff --git a/branches/sca-java-1.0.1/samples/implementation-crud-extension/DISCLAIMER b/branches/sca-java-1.0.1/samples/implementation-crud-extension/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/branches/sca-java-1.0.1/samples/implementation-crud-extension/LICENSE b/branches/sca-java-1.0.1/samples/implementation-crud-extension/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/branches/sca-java-1.0.1/samples/implementation-crud-extension/NOTICE b/branches/sca-java-1.0.1/samples/implementation-crud-extension/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-1.0.1/samples/implementation-crud-extension/README b/branches/sca-java-1.0.1/samples/implementation-crud-extension/README new file mode 100644 index 0000000000..5e8190648f --- /dev/null +++ b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/samples/implementation-crud-extension/build.xml b/branches/sca-java-1.0.1/samples/implementation-crud-extension/build.xml new file mode 100644 index 0000000000..88d308e6fc --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.0.1/samples/implementation-crud-extension/pom.xml b/branches/sca-java-1.0.1/samples/implementation-crud-extension/pom.xml new file mode 100644 index 0000000000..50d2f21cfc --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/pom.xml @@ -0,0 +1,77 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.0.1-incubating-SNAPSHOT + ../../pom.xml + + sample-implementation-crud-extension + Apache Tuscany SCA CRUD Implementation Extension Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0.1-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 1.0.1-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0.1-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.0.1-incubating-SNAPSHOT + test + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUD.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUD.java new file mode 100644 index 0000000000..b23d85887b --- /dev/null +++ b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java new file mode 100644 index 0000000000..5cb2bd2b1c --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package 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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java new file mode 100644 index 0000000000..fa83c63c1b --- /dev/null +++ b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java new file mode 100644 index 0000000000..cc0795a735 --- /dev/null +++ b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationFactoryImpl.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationFactoryImpl.java new file mode 100644 index 0000000000..7f9f8da674 --- /dev/null +++ b/branches/sca-java-1.0.1/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 default 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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java new file mode 100644 index 0000000000..383a035e69 --- /dev/null +++ b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationInvoker.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationInvoker.java new file mode 100644 index 0000000000..f37d9f0c1d --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationInvoker.java @@ -0,0 +1,71 @@ +/* + * 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 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. + */ +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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java new file mode 100644 index 0000000000..450bc8a928 --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java @@ -0,0 +1,70 @@ +/* + * 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; + + +/** + * 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 + */ +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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java new file mode 100644 index 0000000000..d0166d649b --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.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.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; + + +/** + * 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 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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/META-INF/services/crud.CRUDImplementationFactory b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/META-INF/services/crud.CRUDImplementationFactory new file mode 100644 index 0000000000..3cf5de5fa1 --- /dev/null +++ b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/sample-implementation-crud.xsd b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/sample-implementation-crud.xsd new file mode 100644 index 0000000000..447e31bf93 --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/main/resources/sample-implementation-crud.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java new file mode 100644 index 0000000000..999ec4bdb6 --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java @@ -0,0 +1,67 @@ +/* + * 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 service + */ +public class CRUDTestCase extends TestCase { + + private SCADomain scaDomain; + private CRUD crudService; + + /** + * @throws java.lang.Exception + */ + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("crud.composite"); + crudService = scaDomain.getService(CRUD.class, "CRUDServiceComponent"); + } + + /** + * @throws java.lang.Exception + */ + @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/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/test/resources/crud.composite b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/test/resources/crud.composite new file mode 100644 index 0000000000..18745033bb --- /dev/null +++ b/branches/sca-java-1.0.1/samples/implementation-crud-extension/src/test/resources/crud.composite @@ -0,0 +1,30 @@ + + + + + + + + + -- cgit v1.2.3