diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /tags/java/tsss-demo/kernel/spi |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tags/java/tsss-demo/kernel/spi')
330 files changed, 24510 insertions, 0 deletions
diff --git a/tags/java/tsss-demo/kernel/spi/.checkstyle b/tags/java/tsss-demo/kernel/spi/.checkstyle new file mode 100644 index 0000000000..3e57539570 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/.checkstyle @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<fileset-config file-format-version="1.2.0" simple-config="true"> + <fileset name="all" enabled="true" check-config-name="Tuscany Checks" local="false"> + <file-match-pattern match-pattern="." include-pattern="true"/> + </fileset> +</fileset-config> diff --git a/tags/java/tsss-demo/kernel/spi/.pmd b/tags/java/tsss-demo/kernel/spi/.pmd new file mode 100644 index 0000000000..ffc4fe2bbb --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/.pmd @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<pmd><useProjectRuleSet>true</useProjectRuleSet><rules/></pmd> diff --git a/tags/java/tsss-demo/kernel/spi/.ruleset b/tags/java/tsss-demo/kernel/spi/.ruleset new file mode 100644 index 0000000000..3886f07f2d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/.ruleset @@ -0,0 +1,190 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<ruleset name="pmd-eclipse"> + <description>PMD Plugin preferences rule set</description> + + + <rule ref="rulesets/basic.xml/BooleanInstantiation"/> + <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/> + <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/> +<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>--> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/> +<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>--> + <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/> + <rule ref="rulesets/basic.xml/JumbledIncrementer"/> +<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>--> + <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/> + <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/> + <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/> + <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/> + <rule ref="rulesets/basic.xml/UnnecessaryReturn"/> +<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>--> + +<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>--> + +<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>--> +<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>--> +<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>--> + +<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>--> +<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>--> + +<rule ref="rulesets/controversial.xml/AssignmentInOperand"/> +<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>--> +<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>--> +<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>--> +<!--<rule ref="rulesets/controversial.xml/SingularField"/>--> +<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>--> +<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>--> +<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/> +<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>--> + +<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>--> +<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>--> +<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>--> + +<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>--> +<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>--> +<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>--> +<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>--> +<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>--> +<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/> +<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>--> +<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>--> +<!--<rule ref="rulesets/design.xml/BadComparison"/>--> +<!--<rule ref="rulesets/design.xml/CloseConnection"/>--> +<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>--> +<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>--> +<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/> +<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>--> +<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>--> +<rule ref="rulesets/design.xml/IdempotentOperations"/> +<!--<rule ref="rulesets/design.xml/ImmutableField"/>--> +<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>--> +<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>--> +<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>--> +<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>--> +<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>--> +<rule ref="rulesets/design.xml/OptimizableToArrayCall"/> +<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/> +<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/> +<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/> +<rule ref="rulesets/design.xml/SimplifyConditional"/> +<!--<rule ref="rulesets/design.xml/SwitchDensity"/>--> +<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>--> +<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/> +<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>--> +<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>--> +<!--<rule ref="rulesets/design.xml/UseSingleton"/>--> + +<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>--> +<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>--> + +<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>--> +<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>--> +<!--<rule ref="rulesets/imports.xml/UnusedImports"/>--> +<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>--> + +<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>--> +<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>--> + +<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>--> +<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>--> +<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>--> + + <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>--> + <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>--> + + <!--<rule ref="rulesets/naming.xml/ShortVariable"/>--> + <!--<rule ref="rulesets/naming.xml/LongVariable"/>--> + <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>--> + <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>--> + <!--<rule ref="rulesets/naming.xml/NoPackage"/>--> + <!--<rule ref="rulesets/naming.xml/PackageCase"/>--> + + <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>--> + <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>--> + + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>--> + <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>--> + <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>--> + + <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>--> + <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>--> + <!--<rule ref="rulesets/strings.xml/StringToString"/>--> + <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>--> + <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>--> + + <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>--> + <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>--> + + <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/> + <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>--> + +</ruleset> diff --git a/tags/java/tsss-demo/kernel/spi/LICENSE.txt b/tags/java/tsss-demo/kernel/spi/LICENSE.txt new file mode 100644 index 0000000000..0084319535 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/LICENSE.txt @@ -0,0 +1,202 @@ + + 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, serviceDefinition 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/tags/java/tsss-demo/kernel/spi/NOTICE.txt b/tags/java/tsss-demo/kernel/spi/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +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. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/tsss-demo/kernel/spi/pom.xml b/tags/java/tsss-demo/kernel/spi/pom.xml new file mode 100644 index 0000000000..e622672898 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/pom.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>kernel</artifactId> + <version>2.0-alpha2-incubating-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <name>Apache Tuscany SCA SPI</name> + <description>Tuscany Service Provider Interfaces.</description> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-host-api</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>stax</groupId> + <artifactId>stax-api</artifactId> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + </dependency> + + <dependency> + <groupId>org.codehaus.woodstox</groupId> + <artifactId>wstx-asl</artifactId> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + </dependency> + + </dependencies> +</project> diff --git a/tags/java/tsss-demo/kernel/spi/src/doc/Context Model.emx b/tags/java/tsss-demo/kernel/spi/src/doc/Context Model.emx new file mode 100644 index 0000000000..0445ea5a6b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/doc/Context Model.emx @@ -0,0 +1,673 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<!--xtools2_universal_type_manager-->
+<uml:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:notation="http://www.ibm.com/xtools/1.5.0/Notation" xmlns:uml="http://www.eclipse.org/uml2/1.0.0/UML" xmlns:umlnotation="http://www.ibm.com/xtools/1.5.0/Umlnotation" xmi:id="_al1S8NovEdqRBPR5WyT36A" name="Context Model" appliedProfile="_al1S9NovEdqRBPR5WyT36A _al1S99ovEdqRBPR5WyT36A _al1S-tovEdqRBPR5WyT36A _al1S_dovEdqRBPR5WyT36A _al1TANovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S8dovEdqRBPR5WyT36A" source="uml2.diagrams" references="_al1S8tovEdqRBPR5WyT36A">
+ <contents xmi:type="notation:Diagram" xmi:id="_al1S8tovEdqRBPR5WyT36A" type="Class" name="Main">
+ <children xmi:id="_ePDcYdovEdqRBPR5WyT36A" sourceEdges="_Fd3lQdowEdqRBPR5WyT36A _R5Rjwdo1EdqRBPR5WyT36A _pdfmkNo2EdqRBPR5WyT36A" targetEdges="_hmIF4dovEdqRBPR5WyT36A _mu9A4dovEdqRBPR5WyT36A _pe3jwNovEdqRBPR5WyT36A" element="_ePDcYNovEdqRBPR5WyT36A">
+ <children xmi:id="_ePJjANovEdqRBPR5WyT36A" type="ImageCompartment" element="_ePDcYNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_ePJjAdovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_ePJjAtovEdqRBPR5WyT36A" type="Stereotype" element="_ePDcYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ePJjA9ovEdqRBPR5WyT36A" type="Kind" element="_ePDcYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ePJjBNovEdqRBPR5WyT36A" type="Name" element="_ePDcYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ePJjBdovEdqRBPR5WyT36A" type="AttributeCompartment" element="_ePDcYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ePJjBtovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_ePJjB9ovEdqRBPR5WyT36A" type="OperationCompartment" element="_ePDcYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ePJjCNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_ePJjCdovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_ePDcYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ePJjCtovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_ePDcYtovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_ePDcY9ovEdqRBPR5WyT36A" x="6693" y="3545"/>
+ </children>
+ <children xmi:id="_fs1pANovEdqRBPR5WyT36A" sourceEdges="_hmIF4dovEdqRBPR5WyT36A _pe3jwNovEdqRBPR5WyT36A" targetEdges="_xInjYdovEdqRBPR5WyT36A" element="_fsviYNovEdqRBPR5WyT36A">
+ <children xmi:id="_fs1pA9ovEdqRBPR5WyT36A" type="ImageCompartment" element="_fsviYNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_fs1pBNovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_fs1pBdovEdqRBPR5WyT36A" type="Stereotype" element="_fsviYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_fs1pBtovEdqRBPR5WyT36A" type="Kind" element="_fsviYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_fs1pB9ovEdqRBPR5WyT36A" type="Name" element="_fsviYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_fs1pCNovEdqRBPR5WyT36A" type="AttributeCompartment" element="_fsviYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_fs1pCdovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_fs1pCtovEdqRBPR5WyT36A" type="OperationCompartment" element="_fsviYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_fs1pC9ovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_fs1pDNovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_fsviYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_fs1pDdovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_fs1pAdovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_fs1pAtovEdqRBPR5WyT36A" x="2226" y="8268"/>
+ </children>
+ <children xmi:id="_ikr_4NovEdqRBPR5WyT36A" sourceEdges="_mu9A4dovEdqRBPR5WyT36A" element="_ikl5QNovEdqRBPR5WyT36A">
+ <children xmi:id="_ikr_49ovEdqRBPR5WyT36A" type="ImageCompartment" element="_ikl5QNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_ikr_5NovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_ikr_5dovEdqRBPR5WyT36A" type="Stereotype" element="_ikl5QNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ikr_5tovEdqRBPR5WyT36A" type="Kind" element="_ikl5QNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ikr_59ovEdqRBPR5WyT36A" type="Name" element="_ikl5QNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ikr_6NovEdqRBPR5WyT36A" type="AttributeCompartment" element="_ikl5QNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ikr_6dovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_ikr_6tovEdqRBPR5WyT36A" type="OperationCompartment" element="_ikl5QNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ikr_69ovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_ikr_7NovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_ikl5QNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ikr_7dovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_ikr_4dovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_ikr_4tovEdqRBPR5WyT36A" x="9222" y="8268"/>
+ </children>
+ <children xmi:id="_tZF9odovEdqRBPR5WyT36A" sourceEdges="_xInjYdovEdqRBPR5WyT36A _BkUg0dowEdqRBPR5WyT36A" element="_tZF9oNovEdqRBPR5WyT36A">
+ <children xmi:id="_tZF9pNovEdqRBPR5WyT36A" type="ImageCompartment" element="_tZF9oNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_tZF9pdovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_tZF9ptovEdqRBPR5WyT36A" type="Stereotype" element="_tZF9oNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_tZF9p9ovEdqRBPR5WyT36A" type="Kind" element="_tZF9oNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_tZF9qNovEdqRBPR5WyT36A" type="Name" element="_tZF9oNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_tZF9qdovEdqRBPR5WyT36A" type="AttributeCompartment" element="_tZF9oNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_tZF9qtovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_tZF9q9ovEdqRBPR5WyT36A" type="OperationCompartment" element="_tZF9oNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_tZF9rNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_tZF9rdovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_tZF9oNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_tZF9rtovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_tZF9otovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_tZF9o9ovEdqRBPR5WyT36A" x="2226" y="12084"/>
+ </children>
+ <children xmi:id="_z_m-oNovEdqRBPR5WyT36A" sourceEdges="_cN4xsdo2EdqRBPR5WyT36A" targetEdges="_3Ic-4NovEdqRBPR5WyT36A _9XeF4tovEdqRBPR5WyT36A _Fd3lQdowEdqRBPR5WyT36A" element="_z_g4ANovEdqRBPR5WyT36A">
+ <children xmi:id="_z_m-o9ovEdqRBPR5WyT36A" type="ImageCompartment" element="_z_g4ANovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_z_m-pNovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_z_m-pdovEdqRBPR5WyT36A" type="Stereotype" element="_z_g4ANovEdqRBPR5WyT36A"/>
+ <children xmi:id="_z_m-ptovEdqRBPR5WyT36A" type="Kind" element="_z_g4ANovEdqRBPR5WyT36A"/>
+ <children xmi:id="_z_m-p9ovEdqRBPR5WyT36A" type="Name" element="_z_g4ANovEdqRBPR5WyT36A"/>
+ <children xmi:id="_z_m-qNovEdqRBPR5WyT36A" type="AttributeCompartment" element="_z_g4ANovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_z_m-qdovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_z_m-qtovEdqRBPR5WyT36A" type="OperationCompartment" element="_z_g4ANovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_z_m-q9ovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_z_m-rNovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_z_g4ANovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_z_m-rdovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_z_m-odovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_z_m-otovEdqRBPR5WyT36A" x="17172" y="6996"/>
+ </children>
+ <children xmi:id="_1y-ZsNovEdqRBPR5WyT36A" sourceEdges="_3Ic-4NovEdqRBPR5WyT36A _9-BEUNo2EdqRBPR5WyT36A" targetEdges="_BkUg0dowEdqRBPR5WyT36A" element="_1yyMcNovEdqRBPR5WyT36A">
+ <children xmi:id="_1y-Zs9ovEdqRBPR5WyT36A" type="ImageCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_1y-ZtNovEdqRBPR5WyT36A" width="1320" height="1320"/>
+ </children>
+ <children xmi:id="_1y-ZtdovEdqRBPR5WyT36A" type="Stereotype" element="_1yyMcNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_1y-ZttovEdqRBPR5WyT36A" type="Name" element="_1yyMcNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_1y-Zt9ovEdqRBPR5WyT36A" type="AttributeCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_1y-ZuNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_1y-ZudovEdqRBPR5WyT36A" type="OperationCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_1y-ZutovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_1y-Zu9ovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_1y-ZvNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_1y-ZvdovEdqRBPR5WyT36A" visible="false" type="StructureCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLShapeCompartmentStyle" xmi:id="_1y-ZvtovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLShapeStyle" xmi:id="_1y-ZsdovEdqRBPR5WyT36A" showStereotype="Label"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_1y-ZstovEdqRBPR5WyT36A" x="13992" y="12084"/>
+ </children>
+ <children xmi:id="_4WSrANovEdqRBPR5WyT36A" sourceEdges="_9XeF4tovEdqRBPR5WyT36A _9PaR4No2EdqRBPR5WyT36A" element="_4WMkYNovEdqRBPR5WyT36A">
+ <children xmi:id="_4WSrA9ovEdqRBPR5WyT36A" type="ImageCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_4WSrBNovEdqRBPR5WyT36A" width="1320" height="1320"/>
+ </children>
+ <children xmi:id="_4WSrBdovEdqRBPR5WyT36A" type="Stereotype" element="_4WMkYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_4WSrBtovEdqRBPR5WyT36A" type="Name" element="_4WMkYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_4WSrB9ovEdqRBPR5WyT36A" type="AttributeCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_4WSrCNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_4WSrCdovEdqRBPR5WyT36A" type="OperationCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_4WSrCtovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_4WSrC9ovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_4WSrDNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_4WSrDdovEdqRBPR5WyT36A" visible="false" type="StructureCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLShapeCompartmentStyle" xmi:id="_4WSrDtovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLShapeStyle" xmi:id="_4WSrAdovEdqRBPR5WyT36A" showStereotype="Label"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_4WSrAtovEdqRBPR5WyT36A" x="19716" y="12084"/>
+ </children>
+ <children xmi:id="_o2m3oNo0EdqRBPR5WyT36A" targetEdges="_9PaR4No2EdqRBPR5WyT36A _9-BEUNo2EdqRBPR5WyT36A" element="_o2gxANo0EdqRBPR5WyT36A">
+ <children xmi:id="_o2m3o9o0EdqRBPR5WyT36A" type="ImageCompartment" element="_o2gxANo0EdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_o2m3pNo0EdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_o2m3pdo0EdqRBPR5WyT36A" type="Stereotype" element="_o2gxANo0EdqRBPR5WyT36A"/>
+ <children xmi:id="_o2m3pto0EdqRBPR5WyT36A" type="Kind" element="_o2gxANo0EdqRBPR5WyT36A"/>
+ <children xmi:id="_o2m3p9o0EdqRBPR5WyT36A" type="Name" element="_o2gxANo0EdqRBPR5WyT36A"/>
+ <children xmi:id="_o2m3qNo0EdqRBPR5WyT36A" type="AttributeCompartment" element="_o2gxANo0EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_o2m3qdo0EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_o2m3qto0EdqRBPR5WyT36A" type="OperationCompartment" element="_o2gxANo0EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_o2m3q9o0EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_o2m3rNo0EdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_o2gxANo0EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_o2m3rdo0EdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_o2m3odo0EdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_o2m3oto0EdqRBPR5WyT36A" x="23532" y="6996"/>
+ </children>
+ <children xmi:id="_M0FLkNo1EdqRBPR5WyT36A" targetEdges="_R5Rjwdo1EdqRBPR5WyT36A _V7zlEdo1EdqRBPR5WyT36A" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <children xmi:id="_M0FLk9o1EdqRBPR5WyT36A" type="ImageCompartment" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_M0FLlNo1EdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_M0FLldo1EdqRBPR5WyT36A" type="Stereotype" element="_Mz_E8No1EdqRBPR5WyT36A"/>
+ <children xmi:id="_M0FLlto1EdqRBPR5WyT36A" type="Kind" element="_Mz_E8No1EdqRBPR5WyT36A"/>
+ <children xmi:id="_M0FLl9o1EdqRBPR5WyT36A" type="Name" element="_Mz_E8No1EdqRBPR5WyT36A"/>
+ <children xmi:id="_M0FLmNo1EdqRBPR5WyT36A" type="AttributeCompartment" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_M0FLmdo1EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_M0FLmto1EdqRBPR5WyT36A" type="OperationCompartment" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_M0FLm9o1EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_M0FLnNo1EdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_M0FLndo1EdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_M0FLkdo1EdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_M0FLkto1EdqRBPR5WyT36A" x="6678" y="318"/>
+ </children>
+ <children xmi:id="_TJHbANo1EdqRBPR5WyT36A" sourceEdges="_V7zlEdo1EdqRBPR5WyT36A" targetEdges="_cN4xsdo2EdqRBPR5WyT36A" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <children xmi:id="_TJHbA9o1EdqRBPR5WyT36A" type="ImageCompartment" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_TJHbBNo1EdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_TJHbBdo1EdqRBPR5WyT36A" type="Stereotype" element="_TI7NwNo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_TJHbBto1EdqRBPR5WyT36A" type="Kind" element="_TI7NwNo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_TJHbB9o1EdqRBPR5WyT36A" type="Name" element="_TI7NwNo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_TJHbCNo1EdqRBPR5WyT36A" type="AttributeCompartment" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_TJHbCdo1EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_TJHbCto1EdqRBPR5WyT36A" type="OperationCompartment" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_TJHbC9o1EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_TJHbDNo1EdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_TJHbDdo1EdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_TJHbAdo1EdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_TJHbAto1EdqRBPR5WyT36A" x="16854" y="318"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLDiagramStyle" xmi:id="_al1S89ovEdqRBPR5WyT36A"/>
+ <edges xmi:id="_hmIF4dovEdqRBPR5WyT36A" element="_hmIF4NovEdqRBPR5WyT36A" source="_fs1pANovEdqRBPR5WyT36A" target="_ePDcYdovEdqRBPR5WyT36A">
+ <children xmi:id="_hmIF5NovEdqRBPR5WyT36A" type="NameLabel" element="_hmIF4NovEdqRBPR5WyT36A">
+ <children xmi:id="_hmIF5tovEdqRBPR5WyT36A" type="Stereotype" element="_hmIF4NovEdqRBPR5WyT36A"/>
+ <children xmi:id="_hmIF59ovEdqRBPR5WyT36A" type="Name" element="_hmIF4NovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_hmIF5dovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_hmIF4tovEdqRBPR5WyT36A" routing="Tree" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_hmIF49ovEdqRBPR5WyT36A" points="[26, -31, -110, 148]$[140, -148, 4, 31]"/>
+ </edges>
+ <edges xmi:id="_mu9A4dovEdqRBPR5WyT36A" element="_mu9A4NovEdqRBPR5WyT36A" source="_ikr_4NovEdqRBPR5WyT36A" target="_ePDcYdovEdqRBPR5WyT36A">
+ <children xmi:id="_mu9A5NovEdqRBPR5WyT36A" type="NameLabel" element="_mu9A4NovEdqRBPR5WyT36A">
+ <children xmi:id="_mu9A5tovEdqRBPR5WyT36A" type="Stereotype" element="_mu9A4NovEdqRBPR5WyT36A"/>
+ <children xmi:id="_mu9A59ovEdqRBPR5WyT36A" type="Name" element="_mu9A4NovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_mu9A5dovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_mu9A4tovEdqRBPR5WyT36A" routing="Tree" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_mu9A49ovEdqRBPR5WyT36A" points="[-185, -820, 2937, 3916]$[-185, -3042, 2937, 1694]$[-3255, -3042, -133, 1694]$[-3255, -3916, -133, 820]"/>
+ </edges>
+ <edges xmi:id="_pe3jwNovEdqRBPR5WyT36A" element="_peM1YNovEdqRBPR5WyT36A" source="_fs1pANovEdqRBPR5WyT36A" target="_ePDcYdovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jw9ovEdqRBPR5WyT36A" type="NameLabel" element="_peM1YNovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jxdovEdqRBPR5WyT36A" type="Stereotype" element="_peM1YNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_pe3jxtovEdqRBPR5WyT36A" type="Name" element="_peM1YNovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3jxNovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_pe3jx9ovEdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_peM1YtovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jydovEdqRBPR5WyT36A" type="ToMultiplicity" element="_peM1YtovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3jyNovEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_pe3jytovEdqRBPR5WyT36A" type="ToRoleLabel" element="_peM1YtovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jzNovEdqRBPR5WyT36A" type="ToRole" element="_peM1YtovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3jy9ovEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_pe3jzdovEdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_peM1YdovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jz9ovEdqRBPR5WyT36A" type="FromMultiplicity" element="_peM1YdovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3jztovEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_pe3j0NovEdqRBPR5WyT36A" type="FromRoleLabel" element="_peM1YdovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3j0tovEdqRBPR5WyT36A" type="FromRole" element="_peM1YdovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3j0dovEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_pe3j09ovEdqRBPR5WyT36A" type="ToQualifierLabel" element="_peM1YtovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3j1dovEdqRBPR5WyT36A" type="QualifierCompartment" element="_peM1YtovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pe3j1tovEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3j1NovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_pe3j19ovEdqRBPR5WyT36A" type="FromQualifierLabel" element="_peM1YdovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3j2dovEdqRBPR5WyT36A" type="QualifierCompartment" element="_peM1YdovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pe3j2tovEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3j2NovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_pe3jwdovEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_pe3jwtovEdqRBPR5WyT36A" points="[-317, -820, -3916, 3916]$[-1931, -4762, -5530, -26]$[2382, -4762, -1217, -26]"/>
+ </edges>
+ <edges xmi:id="_xInjYdovEdqRBPR5WyT36A" element="_xInjYNovEdqRBPR5WyT36A" source="_tZF9odovEdqRBPR5WyT36A" target="_fs1pANovEdqRBPR5WyT36A">
+ <children xmi:id="_xInjZNovEdqRBPR5WyT36A" type="NameLabel" element="_xInjYNovEdqRBPR5WyT36A">
+ <children xmi:id="_xInjZtovEdqRBPR5WyT36A" type="Stereotype" element="_xInjYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_xInjZ9ovEdqRBPR5WyT36A" type="Name" element="_xInjYNovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_xInjZdovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_xInjYtovEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_xInjY9ovEdqRBPR5WyT36A" points="[-4, -31, 1, 113]$[-4, -115, 1, 29]"/>
+ </edges>
+ <edges xmi:id="_3Ic-4NovEdqRBPR5WyT36A" element="_3IW4QNovEdqRBPR5WyT36A" source="_1y-ZsNovEdqRBPR5WyT36A" target="_z_m-oNovEdqRBPR5WyT36A">
+ <children xmi:id="_3Ic-49ovEdqRBPR5WyT36A" type="NameLabel" element="_3IW4QNovEdqRBPR5WyT36A">
+ <children xmi:id="_3Ic-5dovEdqRBPR5WyT36A" type="Stereotype" element="_3IW4QNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_3Ic-5tovEdqRBPR5WyT36A" type="Name" element="_3IW4QNovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_3Ic-5NovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_3Ic-4dovEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_3Ic-4tovEdqRBPR5WyT36A" points="[6, -24, -37, 154]$[-22, -170, -65, 8]"/>
+ </edges>
+ <edges xmi:id="_9XeF4tovEdqRBPR5WyT36A" element="_9XeF4NovEdqRBPR5WyT36A" source="_4WSrANovEdqRBPR5WyT36A" target="_z_m-oNovEdqRBPR5WyT36A">
+ <children xmi:id="_9XeF5dovEdqRBPR5WyT36A" type="NameLabel" element="_9XeF4NovEdqRBPR5WyT36A">
+ <children xmi:id="_9XeF59ovEdqRBPR5WyT36A" type="Stereotype" element="_9XeF4NovEdqRBPR5WyT36A"/>
+ <children xmi:id="_9XeF6NovEdqRBPR5WyT36A" type="Name" element="_9XeF4NovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9XeF5tovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_9XeF49ovEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_9XeF5NovEdqRBPR5WyT36A" points="[-23, -23, 162, 151]$[-121, -170, 64, 4]"/>
+ </edges>
+ <edges xmi:id="_BkUg0dowEdqRBPR5WyT36A" element="_Bj8GUNowEdqRBPR5WyT36A" source="_tZF9odovEdqRBPR5WyT36A" target="_1y-ZsNovEdqRBPR5WyT36A">
+ <children xmi:id="_BkancNowEdqRBPR5WyT36A" type="NameLabel" element="_Bj8GUNowEdqRBPR5WyT36A">
+ <children xmi:id="_BkanctowEdqRBPR5WyT36A" type="Stereotype" element="_Bj8GUNowEdqRBPR5WyT36A"/>
+ <children xmi:id="_Bkanc9owEdqRBPR5WyT36A" type="Name" element="_Bj8GUNowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkancdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_BkandNowEdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_Bj8GUtowEdqRBPR5WyT36A">
+ <children xmi:id="_BkandtowEdqRBPR5WyT36A" type="ToMultiplicity" element="_Bj8GUtowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkanddowEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_Bkand9owEdqRBPR5WyT36A" type="ToRoleLabel" element="_Bj8GUtowEdqRBPR5WyT36A">
+ <children xmi:id="_BkanedowEdqRBPR5WyT36A" type="ToRole" element="_Bj8GUtowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkaneNowEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_BkanetowEdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_Bj8GUdowEdqRBPR5WyT36A">
+ <children xmi:id="_BkanfNowEdqRBPR5WyT36A" type="FromMultiplicity" element="_Bj8GUdowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Bkane9owEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_BkanfdowEdqRBPR5WyT36A" type="FromRoleLabel" element="_Bj8GUdowEdqRBPR5WyT36A">
+ <children xmi:id="_Bkanf9owEdqRBPR5WyT36A" type="FromRole" element="_Bj8GUdowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkanftowEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_BkangNowEdqRBPR5WyT36A" type="ToQualifierLabel" element="_Bj8GUtowEdqRBPR5WyT36A">
+ <children xmi:id="_BkangtowEdqRBPR5WyT36A" type="QualifierCompartment" element="_Bj8GUtowEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_Bkang9owEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkangdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_BkanhNowEdqRBPR5WyT36A" type="FromQualifierLabel" element="_Bj8GUdowEdqRBPR5WyT36A">
+ <children xmi:id="_BkanhtowEdqRBPR5WyT36A" type="QualifierCompartment" element="_Bj8GUdowEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_Bkanh9owEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkanhdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_BkUg0towEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_BkUg09owEdqRBPR5WyT36A" points="[83, -24, -490, 123]$[486, -151, -87, -4]"/>
+ </edges>
+ <edges xmi:id="_Fd3lQdowEdqRBPR5WyT36A" element="_FdlRYNowEdqRBPR5WyT36A" source="_ePDcYdovEdqRBPR5WyT36A" target="_z_m-oNovEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lRNowEdqRBPR5WyT36A" type="NameLabel" element="_FdlRYNowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lRtowEdqRBPR5WyT36A" type="Stereotype" element="_FdlRYNowEdqRBPR5WyT36A"/>
+ <children xmi:id="_Fd3lR9owEdqRBPR5WyT36A" type="Name" element="_FdlRYNowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lRdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_Fd3lSNowEdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_FdlRYtowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lStowEdqRBPR5WyT36A" type="ToMultiplicity" element="_FdlRYtowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lSdowEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_Fd3lS9owEdqRBPR5WyT36A" type="ToRoleLabel" element="_FdlRYtowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lTdowEdqRBPR5WyT36A" type="ToRole" element="_FdlRYtowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lTNowEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_Fd3lTtowEdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_FdlRYdowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lUNowEdqRBPR5WyT36A" type="FromMultiplicity" element="_FdlRYdowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lT9owEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_Fd3lUdowEdqRBPR5WyT36A" type="FromRoleLabel" element="_FdlRYdowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lU9owEdqRBPR5WyT36A" type="FromRole" element="_FdlRYdowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lUtowEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_Fd3lVNowEdqRBPR5WyT36A" type="ToQualifierLabel" element="_FdlRYtowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lVtowEdqRBPR5WyT36A" type="QualifierCompartment" element="_FdlRYtowEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_Fd3lV9owEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lVdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_Fd3lWNowEdqRBPR5WyT36A" type="FromQualifierLabel" element="_FdlRYdowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lWtowEdqRBPR5WyT36A" type="QualifierCompartment" element="_FdlRYdowEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_Fd3lW9owEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lWdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_Fd3lQtowEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_Fd3lQ9owEdqRBPR5WyT36A" points="[46, -11, -369, -9]$[351, -11, -64, -9]"/>
+ </edges>
+ <edges xmi:id="_R5Rjwdo1EdqRBPR5WyT36A" element="_R5RjwNo1EdqRBPR5WyT36A" source="_ePDcYdovEdqRBPR5WyT36A" target="_M0FLkNo1EdqRBPR5WyT36A">
+ <children xmi:id="_R5RjxNo1EdqRBPR5WyT36A" type="NameLabel" element="_R5RjwNo1EdqRBPR5WyT36A">
+ <children xmi:id="_R5Rjxto1EdqRBPR5WyT36A" type="Stereotype" element="_R5RjwNo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_R5Rjx9o1EdqRBPR5WyT36A" type="Name" element="_R5RjwNo1EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_R5Rjxdo1EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_R5Rjwto1EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_R5Rjw9o1EdqRBPR5WyT36A" points="[-2, -31, -2, 91]$[-2, -91, -2, 31]"/>
+ </edges>
+ <edges xmi:id="_V7zlEdo1EdqRBPR5WyT36A" element="_V7zlENo1EdqRBPR5WyT36A" source="_TJHbANo1EdqRBPR5WyT36A" target="_M0FLkNo1EdqRBPR5WyT36A">
+ <children xmi:id="_V7zlFNo1EdqRBPR5WyT36A" type="NameLabel" element="_V7zlENo1EdqRBPR5WyT36A">
+ <children xmi:id="_V7zlFto1EdqRBPR5WyT36A" type="Stereotype" element="_V7zlENo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_V7zlF9o1EdqRBPR5WyT36A" type="Name" element="_V7zlENo1EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_V7zlFdo1EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_V7zlEto1EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_V7zlE9o1EdqRBPR5WyT36A" points="[-73, 0, 339, 0]$[-457, 0, -45, 0]"/>
+ </edges>
+ <edges xmi:id="_cN4xsdo2EdqRBPR5WyT36A" targetEdges="_pdfmkNo2EdqRBPR5WyT36A" element="_cNskcNo2EdqRBPR5WyT36A" source="_z_m-oNovEdqRBPR5WyT36A" target="_TJHbANo1EdqRBPR5WyT36A">
+ <children xmi:id="_cN4xtNo2EdqRBPR5WyT36A" type="NameLabel" element="_cNskcNo2EdqRBPR5WyT36A">
+ <children xmi:id="_cN4xtto2EdqRBPR5WyT36A" type="Stereotype" element="_cNskcNo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_cN4xt9o2EdqRBPR5WyT36A" type="Name" element="_cNskcNo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN4xtdo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_cN4xuNo2EdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_cNskcto2EdqRBPR5WyT36A">
+ <children xmi:id="_cN4xuto2EdqRBPR5WyT36A" type="ToMultiplicity" element="_cNskcto2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN4xudo2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_cN4xu9o2EdqRBPR5WyT36A" type="ToRoleLabel" element="_cNskcto2EdqRBPR5WyT36A">
+ <children xmi:id="_cN4xvdo2EdqRBPR5WyT36A" type="ToRole" element="_cNskcto2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN4xvNo2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_cN_fYNo2EdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_cNskcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_cN_fYto2EdqRBPR5WyT36A" type="FromMultiplicity" element="_cNskcdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN_fYdo2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_cN_fY9o2EdqRBPR5WyT36A" type="FromRoleLabel" element="_cNskcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_cN_fZdo2EdqRBPR5WyT36A" type="FromRole" element="_cNskcdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN_fZNo2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_cN_fZto2EdqRBPR5WyT36A" type="ToQualifierLabel" element="_cNskcto2EdqRBPR5WyT36A">
+ <children xmi:id="_cN_faNo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_cNskcto2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_cN_fado2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN_fZ9o2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_cN_fato2EdqRBPR5WyT36A" type="FromQualifierLabel" element="_cNskcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_cN_fbNo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_cNskcdo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_cN_fbdo2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN_fa9o2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_cN4xsto2EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_cN4xs9o2EdqRBPR5WyT36A" points="[-2, -29, 1, 91]$[26, -89, 29, 31]"/>
+ </edges>
+ <edges xmi:id="_pdfmkNo2EdqRBPR5WyT36A" element="_pdHMENo2EdqRBPR5WyT36A" source="_ePDcYdovEdqRBPR5WyT36A" target="_cN4xsdo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfml9o2EdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_pdTZUdo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmmdo2EdqRBPR5WyT36A" type="ToMultiplicity" element="_pdTZUdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmmNo2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_pdfmmto2EdqRBPR5WyT36A" type="ToRoleLabel" element="_pdTZUdo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmnNo2EdqRBPR5WyT36A" type="ToRole" element="_pdTZUdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmm9o2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_pdfmndo2EdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_pdTZUNo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmn9o2EdqRBPR5WyT36A" type="FromMultiplicity" element="_pdTZUNo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmnto2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_pdfmoNo2EdqRBPR5WyT36A" type="FromRoleLabel" element="_pdTZUNo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmoto2EdqRBPR5WyT36A" type="FromRole" element="_pdTZUNo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmodo2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_pdfmo9o2EdqRBPR5WyT36A" type="ToQualifierLabel" element="_pdTZUdo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmpdo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_pdTZUdo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfmpto2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmpNo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_pdfmp9o2EdqRBPR5WyT36A" type="FromQualifierLabel" element="_pdTZUNo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmqdo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_pdTZUNo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfmqto2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmqNo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_pdfmq9o2EdqRBPR5WyT36A" element="_pdHMENo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmrto2EdqRBPR5WyT36A" type="ImageCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_pdfmr9o2EdqRBPR5WyT36A" width="1320" height="1320"/>
+ </children>
+ <children xmi:id="_pdfmsNo2EdqRBPR5WyT36A" type="Stereotype" element="_pdHMENo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_pdfmsdo2EdqRBPR5WyT36A" type="Name" element="_pdHMENo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_pdfmsto2EdqRBPR5WyT36A" type="AttributeCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfms9o2EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_pdfmtNo2EdqRBPR5WyT36A" type="OperationCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfmtdo2EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_pdfmtto2EdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfmt9o2EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_pdfmuNo2EdqRBPR5WyT36A" visible="false" type="StructureCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLShapeCompartmentStyle" xmi:id="_pdfmudo2EdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLShapeStyle" xmi:id="_pdfmrNo2EdqRBPR5WyT36A" showStereotype="Label"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_pdfmrdo2EdqRBPR5WyT36A" y="1323"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_pdfmkdo2EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_pdfmkto2EdqRBPR5WyT36A" points="[46, 3, -366, 94]$[412, -91, 0, 0]"/>
+ <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_pdrz0No2EdqRBPR5WyT36A" id="100"/>
+ </edges>
+ <edges xmi:id="_9PaR4No2EdqRBPR5WyT36A" element="_9PH-ANo2EdqRBPR5WyT36A" source="_4WSrANovEdqRBPR5WyT36A" target="_o2m3oNo0EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR49o2EdqRBPR5WyT36A" type="NameLabel" element="_9PH-ANo2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR5do2EdqRBPR5WyT36A" type="Stereotype" element="_9PH-ANo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_9PaR5to2EdqRBPR5WyT36A" type="Name" element="_9PH-ANo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR5No2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_9PaR59o2EdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_9PH-Ato2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR6do2EdqRBPR5WyT36A" type="ToMultiplicity" element="_9PH-Ato2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR6No2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_9PaR6to2EdqRBPR5WyT36A" type="ToRoleLabel" element="_9PH-Ato2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR7No2EdqRBPR5WyT36A" type="ToRole" element="_9PH-Ato2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR69o2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_9PaR7do2EdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_9PH-Ado2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR79o2EdqRBPR5WyT36A" type="FromMultiplicity" element="_9PH-Ado2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR7to2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_9PaR8No2EdqRBPR5WyT36A" type="FromRoleLabel" element="_9PH-Ado2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR8to2EdqRBPR5WyT36A" type="FromRole" element="_9PH-Ado2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR8do2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_9PgYgNo2EdqRBPR5WyT36A" type="ToQualifierLabel" element="_9PH-Ato2EdqRBPR5WyT36A">
+ <children xmi:id="_9PgYgto2EdqRBPR5WyT36A" type="QualifierCompartment" element="_9PH-Ato2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_9PgYg9o2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PgYgdo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_9PgYhNo2EdqRBPR5WyT36A" type="FromQualifierLabel" element="_9PH-Ado2EdqRBPR5WyT36A">
+ <children xmi:id="_9PgYhto2EdqRBPR5WyT36A" type="QualifierCompartment" element="_9PH-Ado2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_9PgYh9o2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PgYhdo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_9PaR4do2EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_9PaR4to2EdqRBPR5WyT36A" points="[12, -24, -94, 162]$[80, -155, -26, 31]"/>
+ </edges>
+ <edges xmi:id="_9-BEUNo2EdqRBPR5WyT36A" element="_99uwcNo2EdqRBPR5WyT36A" source="_1y-ZsNovEdqRBPR5WyT36A" target="_o2m3oNo0EdqRBPR5WyT36A">
+ <children xmi:id="_9-BEU9o2EdqRBPR5WyT36A" type="NameLabel" element="_99uwcNo2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK8No2EdqRBPR5WyT36A" type="Stereotype" element="_99uwcNo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_9-HK8do2EdqRBPR5WyT36A" type="Name" element="_99uwcNo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-BEVNo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_9-HK8to2EdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_99uwcto2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK9No2EdqRBPR5WyT36A" type="ToMultiplicity" element="_99uwcto2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK89o2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_9-HK9do2EdqRBPR5WyT36A" type="ToRoleLabel" element="_99uwcto2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK99o2EdqRBPR5WyT36A" type="ToRole" element="_99uwcto2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK9to2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_9-HK-No2EdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_99uwcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK-to2EdqRBPR5WyT36A" type="FromMultiplicity" element="_99uwcdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK-do2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_9-HK-9o2EdqRBPR5WyT36A" type="FromRoleLabel" element="_99uwcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK_do2EdqRBPR5WyT36A" type="FromRole" element="_99uwcdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK_No2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_9-HK_to2EdqRBPR5WyT36A" type="ToQualifierLabel" element="_99uwcto2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HLANo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_99uwcto2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_9-HLAdo2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK_9o2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_9-HLAto2EdqRBPR5WyT36A" type="FromQualifierLabel" element="_99uwcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HLBNo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_99uwcdo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_9-HLBdo2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HLA9o2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_9-BEUdo2EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_9-BEUto2EdqRBPR5WyT36A" points="[49, -24, -290, 162]$[404, -163, 65, 23]"/>
+ </edges>
+ </contents>
+ </eAnnotations>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1S9NovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S9dovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1S9tovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_PROFILES/Basic.profile.uml2#_6mFRgK86Edih9-GG5afQ0g"/>
+ <importedProfile href="pathmap://UML2_PROFILES/Basic.profile.uml2#_6mFRgK86Edih9-GG5afQ0g"/>
+ </packageImport>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1S99ovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S-NovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1S-dovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_PROFILES/Intermediate.profile.uml2#_Cz7csK87Edih9-GG5afQ0g"/>
+ <importedProfile href="pathmap://UML2_PROFILES/Intermediate.profile.uml2#_Cz7csK87Edih9-GG5afQ0g"/>
+ </packageImport>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1S-tovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S-9ovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1S_NovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_PROFILES/Complete.profile.uml2#_M7pTkK87Edih9-GG5afQ0g"/>
+ <importedProfile href="pathmap://UML2_PROFILES/Complete.profile.uml2#_M7pTkK87Edih9-GG5afQ0g"/>
+ </packageImport>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1S_dovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S_tovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1S_9ovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_MSL_PROFILES/Default.epx#_a_S3wNWLEdiy4IqP8whjFA?Default"/>
+ <importedProfile href="pathmap://UML2_MSL_PROFILES/Default.epx#_a_S3wNWLEdiy4IqP8whjFA?Default"/>
+ </packageImport>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1TANovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1TAdovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1TAtovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_MSL_PROFILES/Deployment.epx#_vjbuwOvHEdiDX5bji0iVSA?Deployment"/>
+ <importedProfile href="pathmap://UML2_MSL_PROFILES/Deployment.epx#_vjbuwOvHEdiDX5bji0iVSA?Deployment"/>
+ </packageImport>
+ <packageImport xmi:id="_al1TA9ovEdqRBPR5WyT36A">
+ <importedPackage xmi:type="uml:Model" href="pathmap://UML2_LIBRARIES/UML2PrimitiveTypes.library.uml2#_EfRZoK86EdieaYgxtVWN8Q"/>
+ </packageImport>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_ePDcYNovEdqRBPR5WyT36A" name="Context">
+ <generalization xmi:id="_R5RjwNo1EdqRBPR5WyT36A" general="_Mz_E8No1EdqRBPR5WyT36A"/>
+ <ownedAttribute xmi:id="_FdlRYdowEdqRBPR5WyT36A" name="scopecontext" visibility="private" type="_z_g4ANovEdqRBPR5WyT36A" association="_FdlRYNowEdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_FdlRZNowEdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_FdlRY9owEdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_fsviYNovEdqRBPR5WyT36A" name="CompositeContext">
+ <generalization xmi:id="_hmIF4NovEdqRBPR5WyT36A" general="_ePDcYNovEdqRBPR5WyT36A"/>
+ <ownedAttribute xmi:id="_peM1YdovEdqRBPR5WyT36A" name="context" visibility="private" type="_ePDcYNovEdqRBPR5WyT36A" association="_peM1YNovEdqRBPR5WyT36A" aggregation="composite">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_peM1ZNovEdqRBPR5WyT36A" value="-1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_peM1Y9ovEdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_ikl5QNovEdqRBPR5WyT36A" name="AtomicContext">
+ <generalization xmi:id="_mu9A4NovEdqRBPR5WyT36A" general="_ePDcYNovEdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_peM1YNovEdqRBPR5WyT36A" memberEnd="_peM1YdovEdqRBPR5WyT36A _peM1YtovEdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_peM1YtovEdqRBPR5WyT36A" visibility="private" type="_fsviYNovEdqRBPR5WyT36A" association="_peM1YNovEdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_tZF9oNovEdqRBPR5WyT36A" name="DeploymentContext">
+ <generalization xmi:id="_xInjYNovEdqRBPR5WyT36A" general="_fsviYNovEdqRBPR5WyT36A"/>
+ <ownedAttribute xmi:id="_Bj8GUdowEdqRBPR5WyT36A" name="modulescopecontext" visibility="private" type="_1yyMcNovEdqRBPR5WyT36A" association="_Bj8GUNowEdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_Bj8GVNowEdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_Bj8GU9owEdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_z_g4ANovEdqRBPR5WyT36A" name="ScopeContext">
+ <ownedAttribute xmi:id="_cNskcdo2EdqRBPR5WyT36A" name="instancewrapper" visibility="private" type="_TI7NwNo1EdqRBPR5WyT36A" association="_cNskcNo2EdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_cNskdNo2EdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_cNskc9o2EdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Class" xmi:id="_1yyMcNovEdqRBPR5WyT36A" name="ModuleScopeContext" clientDependency="_3IW4QNovEdqRBPR5WyT36A">
+ <implementation xmi:id="_3IW4QNovEdqRBPR5WyT36A" client="_1yyMcNovEdqRBPR5WyT36A" supplier="_z_g4ANovEdqRBPR5WyT36A" realizingClassifier="_z_g4ANovEdqRBPR5WyT36A" contract="_z_g4ANovEdqRBPR5WyT36A">
+ <mapping xmi:id="_3IW4QdovEdqRBPR5WyT36A"/>
+ </implementation>
+ <ownedAttribute xmi:id="_99uwcdo2EdqRBPR5WyT36A" name="scoperegistry" visibility="private" type="_o2gxANo0EdqRBPR5WyT36A" association="_99uwcNo2EdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_99uwdNo2EdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_99uwc9o2EdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Class" xmi:id="_4WMkYNovEdqRBPR5WyT36A" name="HTTPSessionScopeContext" clientDependency="_9XeF4NovEdqRBPR5WyT36A">
+ <implementation xmi:id="_9XeF4NovEdqRBPR5WyT36A" client="_4WMkYNovEdqRBPR5WyT36A" supplier="_z_g4ANovEdqRBPR5WyT36A" realizingClassifier="_z_g4ANovEdqRBPR5WyT36A" contract="_z_g4ANovEdqRBPR5WyT36A">
+ <mapping xmi:id="_9XeF4dovEdqRBPR5WyT36A"/>
+ </implementation>
+ <ownedAttribute xmi:id="_9PH-Ado2EdqRBPR5WyT36A" name="scoperegistry" visibility="private" type="_o2gxANo0EdqRBPR5WyT36A" association="_9PH-ANo2EdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_9PH-BNo2EdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_9PH-A9o2EdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_Bj8GUNowEdqRBPR5WyT36A" memberEnd="_Bj8GUdowEdqRBPR5WyT36A _Bj8GUtowEdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_Bj8GUtowEdqRBPR5WyT36A" visibility="private" type="_tZF9oNovEdqRBPR5WyT36A" association="_Bj8GUNowEdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_FdlRYNowEdqRBPR5WyT36A" memberEnd="_FdlRYdowEdqRBPR5WyT36A _FdlRYtowEdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_FdlRYtowEdqRBPR5WyT36A" visibility="private" type="_ePDcYNovEdqRBPR5WyT36A" association="_FdlRYNowEdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_o2gxANo0EdqRBPR5WyT36A" name="ScopeRegistry"/>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_Mz_E8No1EdqRBPR5WyT36A" name="Lifecycle"/>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_TI7NwNo1EdqRBPR5WyT36A" name="InstanceWrapper">
+ <generalization xmi:id="_V7zlENo1EdqRBPR5WyT36A" general="_Mz_E8No1EdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_cNskcNo2EdqRBPR5WyT36A" memberEnd="_cNskcdo2EdqRBPR5WyT36A _cNskcto2EdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_cNskcto2EdqRBPR5WyT36A" visibility="private" type="_z_g4ANovEdqRBPR5WyT36A" association="_cNskcNo2EdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:AssociationClass" xmi:id="_pdHMENo2EdqRBPR5WyT36A" name="AssociationClass1" memberEnd="_pdTZUNo2EdqRBPR5WyT36A _pdTZUdo2EdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_pdTZUNo2EdqRBPR5WyT36A" visibility="private" type="_cNskcNo2EdqRBPR5WyT36A" association="_pdHMENo2EdqRBPR5WyT36A"/>
+ <ownedEnd xmi:id="_pdTZUdo2EdqRBPR5WyT36A" visibility="private" type="_ePDcYNovEdqRBPR5WyT36A" association="_pdHMENo2EdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_9PH-ANo2EdqRBPR5WyT36A" memberEnd="_9PH-Ado2EdqRBPR5WyT36A _9PH-Ato2EdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_9PH-Ato2EdqRBPR5WyT36A" visibility="private" type="_4WMkYNovEdqRBPR5WyT36A" association="_9PH-ANo2EdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_99uwcNo2EdqRBPR5WyT36A" memberEnd="_99uwcdo2EdqRBPR5WyT36A _99uwcto2EdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_99uwcto2EdqRBPR5WyT36A" visibility="private" type="_1yyMcNovEdqRBPR5WyT36A" association="_99uwcNo2EdqRBPR5WyT36A"/>
+ </ownedMember>
+</uml:Model>
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/AbstractLifecycle.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/AbstractLifecycle.java new file mode 100644 index 0000000000..e8597a55fc --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/AbstractLifecycle.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +/** + * Base class providing a simple implementation of Lifecycle. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractLifecycle implements Lifecycle { + protected volatile int lifecycleState = UNINITIALIZED; + + public int getLifecycleState() { + return lifecycleState; + } + + /** + * Set the current state of the Lifecycle. + * + * @param lifecycleState the new state + */ + protected void setLifecycleState(int lifecycleState) { + this.lifecycleState = lifecycleState; + } + + public void start() { + setLifecycleState(RUNNING); + } + + public void stop() { + setLifecycleState(STOPPED); + } + + /** + * Returns the current lifecycle as a String (for example, "RUNNING"). + * + * @return the current lifecycle as a String + */ + public String toString() { + switch (lifecycleState) { + case Lifecycle.CONFIG_ERROR: + return "CONFIG_ERROR"; + case Lifecycle.ERROR: + return "ERROR"; + case Lifecycle.INITIALIZING: + return "INITIALIZING"; + case Lifecycle.INITIALIZED: + return "INITIALIZED"; + case Lifecycle.RUNNING: + return "RUNNING"; + case Lifecycle.STOPPING: + return "STOPPING"; + case Lifecycle.STOPPED: + return "STOPPED"; + case Lifecycle.UNINITIALIZED: + return "UNINITIALIZED"; + default: + return "UNKNOWN"; + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/CoreRuntimeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/CoreRuntimeException.java new file mode 100644 index 0000000000..641a4e5d21 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/CoreRuntimeException.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * The root exception for the runtime package. Exceptions occurring in the runtime are generally non-recoverable + * + * @version $Rev$ $Date$ + */ +public abstract class CoreRuntimeException extends TuscanyRuntimeException { + + public CoreRuntimeException() { + super(); + } + + public CoreRuntimeException(String message) { + super(message); + } + + + protected CoreRuntimeException(String message, String identifier) { + super(message, identifier); + } + + public CoreRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + + protected CoreRuntimeException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public CoreRuntimeException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/InvalidNameException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/InvalidNameException.java new file mode 100644 index 0000000000..28bc8652b2 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/InvalidNameException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +/** + * Denotes an invalid name + * + * @version $Rev$ $Date$ + */ +public class InvalidNameException extends CoreRuntimeException { + + public InvalidNameException() { + super(); + } + + public InvalidNameException(String message) { + super(message); + } + + public InvalidNameException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidNameException(Throwable cause) { + super(cause); + } + +} + diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/Lifecycle.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/Lifecycle.java new file mode 100644 index 0000000000..e8a0448e44 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/Lifecycle.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +/** + * Implementations adhere to runtime lifecycle semantics + * + * @version $Rev$ $Date$ + */ +public interface Lifecycle { + /* A configuration error state */ + int CONFIG_ERROR = -1; + /* Has not been initialized */ + int UNINITIALIZED = 0; + /* In the process of being configured and initialized */ + int INITIALIZING = 1; + /* Instantiated and configured */ + int INITIALIZED = 2; + /* Configured and initialized */ + int RUNNING = 4; + /* In the process of being shutdown */ + int STOPPING = 5; + /* Has been shutdown and removed from the composite */ + int STOPPED = 6; + /* In an error state */ + int ERROR = 7; + + /** + * Returns the lifecycle state + * + * @see #UNINITIALIZED + * @see #INITIALIZING + * @see #INITIALIZED + * @see #RUNNING + * @see #STOPPING + * @see #STOPPED + */ + int getLifecycleState(); + + /** + * Starts the Lifecycle. + * + * @throws CoreRuntimeException + */ + void start() throws CoreRuntimeException; + + /** + * Stops the Lifecycle. + * + * @throws CoreRuntimeException + */ + void stop() throws CoreRuntimeException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectCreationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectCreationException.java new file mode 100644 index 0000000000..580e928000 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectCreationException.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * Denotes an error creating a new object instance + * + * @version $Rev$ $Date$ + */ +public class ObjectCreationException extends TuscanyRuntimeException { + private static final long serialVersionUID = -6423113430265944499L; + + public ObjectCreationException() { + super(); + } + + public ObjectCreationException(String message) { + super(message); + } + + public ObjectCreationException(String message, String identifier) { + super(message, identifier); + } + + public ObjectCreationException(String message, Throwable cause) { + super(message, cause); + } + + public ObjectCreationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public ObjectCreationException(Throwable cause) { + super(cause); + } + +} + diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectFactory.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectFactory.java new file mode 100644 index 0000000000..d505e14f61 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectFactory.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +/** + * Implementations create new instances of a particular type + * + * @version $Rev$ $Date$ + */ +public interface ObjectFactory<T> { + + /** + * Return a instance of the type that this factory creates. + * + * @return a instance from this factory + */ + T getInstance() throws ObjectCreationException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/QualifiedName.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/QualifiedName.java new file mode 100644 index 0000000000..25e2dbbc65 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/QualifiedName.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +/** + * An evaluated name consisting of a part/port pair. In the runtime, a part generally 'contains' or 'provides' ports + * such as a component/service point or a component/reference pair. + * + * @version $Rev$ $Date$ + */ +public class QualifiedName { + public static final String NAME_SEPARATOR = "/"; + + private final String qName; + private final String fragment; + private final String partName; + private final String portName; + + /** + * Constructs a new qualified name in the form of part/port where part is the parent context and port represents a + * child, which is either a service in the case of an atomic context or a contained context in the case of a + * composite. + * + * @throws InvalidNameException if the name is in an invalid format + */ + public QualifiedName(String qualifiedName) throws InvalidNameException { + String[] parts = qualifiedName.split(NAME_SEPARATOR); + if (parts.length == 1) { + partName = parts[0]; + portName = null; + qName = partName; + fragment = partName; + } else if (parts.length == 2) { + partName = parts[0]; + portName = parts[1]; + qName = partName + '/' + portName; + fragment = partName + '#' + portName; + } else { + throw new InvalidNameException(qualifiedName); + } + } + + /** + * Constructs a qualified name using the given part/port combination + * + * @param partName the part name + * @param portName the port name + */ + public QualifiedName(String partName, String portName) { + this.partName = partName; + this.portName = portName; + if (portName == null) { + qName = partName; + fragment = partName; + } else { + qName = partName + '/' + portName; + fragment = partName + '#' + portName; + } + } + + /** + * Returns the parsed part name + */ + public String getPartName() { + return partName; + } + + /** + * Returns the parsed port name if the original is of the compound for part/port + */ + public String getPortName() { + return portName; + } + + /** + * Returns the full part/port name pair + */ + public String getQualifiedName() { + return qName; + } + + public String getFragment() { + return fragment; + } + + public String toString() { + return qName; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/bootstrap/ComponentNames.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/bootstrap/ComponentNames.java new file mode 100644 index 0000000000..347c4f4d0b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/bootstrap/ComponentNames.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.bootstrap; + +import java.net.URI; + +/** + * Class that defines the names of well known component + * + * @version $Rev$ $Date$ + */ +public final class ComponentNames { + /** + * The name of the component that forms the root of the runtime tree. + */ + public static final URI TUSCANY_RUNTIME = URI.create("tuscany.runtime"); + + /** + * The name of the component that is the root of the application composite tree. + */ + public static final URI TUSCANY_APPLICATION_ROOT = URI.create("sca://root.application/"); + + /** + * The name of the component that is the root of the system composite tree. + */ + public static final URI TUSCANY_SYSTEM_ROOT = URI.create("sca://root.system/"); + + /** + * The name of the top-level component in the system composite tree. + */ + public static final URI TUSCANY_SYSTEM = TUSCANY_SYSTEM_ROOT.resolve("main/"); + + /** + * The name of the component that contains the deployer. + */ + public static final URI TUSCANY_DEPLOYER = TUSCANY_SYSTEM.resolve("deployer"); + + /** + * The name of the component that contains the deployer. + */ + public static final URI TUSCANY_WIRE_SERVICE = TUSCANY_SYSTEM.resolve("proxyService"); + + private ComponentNames() { + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BindingBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BindingBuilder.java new file mode 100644 index 0000000000..4b63f6d7e9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BindingBuilder.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 org.apache.tuscany.spi.builder; + +import org.apache.tuscany.spi.component.ReferenceBinding; +import org.apache.tuscany.spi.component.ServiceBinding; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.model.BindingDefinition; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ServiceDefinition; + +/** + * Responsible for processing a service or reference in an assembly configured with a particular binding. The builder + * will create and return corresponding {@link org.apache.tuscany.spi.component.ServiceBinding} or {@link + * org.apache.tuscany.spi.component.ReferenceBinding} + * + * @version $Rev$ $Date$ + */ +public interface BindingBuilder<B extends BindingDefinition> { + + /** + * Creates a service binding + * + * @param serviceDefinition the service the binding is configured for + * @param bindingDefinition the binding definition + * @param context the current deployment context + * @return a service binding + * @throws BuilderException + */ + ServiceBinding build(ServiceDefinition serviceDefinition, B bindingDefinition, DeploymentContext context) + throws BuilderException; + + /** + * Creates a reference binding + * + * @param referenceDefinition the reference the binding is configured for + * @param bindingDefinition the binding definition + * @param context the current deployment context + * @return a reference binding + * @throws BuilderException + */ + ReferenceBinding build(ReferenceDefinition referenceDefinition, B bindingDefinition, DeploymentContext context) + throws BuilderException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Builder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Builder.java new file mode 100644 index 0000000000..4433a4689c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Builder.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 org.apache.tuscany.spi.builder; + +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ServiceDefinition; + +/** + * Implementations build <code>SCAObject</code> types from model objects. + * + * @version $Rev$ $Date$ + */ +public interface Builder { + /** + * Builds a <code>Component</code> from a <code>ComponentDefinition</code> + * + * @param definition the component definition as parsed from an SCA assembly + * @param context the current deployment context + * @return the newly created component + * @throws BuilderException + */ + <I extends Implementation<?>> Component build(ComponentDefinition<I> definition, DeploymentContext context) + throws BuilderException; + + /** + * Builds a <code>Service</code> and its bindings from a <code>BoundServiceDefinition</code> + * + * @param definition the service definition as parsed from an SCA assembly + * @param context the current deployment context + * @return the newly created service + * @throws BuilderException + */ + Service build(ServiceDefinition definition, DeploymentContext context) throws BuilderException; + + /** + * Builds a <code>Reference</code> and its bindings from a <code>BoundReferenceDefinition</code> + * + * @param definition the reference definition as parsed from an SCA assembly + * @param context the current deployment context + * @return the newly created reference + * @throws BuilderException + */ + Reference build(ReferenceDefinition definition, DeploymentContext context) throws BuilderException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderConfigException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderConfigException.java new file mode 100644 index 0000000000..6e9f2ef95d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderConfigException.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 org.apache.tuscany.spi.builder; + +/** + * Represents an error processing an assembly model + * + * @version $Rev$ $Date$ + */ +public class BuilderConfigException extends BuilderException { + + public BuilderConfigException() { + super(); + } + + public BuilderConfigException(String message) { + super(message); + } + + public BuilderConfigException(String message, String identifier) { + super(message, identifier); + } + + public BuilderConfigException(String message, Throwable cause) { + super(message, cause); + } + + public BuilderConfigException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderException.java new file mode 100644 index 0000000000..846d52492c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderException.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder; + +import org.apache.tuscany.api.TuscanyException; + +/** + * The root exception for the builder package. Builder exceptions denote a non-recoverable failure. + * + * @version $Rev$ $Date$ + */ +public abstract class BuilderException extends TuscanyException { + + public BuilderException() { + super(); + } + + public BuilderException(String message) { + super(message); + } + + + protected BuilderException(String message, String identifier) { + super(message, identifier); + } + + public BuilderException(String message, Throwable cause) { + super(message, cause); + } + + protected BuilderException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public BuilderException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderInstantiationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderInstantiationException.java new file mode 100644 index 0000000000..30957635db --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderInstantiationException.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder; + +/** + * Denotes an error instantiating an <code>SCAObject</code> + * + * @version $Rev$ $Date$ + */ +public class BuilderInstantiationException extends BuilderException { + + public BuilderInstantiationException(String message, String identifier) { + super(message, identifier); + } + + public BuilderInstantiationException(String message, Throwable cause) { + super(message, cause); + } + + public BuilderInstantiationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java new file mode 100644 index 0000000000..c4ecdfa35b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder; + +import org.apache.tuscany.spi.model.BindingDefinition; +import org.apache.tuscany.spi.model.Implementation; + +/** + * Maintains a registry of builders in the runtime, dispatching to the appropriate one as an assembly model is processed + * into runtime artifacts + * + * @version $Rev$ $Date$ + */ +public interface BuilderRegistry extends Builder { + + /** + * Register a builder for an implementation type. + * + * @param implClass the type of implementation that this builder can handle + * @param builder the builder to be registered + */ + <I extends Implementation<?>> void register(Class<I> implClass, ComponentBuilder<I> builder); + + /** + * Unregister a builder for an implementation type. + * + * @param implClass the implementation whose builder should be unregistered + */ + <I extends Implementation<?>> void unregister(Class<I> implClass); + + /** + * Register a binding builder for a binding type + * + * @param implClass the binding type + * @param builder the buinder to be registered + */ + <B extends BindingDefinition> void register(Class<B> implClass, BindingBuilder<B> builder); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java new file mode 100644 index 0000000000..b381adddc4 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder; + +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.Implementation; + +/** + * Responsible for building a {@link Component} from an component definition + * + * @version $Rev$ $Date$ + */ +public interface ComponentBuilder<I extends Implementation<?>> { + + /** + * Builds the component + * + * @param componentDefinition the component definition + * @param context the deployment context + * @return the built component + * @throws BuilderException + */ + Component build(ComponentDefinition<I> componentDefinition, DeploymentContext context) throws BuilderException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.java new file mode 100644 index 0000000000..4ac762acfb --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.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 org.apache.tuscany.spi.builder; + +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition; + +/** + * Implementations are responsible for creating a wires between source and target artifacts + * + * @version $$Rev$$ $$Date$$ + */ +public interface Connector { + + /** + * Recursively connects component references and its children. This method will eventially be replaced by one that + * just takes a WireDefinition + * + * @param definition the component definition to connect + * @throws WiringException + * @deprecated + */ + void connect(ComponentDefinition<? extends Implementation<?>> definition) throws WiringException; + + /** + * Placeholder for the connect operation using federated deployment + * + * @param definition metadata describing the wire to create + * @throws WiringException + */ + void connect(PhysicalWireDefinition definition) throws BuilderException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java new file mode 100644 index 0000000000..78bb5a5cc8 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder; + +/** + * @version $Rev$ $Date$ + */ +public class InvalidServiceInterfaceException extends BuilderConfigException { + private final Class<?> interfaceClass; + + public InvalidServiceInterfaceException(String message, Class<?> interfaceClass) { + super(message); + this.interfaceClass = interfaceClass; + } + + public Class<?> getInterfaceClass() { + return interfaceClass; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/MissingWireTargetException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/MissingWireTargetException.java new file mode 100644 index 0000000000..dcb0068b9d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/MissingWireTargetException.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 org.apache.tuscany.spi.builder; + +import java.net.URI; + +/** + * Denotes a missing wire target in an assembly + * + * @version $Rev$ $Date$ + */ +public class MissingWireTargetException extends WiringException { + + public MissingWireTargetException(String message) { + super(message); + } + + public MissingWireTargetException(String message, URI sourceUri, URI targetUri) { + super(message, sourceUri, targetUri); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ScopeNotFoundException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ScopeNotFoundException.java new file mode 100644 index 0000000000..acf8dadda6 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ScopeNotFoundException.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder; + +/** + * @version $Rev$ $Date$ + */ +public class ScopeNotFoundException extends BuilderConfigException { + + public ScopeNotFoundException(String scope) { + super("Scope not found", scope); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/WiringException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/WiringException.java new file mode 100644 index 0000000000..1ba2a92d53 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/WiringException.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder; + +import java.net.URI; + + +/** + * Denotes a general error raised during wiring + * + * @version $Rev$ $Date$ + */ +public abstract class WiringException extends BuilderException { + private final URI sourceUri; + private final URI targetUri; + + protected WiringException(String message) { + super(message); + sourceUri = null; + targetUri = null; + } + + protected WiringException(String message, URI sourceUri, URI targetUri) { + super(message); + this.sourceUri = sourceUri; + this.targetUri = targetUri; + } + + protected WiringException(String message, URI sourceUri, URI targetUri, Throwable cause) { + super(message, cause); + this.sourceUri = sourceUri; + this.targetUri = targetUri; + } + + protected WiringException(String message, String identifier, URI sourceUri, URI targetUri) { + super(message, identifier); + this.sourceUri = sourceUri; + this.targetUri = targetUri; + } + + + protected WiringException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + sourceUri = null; + targetUri = null; + } + + /** + * Returns the source name for the wire + * + * @return the source name the source name for the wire + */ + public URI getSourceUri() { + return sourceUri; + } + + /** + * Returns the target name for the wire + * + * @return the target name the source name for the wire + */ + public URI getTargetUri() { + return targetUri; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilder.java new file mode 100644 index 0000000000..bf26c66c2d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilder.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder.interceptor; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition; +import org.apache.tuscany.spi.wire.Interceptor; + +/** + * Implementations return an interceptor for a given + * + * @version $Rev$ $Date$ + */ +public interface InterceptorBuilder { + + Interceptor build(PhysicalInterceptorDefinition definition) throws BuilderException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilderRegistry.java new file mode 100644 index 0000000000..7a2915e956 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilderRegistry.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder.interceptor; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition; +import org.apache.tuscany.spi.wire.Interceptor; + +/** + * A registry of interceptor builders that performs a dispatch to a builder based on an interceptor definition QName + * + * @version $Rev$ $Date$ + */ +public interface InterceptorBuilderRegistry { + + /** + * Register a interceptor builder for the given QName + * + * @param name the QName associated with the builder + * @param builder the builder to register + */ + void register(QName name, InterceptorBuilder builder); + + /** + * Unregister a interceptor builder for the given QName + * + * @param name the QName associated with the builder to unregister + */ + void unregister(QName name); + + /** + * Dispatches to an interceptor builder matching the definition QName + * + * @param definition the interceptor definition to build from + * @return an interceptor matching the given definition + * @throws BuilderException if an error ocurrs during the dispatch or build + */ + Interceptor build(PhysicalInterceptorDefinition definition) throws BuilderException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilder.java new file mode 100644 index 0000000000..065b7e793c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilder.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder.physical; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition; + +/** + * Interface for building components from physical component definitions. + * + * @version $Rev$ $Date$ + */ +public interface PhysicalComponentBuilder<PCD extends PhysicalComponentDefinition, C extends Component> { + + /** + * Builds a component from its physical component definition. + * + * @param componentDefinition Physical component definition of the component + * to be built. + * @return A component instance that is ready to go live. + * @throws BuilderException If unable to build the component. + */ + C build(PCD componentDefinition) throws BuilderException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilderRegistry.java new file mode 100644 index 0000000000..dc6ddb5f4b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilderRegistry.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 org.apache.tuscany.spi.builder.physical; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition; + +/** + * A registry of physical component builders. + * + * @version $Rev$ $Date$ + */ +public interface PhysicalComponentBuilderRegistry { + + /** + * Registers a physical component builder. + * + * @param <PCD> Type of the physical component definition. + * @param definitionClass Class of the physical component definition. + * @param builder Builder for the physical component definition. + */ + <PCD extends PhysicalComponentDefinition, C extends Component> + void register(Class<?> definitionClass, + PhysicalComponentBuilder<PCD, C> builder); + + /** + * Builds a physical component from component definition. + * + * @param componentDefinition Component definition. + * @return Component to be built. + */ + Component build(PhysicalComponentDefinition componentDefinition) throws BuilderException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttachException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttachException.java new file mode 100644 index 0000000000..3e76d987fa --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttachException.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder.physical; + +import java.net.URI; + +import org.apache.tuscany.spi.builder.WiringException; + +/** + * Thrown when an error is encountered attaching a wire + * + * @version $Rev$ $Date$ + */ +public class WireAttachException extends WiringException { + public WireAttachException(String message, URI sourceUri, URI targetUri, Throwable cause) { + super(message, sourceUri, targetUri, cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacher.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacher.java new file mode 100644 index 0000000000..2727b82054 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacher.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 org.apache.tuscany.spi.builder.physical; + +import org.apache.tuscany.spi.builder.WiringException; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition; +import org.apache.tuscany.spi.wire.Wire; + +/** + * Responsible for attaching a wire to a source and target component. The mechanism for perforing the attach is specific + * to the component implementation type. + * + * @version $Date$ $Revision$ + */ +public interface WireAttacher<C extends Component, + PWSD extends PhysicalWireSourceDefinition, + PWTD extends PhysicalWireTargetDefinition> { + + /** + * Attaches a wire to a source component. + * + * @param source the source component + * @param sourceDefinition metadata for performing the attach + * @param target the target component + * @param targetDefinition metadata for performing the attach + * @param wire the wire + * @throws WiringException if an exception occurs during the attach operation + */ + void attachToSource(C source, + PWSD sourceDefinition, + Component target, + PhysicalWireTargetDefinition targetDefinition, + Wire wire) throws WiringException; + + /** + * Attaches a wire to a target component. + * + * @param source the source component + * @param sourceDefinition metadata for performing the attach + * @param target the target component + * @param targetDefinition metadata for performing the attach + * @param wire the wire + * @throws WiringException if an exception occurs during the attach operation + */ + void attachToTarget(Component source, + PhysicalWireSourceDefinition sourceDefinition, + C target, + PWTD targetDefinition, + Wire wire) throws WiringException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacherRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacherRegistry.java new file mode 100644 index 0000000000..a29cf3e412 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacherRegistry.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.builder.physical; + +import org.apache.tuscany.spi.builder.WiringException; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition; +import org.apache.tuscany.spi.wire.Wire; + +/** + * A registry for wire attachers + * + * @version $Rev$ $Date$ + */ +public interface WireAttacherRegistry { + + <C extends Component, + PWSD extends PhysicalWireSourceDefinition, + PWTD extends PhysicalWireTargetDefinition> void register(Class<?> clazz, WireAttacher<C, PWSD, PWTD> attacher); + + /** + * Attaches a wire to a source component. + * + * @param source the source component + * @param sourceDefinition metadata for performing the attach + * @param target the target component + * @param targetDefinition metadata for performing the attach + * @param wire the wire + * @throws WiringException if an exception occurs during the attach operation + */ + <C extends Component, PWSD extends PhysicalWireSourceDefinition> + void attachToSource(C source, + PWSD sourceDefinition, + Component target, + PhysicalWireTargetDefinition targetDefinition, + Wire wire) + throws WiringException; + + /** + * Attaches a wire to a target component. + * + * @param source the source component + * @param sourceDefinition metadata for performing the attach + * @param target the target component + * @param targetDefinition metadata for performing the attach + * @param wire the wire + * @throws WiringException if an exception occurs during the attach operation + */ + <C extends Component, PWTD extends PhysicalWireTargetDefinition> + void attachToTarget(Component source, + PhysicalWireSourceDefinition sourceDefinition, + C target, + PWTD targetDefinition, + Wire wire) throws WiringException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java new file mode 100644 index 0000000000..d13626ad03 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.net.URI; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.tuscany.spi.AbstractLifecycle; +import org.apache.tuscany.spi.event.Event; +import org.apache.tuscany.spi.event.EventFilter; +import org.apache.tuscany.spi.event.RuntimeEventListener; +import org.apache.tuscany.spi.event.TrueFilter; + +/** + * Functionality common to all <code>SCAObject<code> implementations + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractSCAObject extends AbstractLifecycle implements SCAObject { + protected static final EventFilter TRUE_FILTER = new TrueFilter(); + protected Map<EventFilter, List<RuntimeEventListener>> listeners; + protected final URI uri; + + public AbstractSCAObject(URI uri) { + assert uri != null; + this.uri = uri; + } + + public URI getUri() { + return uri; + } + + public void addListener(RuntimeEventListener listener) { + addListener(TRUE_FILTER, listener); + } + + public void removeListener(RuntimeEventListener listener) { + assert listener != null : "Listener cannot be null"; + synchronized (getListeners()) { + for (List<RuntimeEventListener> currentList : getListeners().values()) { + for (RuntimeEventListener current : currentList) { + if (current == listener) { + currentList.remove(current); + return; + } + } + } + } + } + + public void addListener(EventFilter filter, RuntimeEventListener listener) { + assert listener != null : "Listener cannot be null"; + synchronized (getListeners()) { + List<RuntimeEventListener> list = getListeners().get(filter); + if (list == null) { + list = new CopyOnWriteArrayList<RuntimeEventListener>(); + listeners.put(filter, list); + } + list.add(listener); + } + } + + public void publish(Event event) { + assert event != null : "Event object was null"; + for (Map.Entry<EventFilter, List<RuntimeEventListener>> entry : getListeners().entrySet()) { + if (entry.getKey().match(event)) { + for (RuntimeEventListener listener : entry.getValue()) { + listener.onEvent(event); + } + } + } + } + + protected Map<EventFilter, List<RuntimeEventListener>> getListeners() { + if (listeners == null) { + listeners = new ConcurrentHashMap<EventFilter, List<RuntimeEventListener>>(); + } + return listeners; + } + + public String toString() { + return "[" + uri.toString() + "] in state [" + super.toString() + ']'; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AtomicComponent.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AtomicComponent.java new file mode 100644 index 0000000000..ed56f2dcda --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AtomicComponent.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import org.apache.tuscany.spi.ObjectCreationException; +import org.apache.tuscany.spi.ObjectFactory; + +/** + * The runtime instantiation of an SCA atomic, or leaf-type, component + * + * @version $Rev$ $Date$ + * @param <T> the type of the Java instance associated with this component + */ +public interface AtomicComponent<T> extends Component { + + /** + * Returns true if component instances should be eagerly initialized. + * + * @return true if component instances should be eagerly initialized + */ + boolean isEagerInit(); + + /** + * Returns the initialization level for this component. + * + * @return the initialization level for this component + */ + int getInitLevel(); + + /** + * Returns the idle time allowed between operations in milliseconds if the implementation is conversational. + * + * @return the idle time allowed between operations in milliseconds if the implementation is conversational + */ + long getMaxIdleTime(); + + /** + * Returns the maximum age a conversation may remain active in milliseconds if the implementation is + * conversational. + * + * @return the maximum age a conversation may remain active in milliseconds if the implementation is conversational + */ + long getMaxAge(); + + /** + * Create a new implementation instance, fully injected with all property and reference values. + * The instance's lifecycle callbacks must not have been called. + * + * @return a wrapper for a new implementation instance + * @throws ObjectCreationException if there was a problem instantiating the implementation + */ + InstanceWrapper<T> createInstanceWrapper() throws ObjectCreationException; + + /** + * Create an ObjectFactory that returns an instance of this AtomicComponent. + * + * @return an ObjectFactory that returns an instance of this AtomicComponent + */ + ObjectFactory<T> createObjectFactory(); + + /** + * Creates a new implementation instance, generally used as a callback by a {@link + * org.apache.tuscany.spi.component.ScopeContainer}. + * + * @return the instance + * @throws ObjectCreationException + */ + @Deprecated + Object createInstance() throws ObjectCreationException; + + /** + * Removes an implementation instance associated with the current invocation context. + * + * @throws ComponentException + */ + @Deprecated + void removeInstance() throws ComponentException; + + /** + * Returns the target instance associated with the component. A target instance is the actual object a request is + * dispatched to sans wire chain. + * + * @throws TargetResolutionException + */ + @Deprecated + Object getTargetInstance() throws TargetResolutionException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Component.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Component.java new file mode 100644 index 0000000000..1b714bde1f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Component.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.util.List; +import java.util.Map; + +import org.osoa.sca.ComponentContext; + +import org.apache.tuscany.spi.model.PropertyValue; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.wire.Wire; + +/** + * The runtime instantiation of an SCA component + * + * @version $$Rev$$ $$Date$$ + */ +public interface Component extends Invocable { + + /** + * Returns the SCA ComponentContext for this component. + * + * @return the SCA ComponentContext for this component + */ + ComponentContext getComponentContext(); + + /** + * Returns a collection of wires for the component associated with a reference. + * + * @param name the reference name + * @return a collection of wires for the component associated with the reference + */ + List<Wire> getWires(String name); + + /** + * Returns the default property values associated with the component. + * + * @return default property values associated with the component. + */ + Map<String, PropertyValue<?>> getDefaultPropertyValues(); + + /** + * Sets the default property values associated with the component. + * + * @param defaultPropertyValues Default property values associated with the component. + */ + void setDefaultPropertyValues(Map<String, PropertyValue<?>> defaultPropertyValues); + + /** + * Returns the ScopeContainer responsible for managing implementation instance or null if a ScopeContainer is not + * associated with the Component + * + * @return the scope container + */ + ScopeContainer getScopeContainer(); + + /** + * Returns the component scope + * + * @return the component scope + */ + @Deprecated + Scope getScope(); + + /** + * Sets the scope container associated with the component + * + * @param scopeContainer the scope container associated with the component + */ + @Deprecated + void setScopeContainer(ScopeContainer scopeContainer); + + /** + * Returns true if invocation dispatching can be optimized, i.e. invocation chains are not required + * + * @return true if invocation dispatching can be optimized, i.e. invocation chains are not required + */ + @Deprecated + boolean isOptimizable(); + + /** + * Registers a service of this composite. + * + * @param service the service to add as a child + * @throws RegistrationException + */ + @Deprecated + void register(Service service) throws RegistrationException; + + /** + * Registers a reference of this composite. + * + * @param reference the reference to add as a child + * @throws RegistrationException + */ + @Deprecated + void register(Reference reference) throws RegistrationException; + + /** + * Returns the service with the given name or null if not found + * + * @param name the service name which is relative to the composite + * @return the service with the given name or null if not found + */ + @Deprecated + Service getService(String name); + + /** + * Returns the reference with the given name or null if not found + * + * @param name the reference name which is relative to the composite + * @return the reference with the given name or null if not found + */ + @Deprecated + Reference getReference(String name); + + /** + * Attaches a callback wire to the comoponent + * + * @param wire the wire to attach + */ + @Deprecated + void attachCallbackWire(Wire wire); + + /** + * Attaches a wire to a component reference + * + * @param wire the wire to attach + */ + @Deprecated + void attachWire(Wire wire); + + /** + * Attaches a set of wires to a component reference. Used for multiplicity. + * + * @param wires the wire to attach + */ + @Deprecated + void attachWires(List<Wire> wires); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentException.java new file mode 100644 index 0000000000..2007cbb6bc --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentException.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import org.apache.tuscany.api.TuscanyException; + +/** + * An checked exception encountered by an {@link org.apache.tuscany.spi.component.Component} + * + * @version $Rev$ $Date$ + */ +public abstract class ComponentException extends TuscanyException { + + protected ComponentException() { + } + + protected ComponentException(String message) { + super(message); + } + + protected ComponentException(String message, String identifier) { + super(message, identifier); + } + + protected ComponentException(String message, Throwable cause) { + super(message, cause); + } + + protected ComponentException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + protected ComponentException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java new file mode 100644 index 0000000000..8c414f8c23 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.net.URI; +import java.util.List; + +import org.apache.tuscany.spi.event.RuntimeEventListener; +import org.apache.tuscany.spi.idl.java.JavaServiceContract; + +/** + * Responsible for tracking and managing the component tree for a runtime instance. The tree corresponds to components + * deployed to the current runtime and hence may be sparse in comparison to the assembly component hierarchy for the SCA + * domain as parents and children may be distributed to different runtimes. + * + * @version $Rev$ $Date$ + */ +public interface ComponentManager extends RuntimeEventListener { + + /** + * Registers a component which will be managed by the runtime + * + * @param component the component + * @throws RegistrationException + */ + void register(Component component) throws RegistrationException; + + /** + * Deregisters a component + * + * @param component the component to deregister + * @throws RegistrationException + */ + void unregister(Component component) throws RegistrationException; + + /** + * Register a simple Java Object as a system component. This is primarily intended for use by bootstrap code to + * create the initial configuration components. + * + * @param uri the uri of the resulting component + * @param service the service contract the component should expose + * @param instance the Object that will become the component's implementation + * @throws RegistrationException + */ + <S, I extends S> void registerJavaObject(URI uri, JavaServiceContract<S> service, I instance) + throws RegistrationException; + + /** + * Register a simple Java Object as a system component. This is primarily intended for use by bootstrap code to + * create the initial configuration components. + * + * @param uri the name of the resulting component + * @param services the service contracts the component should expose + * @param instance the Object that will become the component's implementation + * @throws RegistrationException + */ + <S, I extends S> void registerJavaObject(URI uri, List<JavaServiceContract<?>> services, I instance) + throws RegistrationException; + + /** + * Returns the component with the given URI + * + * @param uri the component URI + * @return the component or null if not found + */ + Component getComponent(URI uri); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentRuntimeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentRuntimeException.java new file mode 100644 index 0000000000..8479681c75 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentRuntimeException.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 org.apache.tuscany.spi.component; + +import org.apache.tuscany.spi.CoreRuntimeException; + +/** + * An unchecked exception encountered by an {@link org.apache.tuscany.spi.component.Component} + * + * @version $Rev$ $Date$ + */ +public abstract class ComponentRuntimeException extends CoreRuntimeException { + + public ComponentRuntimeException() { + super(); + } + + public ComponentRuntimeException(String message) { + super(message); + } + + public ComponentRuntimeException(String message, String identifier) { + super(message, identifier); + } + + public ComponentRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public ComponentRuntimeException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public ComponentRuntimeException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/DuplicateNameException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/DuplicateNameException.java new file mode 100644 index 0000000000..b9ee834b55 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/DuplicateNameException.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Denotes an attempt to add an child to a composite component with a name equal to an existing child + * + * @version $Rev$ $Date$ + */ +public class DuplicateNameException extends RegistrationException { + + public DuplicateNameException(String message) { + super(message); + } + + public DuplicateNameException(String message, String identifier) { + super(message, identifier); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/GroupInitializationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/GroupInitializationException.java new file mode 100644 index 0000000000..d540262ad7 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/GroupInitializationException.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 org.apache.tuscany.spi.component; + +import java.util.List; + +/** + * @version $Rev$ $Date$ + */ +public class GroupInitializationException extends TargetResolutionException { + private final List<Exception> causes; + + /** + * Exception indicating a problem initializing a group of components. + * + * @param contextId an identified for the context being initialized + * @param causes the individual exceptions that occurred + */ + public GroupInitializationException(String contextId, List<Exception> causes) { + super(contextId); + this.causes = causes; + } + + /** + * Return the exceptions that occurred as the group was initialized. + * + * @return a list of exceptions that occurred + */ + public List<Exception> getCauses() { + return causes; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/IllegalTargetException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/IllegalTargetException.java new file mode 100644 index 0000000000..7eb37c3639 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/IllegalTargetException.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Thrown when a target for an operation is not of the required type + * + * @version $$Rev$$ $$Date$$ + */ +public class IllegalTargetException extends TargetResolutionException { + + public IllegalTargetException(String message, String identifier) { + super(message, identifier); + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InstanceWrapper.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InstanceWrapper.java new file mode 100644 index 0000000000..e00ca13f66 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InstanceWrapper.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import org.apache.tuscany.spi.component.TargetDestructionException; +import org.apache.tuscany.spi.component.TargetInitializationException; + +/** + * Provides lifecycle management for an implementation instance associated with an {@link + * org.apache.tuscany.spi.component.AtomicComponent} for use by the atomic component's associated {@link + * org.apache.tuscany.spi.component.ScopeContainer} + * + * @version $Rev$ $Date$ + */ +public interface InstanceWrapper<T> { + + T getInstance(); + + boolean isStarted(); + + void start() throws TargetInitializationException; + + void stop() throws TargetDestructionException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidAutowireInterface.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidAutowireInterface.java new file mode 100644 index 0000000000..20e5732dd4 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidAutowireInterface.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Thrown when an invalid interface is specified during autowire registration + * + * @version $Rev$ $Date$ + */ +public class InvalidAutowireInterface extends RegistrationException { + + public InvalidAutowireInterface(String message, String identifier) { + super(message, identifier); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidConversationSequenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidConversationSequenceException.java new file mode 100644 index 0000000000..21a1712e1a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidConversationSequenceException.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Denotes an unknown operation sequence in a conversation + * + * @version $Rev$ $Date$ + */ +public class InvalidConversationSequenceException extends TargetInvocationException { + + public InvalidConversationSequenceException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Invocable.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Invocable.java new file mode 100644 index 0000000000..1aabd99401 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Invocable.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.wire.TargetInvoker; + +/** + * @version $Rev$ $Date$ + * + */ +@Deprecated +public interface Invocable extends SCAObject { + + /** + * Callback to create a {@link org.apache.tuscany.spi.wire.TargetInvoker} which dispatches to a service offered this + * artifact + * + * @param targetName the service name + * @param operation the operation to invoke + * @return the target invoker + * @throws TargetInvokerCreationException + */ + @Deprecated + TargetInvoker createTargetInvoker(String targetName, Operation operation) throws TargetInvokerCreationException; + + /** + * Callback to create a {@link org.apache.tuscany.spi.wire.TargetInvoker} which dispatches to a service offered this + * artifact + * + * @param targetName the service name + * @param operation the operation to invoke + * @return the target invoker + * @throws TargetInvokerCreationException if an error is encountered creating the invoker + */ + @Deprecated + TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation) + throws TargetInvokerCreationException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/MalformedNameException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/MalformedNameException.java new file mode 100644 index 0000000000..de5225d12b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/MalformedNameException.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Denotes an attempt to add a child to a composite component with an illegal name + * + * @version $Rev$ $Date$ + */ +public class MalformedNameException extends RegistrationException { + + public MalformedNameException(Throwable e) { + super("Malformed name", e); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/PersistenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/PersistenceException.java new file mode 100644 index 0000000000..06940aaff7 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/PersistenceException.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Raised when an error persisting a component implementation instance is encountered + * + * @version $Rev$ $Date$ + */ +public class PersistenceException extends ComponentException { + public PersistenceException() { + } + + public PersistenceException(String message) { + super(message); + } + + public PersistenceException(String message, Throwable cause) { + super(message, cause); + } + + public PersistenceException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReactivationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReactivationException.java new file mode 100644 index 0000000000..4ef0929422 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReactivationException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Raised when an error is encountered reactivating a serialized instance + * + * @version $Rev$ $Date$ + */ +public class ReactivationException extends ComponentRuntimeException { + private String owner; + + public ReactivationException(String message) { + super(message); + } + + public ReactivationException(String message, String identifier, String ower) { + super(message, identifier); + this.owner = ower; + } + + public ReactivationException(Throwable cause) { + super(cause); + } + + public String getOwner() { + return owner; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Reference.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Reference.java new file mode 100644 index 0000000000..1ab107fd38 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Reference.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.util.List; + +import org.apache.tuscany.spi.model.ServiceContract; + +/** + * The runtime instantiation of an SCA reference + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public interface Reference extends SCAObject { + + /** + * Returns the contract for the reference. + * + * @return the contract for the reference. + */ + ServiceContract<?> getServiceContract(); + + /** + * Returns the collection of bindings configured for the reference. + * + * @return the collection of bindings configured for the reference. + */ + List<ReferenceBinding> getReferenceBindings(); + + /** + * Adds a binding the reference is configured with. + * + * @param binding the binding the reference is configured with. + */ + void addReferenceBinding(ReferenceBinding binding); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceBinding.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceBinding.java new file mode 100644 index 0000000000..32bc8f1624 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceBinding.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.net.URI; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.Wire; + +/** + * Manages an SCA reference configured with a binding + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public interface ReferenceBinding extends Invocable { + + /** + * Returns the binding qualified name + * + * @return the binding qualified name + */ + QName getBindingType(); + + /** + * Returns the wire for flowing a request through the reference + */ + Wire getWire(); + + /** + * Sets the wire wire for flowing a request through the reference + */ + void setWire(Wire wire); + + /** + * Returns the service contract for the binding + * + * @return the service contract for the binding + */ + ServiceContract<?> getBindingServiceContract(); + + /** + * Returns the target URI for the binding + * + * @return the target URI for the binding + */ + URI getTargetUri(); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/RegistrationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/RegistrationException.java new file mode 100644 index 0000000000..b776c49c00 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/RegistrationException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Thrown when an error is encountered registering a service or reference on a composite + * + * @version $$Rev$$ $$Date$$ + */ +public abstract class RegistrationException extends ComponentException { + public RegistrationException() { + } + + public RegistrationException(String message) { + super(message); + } + + public RegistrationException(String message, String identifier) { + super(message, identifier); + } + + public RegistrationException(String message, Throwable cause) { + super(message, cause); + } + + public RegistrationException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAExternalizable.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAExternalizable.java new file mode 100644 index 0000000000..6454e66369 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAExternalizable.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * A serialization contract for runtime SCA artifacts. When an instance is deserialized, runtime services defined in + * this contract must be set before reactivating the instance + * + * @version $Rev$ $Date$ + */ +public interface SCAExternalizable { + + /** + * Sets the current work context + * + * @param context the current work context + */ + void setWorkContext(WorkContext context); + + /** + * Callback after all values have been set prior to making the instance available in the runtime + * + * @throws org.apache.tuscany.spi.component.ReactivationException + * + */ + void reactivate() throws ReactivationException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java new file mode 100644 index 0000000000..d92385cd6f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.net.URI; + +import org.apache.tuscany.spi.Lifecycle; +import org.apache.tuscany.spi.event.EventPublisher; + +/** + * Represents the base SCA artifact type in an assembly + * + * @version $Rev$ $Date$ + */ +public interface SCAObject extends EventPublisher, Lifecycle { + + /** + * Returns the artifact URI + * + * @return the artifact URI + */ + URI getUri(); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectInputStream.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectInputStream.java new file mode 100644 index 0000000000..052a1d053b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectInputStream.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectStreamClass; + +/** + * Deserializes an object based on the thread context classloader and provides special handling for {@link + * SCAExternalizable} + * + * @version $Rev$ $Date$ + */ +public class SCAObjectInputStream extends ObjectInputStream { + private final ClassLoader classLoader; + private WorkContext context; + + public SCAObjectInputStream(InputStream in, WorkContext context) throws IOException, SecurityException { + super(in); + this.context = context; + this.classLoader = Thread.currentThread().getContextClassLoader(); + enableResolveObject(true); + } + + protected Class resolveClass(ObjectStreamClass streamClass) throws IOException, ClassNotFoundException { + return classLoader.loadClass(streamClass.getName()); + } + + protected Object resolveObject(Object obj) throws IOException { + if (obj instanceof SCAExternalizable) { + SCAExternalizable ext = (SCAExternalizable) obj; + ext.setWorkContext(context); + ext.reactivate(); + } + return obj; + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStartException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStartException.java new file mode 100644 index 0000000000..a712b1b0eb --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStartException.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import org.apache.tuscany.spi.CoreRuntimeException; + +/** + * Denotes an error starting an SCAObject + * + * @version $Rev$ $Date$ + */ +public class SCAObjectStartException extends CoreRuntimeException { + + public SCAObjectStartException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStopException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStopException.java new file mode 100644 index 0000000000..9f430bc414 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStopException.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import org.apache.tuscany.spi.CoreRuntimeException; + +/** + * Denotes an error stopping an SCAObject + * + * @version $Rev$ $Date$ + */ +public class SCAObjectStopException extends CoreRuntimeException { + + public SCAObjectStopException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainer.java new file mode 100644 index 0000000000..ef09521a95 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainer.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.net.URI; + +import org.apache.tuscany.spi.Lifecycle; +import org.apache.tuscany.spi.event.RuntimeEventListener; +import org.apache.tuscany.spi.model.Scope; + + +/** + * Manages the lifecycle and visibility of instances associated with a an {@link AtomicComponent}. + * + * @version $Rev$ $Date$ + * @param <KEY> the type of IDs that this container uses to identify its contexts. + * For example, for COMPOSITE scope this could be the URI of the composite component, + * or for HTTP Session scope it might be the HTTP session ID. + */ +public interface ScopeContainer<KEY> extends Lifecycle, RuntimeEventListener { + + /** + * Returns the Scope that this container supports. + * + * @return the Scope that this container supports + */ + Scope getScope(); + + /** + * Registers a component with the scope. + * + * @param component the component to register + * @param groupId the id of the group to associate this component with + */ + <T> void register(AtomicComponent<T> component, URI groupId); + + /** + * Unregisters a component with the scope. + * + * @param component the component to unregister + */ + <T> void unregister(AtomicComponent<T> component); + + /** + * Start a new context with the supplied ID. + * + * @param contextId an ID that uniquely identifies the context. + * @param groupId the group of components to associate with this context + * @throws GroupInitializationException if an exception was thrown by any eagerInit component + */ + void startContext(KEY contextId, URI groupId) throws GroupInitializationException; + + /** + * Stop the context with the supplied ID. + * + * @param contextId an ID that uniquely identifies the context. + */ + void stopContext(KEY contextId); + + /** + * Returns an instance wrapper associated with the current scope context, creating one if necessary + * + * @param <T> the type of the target instance + * @param component the component + * @param contextId the id for the scope context + * @return the wrapper for the target instance + * @throws TargetResolutionException if there was a problem instantiating the target instance + */ + <T> InstanceWrapper<T> getWrapper(AtomicComponent<T> component, KEY contextId) throws TargetResolutionException; + + /** + * Returns an implementation instance associated with the current scope context. + * If no instance is found, a {@link TargetNotFoundException} is thrown. + * + * @param <T> the type of the target instance + * @param component the component + * @param contextId the id for the scope context + * @return the wrapper for the target instance + * @throws TargetResolutionException if there was a problem instantiating the target instance + */ + <T> InstanceWrapper<T> getAssociatedWrapper(AtomicComponent<T> component, KEY contextId) + throws TargetResolutionException; + + /** + * Return a wrapper after use (for example, after invoking the instance). + * + * @param <T> the type of the target instance + * @param component the component + * @param contextId the id for the scope context + * @param wrapper the wrapper for the target instance being returned + * @throws TargetDestructionException if there was a problem returning the target instance + */ + <T> void returnWrapper(AtomicComponent<T> component, InstanceWrapper<T> wrapper, KEY contextId) + throws TargetDestructionException; + + /** + * Removes a component implementation instance associated with the current context from persistent storage + * + * @param component the owning component + * @throws PersistenceException if there was a problem removing the instance + */ + <T> void remove(AtomicComponent<T> component) throws PersistenceException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainerMonitor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainerMonitor.java new file mode 100644 index 0000000000..3e7649d59e --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainerMonitor.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import org.apache.tuscany.api.annotation.LogLevel; + +/** + * Defines monitor events for scope containers + * + * @version $Rev$ $Date$ + */ +public interface ScopeContainerMonitor { + + @LogLevel("SEVERE") + void eagerInitializationError(Exception e); + + @LogLevel("SEVERE") + void destructionError(TargetDestructionException e); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeRegistry.java new file mode 100644 index 0000000000..91cf1d9b6e --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeRegistry.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import org.apache.tuscany.spi.model.Scope; + +/** + * Manages {@link ScopeContainer}s in the runtime + * + * @version $$Rev$$ $$Date$$ + */ +public interface ScopeRegistry { + + /** + * Returns the scope container for the given scope or null if one not found + * + * @param scope the scope + * @return the scope container for the given scope or null if one not found + */ + ScopeContainer getScopeContainer(Scope scope); + + void register(ScopeContainer container); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Service.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Service.java new file mode 100644 index 0000000000..fc0708f7c1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Service.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.util.List; + +import org.apache.tuscany.spi.model.ServiceContract; + +/** + * The runtime instantiation of an SCA service + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public interface Service extends SCAObject { + + /** + * Returns the contract for the service. + * + * @return the contract for the service. + */ + ServiceContract<?> getServiceContract(); + + /** + * Returns the collection of bindings configured for the service. + * + * @return the collection of bindings configured for the service. + */ + List<ServiceBinding> getServiceBindings(); + + /** + * Adds a binding the service is exposed over. + * + * @param binding the binding the service is exposed over. + */ + void addServiceBinding(ServiceBinding binding); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ServiceBinding.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ServiceBinding.java new file mode 100644 index 0000000000..60cd822913 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ServiceBinding.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.Wire; + +/** + * The runtime instantiation of an SCA service binding. + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public interface ServiceBinding extends Invocable { + + /** + * Returns the binding qualified name + * + * @return the binding qualified name + */ + QName getBindingType(); + + /** + * Get the ServiceContract for the binding + * + * @return the ServiceContract for the binding + */ + ServiceContract<?> getBindingServiceContract(); + + Wire getWire(); + + void setWire(Wire wire); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetDestructionException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetDestructionException.java new file mode 100644 index 0000000000..5f521f9b0a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetDestructionException.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Denotes an error destroying a target + * + * @version $Rev$ $Date$ + */ +public class TargetDestructionException extends TargetResolutionException { + + public TargetDestructionException(String message, String identifier) { + super(message, identifier); + } + + public TargetDestructionException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + + public TargetDestructionException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetException.java new file mode 100644 index 0000000000..6b8278cf8b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetException.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 org.apache.tuscany.spi.component; + +/** + * Denotes an error while performing an operation on a target component implementation instance + * + * @version $Rev$ $Date$ + */ +public abstract class TargetException extends ComponentException { + + public TargetException(String message) { + super(message); + } + + + public TargetException(String message, String identifier) { + super(message, identifier); + } + + public TargetException(String message, Throwable cause) { + super(message, cause); + } + + + public TargetException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public TargetException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInitializationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInitializationException.java new file mode 100644 index 0000000000..eaea4c3bc9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInitializationException.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Denotes an error initializing a target + * + * @version $Rev$ $Date$ + */ +public class TargetInitializationException extends TargetResolutionException { + + public TargetInitializationException(String message, String identifier) { + super(message, identifier); + } + + public TargetInitializationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public TargetInitializationException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvocationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvocationException.java new file mode 100644 index 0000000000..1fc2b24f5b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvocationException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Raised when an error is encountered during a target invocation + * + * @version $Rev$ $Date$ + */ +public class TargetInvocationException extends TargetException { + + public TargetInvocationException(String message) { + super(message); + } + + public TargetInvocationException(String message, String identifier) { + super(message, identifier); + } + + public TargetInvocationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInvocationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvokerCreationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvokerCreationException.java new file mode 100644 index 0000000000..da44ec82ae --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvokerCreationException.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 org.apache.tuscany.spi.component; + +/** + * Denotes an error creating a {@link org.apache.tuscany.spi.wire.TargetInvoker} + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public abstract class TargetInvokerCreationException extends ComponentException { + + public TargetInvokerCreationException() { + } + + public TargetInvokerCreationException(String message) { + super(message); + } + + public TargetInvokerCreationException(String message, String identifier) { + super(message, identifier); + } + + public TargetInvokerCreationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInvokerCreationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public TargetInvokerCreationException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetNotFoundException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetNotFoundException.java new file mode 100644 index 0000000000..cd6996789c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetNotFoundException.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Thrown when a target of an operation cannot be found + * + * @version $$Rev$$ $$Date$$ + */ +public class TargetNotFoundException extends TargetResolutionException { + + public TargetNotFoundException(String message) { + super(message); + } + + public TargetNotFoundException(String message, String identifier) { + super(message, identifier); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetResolutionException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetResolutionException.java new file mode 100644 index 0000000000..858fa9415d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetResolutionException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +/** + * Denotes an error retrieving a target instance + * + * @version $Rev$ $Date$ + */ +public class TargetResolutionException extends TargetException { + + public TargetResolutionException(String message) { + super(message); + } + + public TargetResolutionException(String message, String identifier) { + super(message, identifier); + } + + public TargetResolutionException(String message, Throwable cause) { + super(message, cause); + } + + public TargetResolutionException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java new file mode 100644 index 0000000000..14b190f99b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.spi.wire.Wire; + +/** + * Implementations track information associated with a request as it is processed by the runtime + * + * @version $Rev$ $Date$ + */ +public interface WorkContext { + + /** + * Returns the unique key for the given identifier associated with the current request + */ + Object getIdentifier(Object type); + + /** + * Sets the unique key for the given identifier associated with the current request + */ + void setIdentifier(Object type, Object identifier); + + /** + * Clears the unique key for the given identifier associated with the current request + */ + void clearIdentifier(Object type); + + /** + * Clears all identifiers associated with the current request + */ + void clearIdentifiers(); + + /** + * Returns an ordered list of callback URIs for the current context. Ordering is based on the sequence of service + * invocations for collocated components + * + * @return the current list of callback URIs + * @Deprecated + */ + LinkedList<URI> getCallbackUris(); + + /** + * Sets an ordered list of callback URIs for the current context. Ordering is based on the sequence of service + * invocations for collocated components + * + * @Deprecated + */ + void setCallbackUris(LinkedList<URI> uris); + + /** + * Returns an ordered list of callback wures for the current context. Ordering is based on the sequence of service + * invocations for collocated components + * + * @return the current list of callback wires + */ + LinkedList<Wire> getCallbackWires(); + + /** + * Sets an ordered list of callback wires for the current context. Ordering is based on the sequence of service + * invocations for collocated components + */ + void setCallbackWires(LinkedList<Wire> wires); + + /** + * Returns the correlation id for the current invocation or null if not available. Transports may use correlation + * ids for message routing. + * + * @return the correlation id for the current invocation or null + */ + Object getCorrelationId(); + + /** + * Sets the correlation id for the current invocation. Transports may use correlation ids for message routing. + * + * @param id the correlation id + */ + void setCorrelationId(Object id); + + /** + * Returns the current atomic component as a request is processed or null if it is not being tracked. Note that the + * current atomic component is typically only tracked during persistence operations involving implementation + * instances + * + * @return the current atomic component as a request is processed or null + */ + AtomicComponent getCurrentAtomicComponent(); + + /** + * Sets the current atomic component that is handling processing of a request. Note that in most cases it will not + * be necessary to track this in the rumtime + * + * @param component the current atomic component + */ + void setCurrentAtomicComponent(AtomicComponent component); + + /** + * Removes and returns the name of the last remotable service to handle the current request + * + * @return the name of the last remotable service to handle the current request or null + */ + String popServiceName(); + + /** + * Returns the name of the last remotable service to handle the current request + * + * @return the name of the last remotable service to handle the current request or null + */ + String getCurrentServiceName(); + + /** + * Adds the name of the last remotable service to handle the current request + * + * @param name the name of the last remotable service to handle the current request or null + */ + void pushServiceName(String name); + + /** + * Clears the stack of current service names + */ + void clearServiceNames(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java new file mode 100644 index 0000000000..a33b40a785 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.databinding; + +import org.apache.tuscany.spi.model.DataType; + +/** + * DataBinding represents a data representation, for example, SDO, JAXB and AXIOM + */ +public interface DataBinding { + /** + * The name of a databinding should be case-insensitive and unique + * + * @return The name of the databinding + */ + String getName(); + + /** + * Introspect a java class or interface to create a DataType model + * + * @param javaType The java class or interface to be introspected + * @return The DataType or null if the java type is not supported by this databinding + */ + DataType introspect(Class<?> javaType); + + /** + * Introspect the data to figure out the corresponding data type + * + * @param value The object to be checked + * @return The DataType or null if the java type is not supported by this databinding + */ + DataType introspect(Object value); + + /** + * Provide a WrapperHandler for this databinding + * + * @return A wrapper handler which can handle wrapping/wrapping for this databinding + */ + WrapperHandler getWrapperHandler(); + + /** + * Make a copy of the object for "pass-by-value" semantics + * + * @param object object to copy + * @return copy of the object passed in as argument + */ + Object copy(Object object); + + /** + * Get the type mapper for simple types + * + * @return The databinding-specific simple type mapper + */ + SimpleTypeMapper getSimpleTypeMapper(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.java new file mode 100644 index 0000000000..ba47401cc2 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.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 org.apache.tuscany.spi.databinding; + +import org.apache.tuscany.spi.model.DataType; + +/** + * The registry for data bindings + */ +public interface DataBindingRegistry { + /** + * Register a data binding + * + * @param dataBinding + */ + void register(DataBinding dataBinding); + + /** + * Look up a data binding by id + * + * @param id The name of the databinding + * @return The databinding + */ + DataBinding getDataBinding(String id); + + /** + * Unregister a data binding + * + * @param id + * @return The unregistered databinding + */ + DataBinding unregister(String id); + + /** + * Introspect the java class to figure out what DataType supports it + * + * @param javaType The java class or interface + * @return A DataType representing the java type or null if no databinding + * recognizes the java type + */ + DataType introspectType(Class<?> javaType); + + /** + * Introspect the value to figure out the corresponding DataType + * + * @param value The object value + * @return A DataType representing the value or null if no databinding + * recognizes the value + */ + DataType introspectType(Object value); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java new file mode 100755 index 0000000000..dcb83426d1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding; + +/** + * Data pipe allows a data source pushes data into its sink and pipe the data into its result + * + * @param <S> The data binding type of the sink + * @param <R> The data binding type of the result + */ +public interface DataPipe<S, R> extends Transformer { + + /** + * Returns a sink (for example, java.io.OutputStream, java.io.Writer or org.xml.sax.ContentHandler) to receive data + * pushed by the source + * + * @return The sink to consume data + */ + S getSink(); + + /** + * Returns the data populated by the sink + * + * @return R the result + */ + R getResult(); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java new file mode 100755 index 0000000000..0983ed46fd --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding; + +import java.util.Map; + +import org.apache.tuscany.spi.model.DataType; + +/** + * This interface will be used as a Tuscany system service to perform data mediations + * <p/> + * Mediate the data from one type to the other one + */ +public interface Mediator { + + /** + * Mediate the data from the source type to the target type + * + * @param source The data to be mediated + * @param sourceDataType Data type for the source data + * @param targetDataType Data type for the target data + * @param context the context for the mediation + * @return the result of the mediation + */ + Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map<Class<?>, Object> context); + + /** + * Mediate the source data into the target which is a sink to receive the data + * + * @param source The data to be mediated + * @param target The sink to receive data + * @param sourceDataType Data type for the source data + * @param targetDataType Data type for the target data + * @param context the context for the mediation + */ + void mediate(Object source, + Object target, + DataType sourceDataType, + DataType targetDataType, + Map<Class<?>, Object> context); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PullTransformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PullTransformer.java new file mode 100644 index 0000000000..21e8cc2750 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PullTransformer.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding; + +/** + * PullTransformer transforms data from one binding format to the other one which can be directly consumed + * + * @param <S> The source data type + * @param <R> the target data type + */ +public interface PullTransformer<S, R> extends Transformer { + /** + * Transform source data into the result type. + * + * @param source The source data + * @param context The context for the transformation + * @return The transformed result + */ + R transform(S source, TransformationContext context); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PushTransformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PushTransformer.java new file mode 100644 index 0000000000..d68b6aa772 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PushTransformer.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding; + +/** + * A transformer that pushes data from its source into the sink + * + * @param <S> + * @param <R> + */ +public interface PushTransformer<S, R> extends Transformer { + /** + * @param source The source data + * @param sink The sink to receive the data + * @param context + */ + void transform(S source, R sink, TransformationContext context); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java new file mode 100644 index 0000000000..0da681c71e --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.databinding; + +import org.apache.tuscany.spi.model.TypeInfo; + +/** + * Type Mapper between XML schema simple data types and java objects + */ +public interface SimpleTypeMapper { + /** + * Parse the XML lexical representation into a java object + * @param simpleType The XSD simple type + * @param value the XML lexical representation + * @param context The context of the transformation + * @return A java object for the XML value + */ + Object toJavaObject(TypeInfo simpleType, String value, TransformationContext context); + /** + * Create the XML lexical representation for a java object + * @param simpleType The XSD simple type + * @param obj The java object + * @param context The context of the transformation + * @return The XML lexical representation + */ + String toXMLLiteral(TypeInfo simpleType, Object obj, TransformationContext context); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.java new file mode 100755 index 0000000000..efddfb8fc0 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.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 org.apache.tuscany.spi.databinding; + +import java.util.Map; + +import org.apache.tuscany.spi.model.DataType; + +/** + * Context for data transformation + */ +public interface TransformationContext { + /** + * Get the source data type + * + * @return the source data type + */ + DataType getSourceDataType(); + + /** + * Get the target data type + * + * @return the target datatype + */ + DataType getTargetDataType(); + + /** + * Set the source data type + * + * @param sourceDataType the source data type + */ + void setSourceDataType(DataType sourceDataType); + + /** + * Set the target data type + * + * @param targetDataType the target data type + */ + void setTargetDataType(DataType targetDataType); + + /** + * Get the classloader + * + * @return the classloader + */ + ClassLoader getClassLoader(); + + /** + * Get a map of metadata + * + * @return the map of metadata + */ + Map<Class<?>, Object> getMetadata(); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java new file mode 100755 index 0000000000..9b57e1cf70 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * Reports problems during data transformation + */ +public class TransformationException extends TuscanyRuntimeException { + + private static final long serialVersionUID = 7662385613693006428L; + + public TransformationException() { + super(); + } + + public TransformationException(String message, Throwable cause) { + super(message, cause); + } + + public TransformationException(String message) { + super(message); + } + + public TransformationException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Transformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Transformer.java new file mode 100755 index 0000000000..2f969e979d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Transformer.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding; + +/** + * A transformer provides the data transformation from source type to target type. The cost of the transformation is + * modeled as weight. + */ +public interface Transformer { + /** + * Get the source type that this transformer transforms data from. The type is used as the key when the transformer + * is registered with TransformerRegistry. + * + * @return A key indentifying the source type + */ + String getSourceDataBinding(); + + /** + * Get the target type that this transformer transforms data into. The type is used as the key when the transformer + * is registered with TransformerRegistry. + * + * @return A key indentifying the target type + */ + String getTargetDataBinding(); + + /** + * Get the cost of the transformation. The weight can be used to choose the most efficient path if there are more + * than one available from the source to the target. + * + * @return An integer representing the cost of the transformation + */ + int getWeight(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformerRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformerRegistry.java new file mode 100755 index 0000000000..18a01b7853 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformerRegistry.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding; + +import java.util.List; + +/** + * Registry for data transformers + */ +public interface TransformerRegistry { + /** + * Register a transformer + * + * @param sourceDataBinding + * @param targetDataBinding + * @param weight + * @param transformer + */ + void registerTransformer(String sourceDataBinding, + String targetDataBinding, + int weight, + Transformer transformer); + + /** + * Register a transformer + * + * @param transformer + */ + void registerTransformer(Transformer transformer); + + /** + * Unregister a transformer + * + * @param sourceDataBinding + * @param targetDataBinding + * @return true if sucessfully unregistered + */ + boolean unregisterTransformer(String sourceDataBinding, String targetDataBinding); + + /** + * Get the direct Transformer which can transform data from source type to result type + * + * @param sourceDataBinding + * @param targetDataBinding + * @return the transformer + */ + Transformer getTransformer(String sourceDataBinding, String targetDataBinding); + + /** + * Get the a chain of Transformers which can transform data from source type to result type + * + * @param sourceDataBinding + * @param targetDataBinding + * @return the list of transformers + */ + List<Transformer> getTransformerChain(String sourceDataBinding, String targetDataBinding); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/WrapperHandler.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/WrapperHandler.java new file mode 100644 index 0000000000..1cb8d00bf5 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/WrapperHandler.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.databinding; + +import org.apache.tuscany.spi.model.ElementInfo; + +/** + * A contract for transformers to deal with wrapping/unwrapping for WSDL wrapper style operations + */ +public interface WrapperHandler<T> { + /** + * Create a wrapper element + * + * @param element The XSD element + * @param context The transformation context + * @return An object representing the wrapper element + */ + T create(ElementInfo element, TransformationContext context); + + /** + * Set child element for the wrapper + * + * @param wrapper The wrapper + * @param i The index + * @param childElement The XSD element + * @param value The value of the child + */ + void setChild(T wrapper, int i, ElementInfo childElement, Object value); + + /** + * Get child element from the wrapper + * + * @param wrapper The wrapper + * @param i The index + * @param element The XSD element + * @return The value of the child + */ + Object getChild(T wrapper, int i, ElementInfo element); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DOMHelper.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DOMHelper.java new file mode 100644 index 0000000000..2b927b8e55 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DOMHelper.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding.extension; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Helper for DOM + */ +public final class DOMHelper { + private static final DocumentBuilderFactory FACTORY = DocumentBuilderFactory.newInstance(); + static { + FACTORY.setNamespaceAware(true); + } + + private DOMHelper() { + } + + public static Document newDocument() throws ParserConfigurationException { + return newDocumentBuilder().newDocument(); + } + + public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { + return FACTORY.newDocumentBuilder(); + } + + public static QName getQName(Node node) { + String ns = node.getNamespaceURI(); + if (ns == null) { + ns = ""; + } + // node.getLocalName() will return null if it is created using DOM Level + // 1 method + // such as createElement() + return new QName(ns, node.getNodeName()); + } + + public static Element createElement(Document document, QName name) { + String prefix = name.getPrefix(); + String qname = + (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name + .getLocalPart(); + return document.createElementNS(name.getNamespaceURI(), qname); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtension.java new file mode 100644 index 0000000000..bc9483f01f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtension.java @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding.extension; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamClass; +import java.io.OutputStream; +import java.io.Serializable; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import org.apache.tuscany.spi.databinding.DataBinding; +import org.apache.tuscany.spi.databinding.DataBindingRegistry; +import org.apache.tuscany.spi.databinding.SimpleTypeMapper; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.model.DataType; + +/** + * Base Implementation of DataBinding + * + * @version $Rev$ $Date$ + */ +@Service(DataBinding.class) +@Scope("COMPOSITE") +@EagerInit +public abstract class DataBindingExtension implements DataBinding { + + protected DataBindingRegistry registry; + + protected Class<?> baseType; + + protected String name; + + /** + * Create a databinding with the base java type whose name will be used as the name of the databinding + * + * @param baseType The base java class or interface representing the databinding, for example, org.w3c.dom.Node + */ + protected DataBindingExtension(Class<?> baseType) { + this(baseType.getName(), baseType); + } + + /** + * Create a databinding with the name and base java type + * + * @param name The name of the databinding + * @param baseType The base java class or interface representing the databinding, for example, org.w3c.dom.Node + */ + protected DataBindingExtension(String name, Class<?> baseType) { + this.name = name; + this.baseType = baseType; + } + + @Reference + public void setDataBindingRegistry(DataBindingRegistry registry) { + this.registry = registry; + } + + @Init + public void init() { + registry.register(this); + } + + public DataType introspect(Class<?> javaType) { + if (baseType == null || javaType == null) { + return null; + } + if (baseType.isAssignableFrom(javaType)) { + return new DataType<Class>(name, javaType, baseType); + } else { + return null; + } + } + + public DataType introspect(Object value) { + if (value == null) { + return null; + } else { + return introspect(value.getClass()); + } + } + + public final String getName() { + return name; + } + + /** + * @see org.apache.tuscany.spi.databinding.DataBinding#getWrapperHandler() + */ + public WrapperHandler getWrapperHandler() { + return null; + } + + public Object copy(Object arg) { + if (arg == null) { + return null; + } + final Class clazz = arg.getClass(); + if (String.class == clazz || clazz.isPrimitive() || Number.class.isAssignableFrom(clazz) + || Boolean.class.isAssignableFrom(clazz) || Character.class.isAssignableFrom(clazz) + || Byte.class.isAssignableFrom(clazz)) { + // Immutable classes + return arg; + } + try { + if (arg instanceof Serializable) { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = getObjectOutputStream(bos); + oos.writeObject(arg); + oos.close(); + bos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = getObjectInputStream(bis, clazz.getClassLoader()); + Object objectCopy = ois.readObject(); + ois.close(); + bis.close(); + return objectCopy; + } else { + //return arg; + throw new IllegalArgumentException( + "Pass-by-value is not supported for the given object"); + } + } catch (Exception e) { + throw new IllegalArgumentException( + "Pass-by-value is not supported for the given object", e); + } + } + + protected ObjectOutputStream getObjectOutputStream(OutputStream os) throws IOException { + return new ObjectOutputStream(os); + } + + protected ObjectInputStream getObjectInputStream(InputStream is, final ClassLoader cl) + throws IOException { + ObjectInputStream ois = new ObjectInputStream(is) { + @Override + protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { + try { + return Class.forName(desc.getName(), false, cl); + } catch (ClassNotFoundException e) { + return super.resolveClass(desc); + } + } + + }; + return ois; + } + + public SimpleTypeMapper getSimpleTypeMapper() { + return new SimpleTypeMapperExtension(); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/Java2SimpleTypeTransformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/Java2SimpleTypeTransformer.java new file mode 100644 index 0000000000..3150dfad3d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/Java2SimpleTypeTransformer.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding.extension; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.SimpleTypeMapper; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.ElementInfo; +import org.apache.tuscany.spi.model.TypeInfo; + +/** + * Transformer to convert data from a simple java object to a databinding's representation + */ +public abstract class Java2SimpleTypeTransformer<T> extends TransformerExtension<Object, T> implements + PullTransformer<Object, T> { + + protected SimpleTypeMapper mapper; + + public Java2SimpleTypeTransformer() { + this.mapper = new SimpleTypeMapperExtension(); + } + + public Java2SimpleTypeTransformer(SimpleTypeMapper mapper) { + this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperExtension(); + } + + public T transform(Object source, TransformationContext context) { + ElementInfo element = + (ElementInfo) context.getTargetDataType().getMetadata(ElementInfo.class.getName()); + TypeInfo simpleType = (TypeInfo) element.getType(); + String text = mapper.toXMLLiteral(simpleType, source, context); + return createElement(element, text, context); + } + + public Class getSourceType() { + return Object.class; + } + + public int getWeight() { + return 10000; + } + + protected abstract T createElement(ElementInfo element, String literal, TransformationContext context); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleType2JavaTransformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleType2JavaTransformer.java new file mode 100644 index 0000000000..2304990e88 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleType2JavaTransformer.java @@ -0,0 +1,72 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.databinding.extension;
+
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.SimpleTypeMapper;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+
+/**
+ * Transformer to convert data from a databinding's representation of simple types to Java Objects
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class SimpleType2JavaTransformer<T> extends TransformerExtension<T, Object> implements
+ PullTransformer<T, Object> {
+
+ protected SimpleTypeMapper mapper;
+
+ public SimpleType2JavaTransformer() {
+ this.mapper = new SimpleTypeMapperExtension();
+ }
+
+ public SimpleType2JavaTransformer(SimpleTypeMapper mapper) {
+ this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperExtension();
+ }
+
+ public Object transform(T source, TransformationContext context) {
+ TypeInfo simpleType = (TypeInfo) context.getSourceDataType().getMetadata(TypeInfo.class.getName());
+ if (simpleType == null) {
+ ElementInfo element =
+ (ElementInfo) context.getSourceDataType().getMetadata(ElementInfo.class.getName());
+ simpleType = element.getType();
+ }
+
+ return mapper.toJavaObject(simpleType, getText(source), context);
+ }
+
+ public Class getTargetType() {
+ return Object.class;
+ }
+
+ public int getWeight() {
+ // Cannot be used for imtermediate
+ return 10000;
+ }
+
+ /**
+ * Get the string value from the source
+ *
+ * @param source the source to return the string from
+ * @return A string
+ */
+ protected abstract String getText(T source);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java new file mode 100644 index 0000000000..5ce3eb978e --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java @@ -0,0 +1,415 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.databinding.extension; + +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.SimpleTypeMapper; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.TypeInfo; + +public class SimpleTypeMapperExtension extends XSDDataTypeConverter implements SimpleTypeMapper { + + public static final int BASE64_ENCODING = 1; + public static final int HEXBIN_ENCODING = 2; + + public static final String SET = "set"; + + public static final Map<Class, String> JAVA2XML = new HashMap<Class, String>(); + + public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; + + public static final Map<String, Class> XML2JAVA = new HashMap<String, Class>(); + + public static final QName XSD_ANY = new QName(URI_2001_SCHEMA_XSD, "any"); + + public static final QName XSD_ANYSIMPLETYPE = new QName(URI_2001_SCHEMA_XSD, "anySimpleType"); + + public static final QName XSD_ANYTYPE = new QName(URI_2001_SCHEMA_XSD, "anyType"); + + public static final QName XSD_ANYURI = new QName(URI_2001_SCHEMA_XSD, "anyURI"); + + public static final QName XSD_BASE64 = new QName(URI_2001_SCHEMA_XSD, "base64Binary"); + + public static final QName XSD_BOOLEAN = new QName(URI_2001_SCHEMA_XSD, "boolean"); + + public static final QName XSD_BYTE = new QName(URI_2001_SCHEMA_XSD, "byte"); + + public static final QName XSD_DATE = new QName(URI_2001_SCHEMA_XSD, "date"); + + public static final QName XSD_DATETIME = new QName(URI_2001_SCHEMA_XSD, "dateTime"); + + public static final QName XSD_DAY = new QName(URI_2001_SCHEMA_XSD, "gDay"); + + public static final QName XSD_DECIMAL = new QName(URI_2001_SCHEMA_XSD, "decimal"); + + public static final QName XSD_DOUBLE = new QName(URI_2001_SCHEMA_XSD, "double"); + + public static final QName XSD_DURATION = new QName(URI_2001_SCHEMA_XSD, "duration"); + + public static final QName XSD_ENTITIES = new QName(URI_2001_SCHEMA_XSD, "ENTITIES"); + + public static final QName XSD_ENTITY = new QName(URI_2001_SCHEMA_XSD, "ENTITY"); + + public static final QName XSD_FLOAT = new QName(URI_2001_SCHEMA_XSD, "float"); + + public static final QName XSD_HEXBIN = new QName(URI_2001_SCHEMA_XSD, "hexBinary"); + + public static final QName XSD_IDREF = new QName(URI_2001_SCHEMA_XSD, "IDREF"); + + public static final QName XSD_IDREFS = new QName(URI_2001_SCHEMA_XSD, "IDREFS"); + + public static final QName XSD_INT = new QName(URI_2001_SCHEMA_XSD, "int"); + + public static final QName XSD_INTEGER = new QName(URI_2001_SCHEMA_XSD, "integer"); + + public static final QName XSD_LONG = new QName(URI_2001_SCHEMA_XSD, "long"); + + public static final QName XSD_MONTH = new QName(URI_2001_SCHEMA_XSD, "gMonth"); + + public static final QName XSD_MONTHDAY = new QName(URI_2001_SCHEMA_XSD, "gMonthDay"); + + public static final QName XSD_NAME = new QName(URI_2001_SCHEMA_XSD, "Name"); + + public static final QName XSD_NCNAME = new QName(URI_2001_SCHEMA_XSD, "NCName"); + + public static final QName XSD_NEGATIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "negativeInteger"); + + public static final QName XSD_NMTOKEN = new QName(URI_2001_SCHEMA_XSD, "NMTOKEN"); + + public static final QName XSD_NMTOKENS = new QName(URI_2001_SCHEMA_XSD, "NMTOKENS"); + + public static final QName XSD_NONNEGATIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "nonNegativeInteger"); + + public static final QName XSD_NONPOSITIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "nonPositiveInteger"); + + public static final QName XSD_NORMALIZEDSTRING = new QName(URI_2001_SCHEMA_XSD, "normalizedString"); + + public static final QName XSD_NOTATION = new QName(URI_2001_SCHEMA_XSD, "NOTATION"); + + public static final QName XSD_POSITIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "positiveInteger"); + + public static final QName XSD_QNAME = new QName(URI_2001_SCHEMA_XSD, "QName"); + + public static final QName XSD_SHORT = new QName(URI_2001_SCHEMA_XSD, "short"); + + public static final Map<String, TypeInfo> XSD_SIMPLE_TYPES = new HashMap<String, TypeInfo>(); + + public static final QName XSD_STRING = new QName(URI_2001_SCHEMA_XSD, "string"); + + public static final QName XSD_TIME = new QName(URI_2001_SCHEMA_XSD, "time"); + + public static final QName XSD_TOKEN = new QName(URI_2001_SCHEMA_XSD, "token"); + + public static final QName XSD_UNSIGNEDBYTE = new QName(URI_2001_SCHEMA_XSD, "unsignedByte"); + + public static final QName XSD_UNSIGNEDINT = new QName(URI_2001_SCHEMA_XSD, "unsignedInt"); + + public static final QName XSD_UNSIGNEDLONG = new QName(URI_2001_SCHEMA_XSD, "unsignedLong"); + + public static final QName XSD_UNSIGNEDSHORT = new QName(URI_2001_SCHEMA_XSD, "unsignedShort"); + + public static final QName XSD_YEAR = new QName(URI_2001_SCHEMA_XSD, "gYear"); + + public static final QName XSD_YEARMONTH = new QName(URI_2001_SCHEMA_XSD, "gYearMonth"); + + private static final String[] XSD_TYPE_NAMES = + {"string", "boolean", "double", "float", "int", "integer", "long", "short", "byte", "decimal", "base64Binary", + "hexBinary", "anySimpleType", "anyType", "any", "QName", "dateTime", "date", "time", "normalizedString", + "token", "unsignedLong", "unsignedInt", "unsignedShort", "unsignedByte", "positiveInteger", "negativeInteger", + "nonNegativeInteger", "nonPositiveInteger", "gYearMonth", "gMonthDay", "gYear", "gMonth", "gDay", "duration", + "Name", "NCName", "NMTOKEN", "NMTOKENS", "NOTATION", "ENTITY", "ENTITIES", "IDREF", "IDREFS", "anyURI", + "language", "ID"}; + + static { + for (String type : XSD_TYPE_NAMES) { + TypeInfo simpleType = new TypeInfo(new QName(URI_2001_SCHEMA_XSD, type), true, null); + XSD_SIMPLE_TYPES.put(type, simpleType); + } + } + + static { + JAVA2XML.put(boolean.class, "boolean"); + JAVA2XML.put(byte.class, "byte"); + JAVA2XML.put(short.class, "short"); + JAVA2XML.put(int.class, "int"); + JAVA2XML.put(long.class, "long"); + JAVA2XML.put(float.class, "float"); + JAVA2XML.put(double.class, "double"); + JAVA2XML.put(Boolean.class, "boolean"); + JAVA2XML.put(Byte.class, "byte"); + JAVA2XML.put(Short.class, "short"); + JAVA2XML.put(Integer.class, "int"); + JAVA2XML.put(Long.class, "long"); + JAVA2XML.put(Float.class, "float"); + JAVA2XML.put(Double.class, "double"); + JAVA2XML.put(java.lang.String.class, "string"); + JAVA2XML.put(java.math.BigInteger.class, "integer"); + JAVA2XML.put(java.math.BigDecimal.class, "decimal"); + JAVA2XML.put(java.util.Calendar.class, "dateTime"); + JAVA2XML.put(java.util.Date.class, "dateTime"); + JAVA2XML.put(javax.xml.namespace.QName.class, "QName"); + JAVA2XML.put(java.net.URI.class, "string"); + JAVA2XML.put(javax.xml.datatype.XMLGregorianCalendar.class, "anySimpleType"); + JAVA2XML.put(javax.xml.datatype.Duration.class, "duration"); + JAVA2XML.put(java.lang.Object.class, "anyType"); + JAVA2XML.put(java.awt.Image.class, "base64Binary"); + JAVA2XML.put(byte[].class, "base64Binary"); + // java2XSD.put(javax.activation.DataHandler.class, "base64Binary"); + JAVA2XML.put(javax.xml.transform.Source.class, "base64Binary"); + JAVA2XML.put(java.util.UUID.class, "string"); + } + + static { + XML2JAVA.put("string", java.lang.String.class); + XML2JAVA.put("integer", java.math.BigInteger.class); + XML2JAVA.put("int", int.class); + XML2JAVA.put("long", long.class); + XML2JAVA.put("short", short.class); + XML2JAVA.put("decimal", java.math.BigDecimal.class); + XML2JAVA.put("float", float.class); + XML2JAVA.put("double", double.class); + XML2JAVA.put("boolean", boolean.class); + XML2JAVA.put("byte", byte.class); + XML2JAVA.put("QName", javax.xml.namespace.QName.class); + XML2JAVA.put("dateTime", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("base64Binary", byte[].class); + XML2JAVA.put("hexBinary", byte[].class); + XML2JAVA.put("unsignedInt", long.class); + XML2JAVA.put("unsignedShort", int.class); + XML2JAVA.put("unsignedByte", short.class); + XML2JAVA.put("time", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("date", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gDay", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gMonth", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gYear", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gYearMonth", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gMonthDay", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("anySimpleType", java.lang.Object.class); // For elements + // XML2JAVA.put("anySimpleType", java.lang.String.class); // For + // attributes + XML2JAVA.put("duration", javax.xml.datatype.Duration.class); + XML2JAVA.put("NOTATION", javax.xml.namespace.QName.class); + } + + private int byteEncoding = BASE64_ENCODING; + private DatatypeFactory factory; + + public SimpleTypeMapperExtension() { + super(); + try { + this.factory = DatatypeFactory.newInstance(); + } catch (DatatypeConfigurationException e) { + throw new IllegalArgumentException(e); + } + } + + public Class getJavaType(TypeInfo xmlType) { + TypeInfo baseType = xmlType; + while (baseType.getBaseType() != null) { + baseType = baseType.getBaseType(); + } + return XML2JAVA.get(baseType.getQName().getLocalPart()); + } + + public TypeInfo getXMLType(Class javaType) { + return XSD_SIMPLE_TYPES.get(JAVA2XML.get(javaType)); + } + + public Object toJavaObject(TypeInfo simpleType, String literal, TransformationContext context) { + /** + * <ul> + * <li>xsd:string --- java.lang.String + * <li>xsd:integer --- java.math.BigInteger + * <li>xsd:int --- int + * <li>xsd:long --- long + * <li>xsd:short --- short + * <li>xsd:decimal --- java.math.BigDecimal + * <li>xsd:float --- float + * <li>xsd:double --- double + * <li>xsd:boolean --- boolean + * <li>xsd:byte --- byte + * <li>xsd:QName --- javax.xml.namespace.QName + * <li>xsd:dateTime --- javax.xml.datatype.XMLGregorianCalendar + * <li>xsd:base64Binary --- byte[] + * <li>xsd:hexBinary --- byte[] + * <li>xsd:unsignedInt --- long + * <li>xsd:unsignedShort --- int + * <li>xsd:unsignedByte --- short + * <li>xsd:time --- javax.xml.datatype.XMLGregorianCalendar + * <li>xsd:date --- javax.xml.datatype.XMLGregorianCalendar + * <li>xsd:g* --- javax.xml.datatype.XMLGregorianCalendar + * <li>xsd:anySimpleType (for xsd:element of this type)a + * java.lang.Object + * <li>xsd:anySimpleType (for xsd:attribute of this type) + * java.lang.String + * <li>xsd:duration javax.xml.datatype.Duration + * <li>xsd:NOTATION javax.xml.namespace.QName + * </ul> + */ + + if (literal == null) { + return null; + } + String value = literal.trim(); + if (!simpleType.isSimpleType()) { + throw new IllegalArgumentException("Complex type is not supported for simple java databinding."); + } + TypeInfo baseType = simpleType; + while (baseType.getBaseType() != null) { + baseType = (TypeInfo)baseType.getBaseType(); + } + + QName type = baseType.getQName(); + if (type.equals(XSD_STRING)) { + return parseString(value); + } else if (type.equals(XSD_INT)) { + return parseInt(value); + } else if (type.equals(XSD_INTEGER)) { + return parseInteger(value); + } else if (type.equals(XSD_INT)) { + return parseInt(value); + } else if (type.equals(XSD_FLOAT)) { + return parseFloat(value); + } else if (type.equals(XSD_DOUBLE)) { + return parseDouble(value); + } else if (type.equals(XSD_SHORT)) { + return parseShort(value); + } else if (type.equals(XSD_DECIMAL)) { + return parseDecimal(value); + } else if (type.equals(XSD_BOOLEAN)) { + return parseBoolean(value); + } else if (type.equals(XSD_BYTE)) { + return parseByte(value); + } else if (type.equals(XSD_LONG)) { + return parseLong(value); + } else if (type.equals(XSD_UNSIGNEDBYTE)) { + return parseUnsignedShort(value); + } else if (type.equals(XSD_UNSIGNEDSHORT)) { + return parseUnsignedShort(value); + } else if (type.equals(XSD_UNSIGNEDINT)) { + return parseUnsignedInt(value); + } else if (type.equals(XSD_UNSIGNEDLONG)) { + return parseUnsignedInt(value); + } else if (type.equals(XSD_DATETIME)) { + return parseDateTime(value); + } else if (type.equals(XSD_DATE)) { + return parseDate(value); + } else if (type.equals(XSD_TIME)) { + return parseTime(value); + } else if (type.equals(XSD_DURATION)) { + return parseDuration(value); + } else if (type.equals(XSD_HEXBIN)) { + return parseHexBinary(value); + } else if (type.equals(XSD_BASE64)) { + return parseBase64Binary(value); + } else if (type.equals(XSD_QNAME)) { + NamespaceContext namespaceContext = + (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class) : null); + return parseQName(value, namespaceContext); + } else if (type.equals(XSD_NOTATION)) { + NamespaceContext namespaceContext = + (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class) : null); + return parseQName(value, namespaceContext); + } else if (type.equals(XSD_YEAR)) { + return factory.newXMLGregorianCalendar(value); + } else if (type.equals(XSD_MONTH)) { + return factory.newXMLGregorianCalendar(value); + } else if (type.equals(XSD_DAY)) { + return factory.newXMLGregorianCalendar(value); + } else if (type.equals(XSD_YEARMONTH)) { + return factory.newXMLGregorianCalendar(value); + } else if (type.equals(XSD_MONTHDAY)) { + return factory.newXMLGregorianCalendar(value); + } else { + return value; + } + } + + @SuppressWarnings("deprecation") + private XMLGregorianCalendar toXMLGregorianCalendar(Date date) { + GregorianCalendar c = + new GregorianCalendar(date.getYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), + date.getSeconds()); + return factory.newXMLGregorianCalendar(c); + } + + private XMLGregorianCalendar toXMLGregorianCalendar(GregorianCalendar calendar) { + return factory.newXMLGregorianCalendar(calendar); + } + + public String toXMLLiteral(TypeInfo simpleType, Object obj, TransformationContext context) { + if (obj instanceof Float || obj instanceof Double) { + if (obj instanceof Float) { + return printDouble(((Float)obj).floatValue()); + } else { + return printDouble(((Double)obj).doubleValue()); + } + } else if (obj instanceof GregorianCalendar) { + GregorianCalendar calendar = (GregorianCalendar)obj; + return toXMLGregorianCalendar(calendar).toXMLFormat(); + } else if (obj instanceof Date) { + return toXMLGregorianCalendar((Date)obj).toXMLFormat(); + } else if (obj instanceof XMLGregorianCalendar) { + return ((XMLGregorianCalendar)obj).toXMLFormat(); + } else if (obj instanceof byte[]) { + if (simpleType != null) { + if (simpleType.getQName().equals(XSD_BASE64)) { + byteEncoding = BASE64_ENCODING; + } else if (simpleType.getQName().equals(XSD_HEXBIN)) { + byteEncoding = BASE64_ENCODING; + } + } + if (byteEncoding == BASE64_ENCODING) { + return printBase64Binary((byte[])obj); + } else if (byteEncoding == HEXBIN_ENCODING) { + return printHexBinary((byte[])obj); + } + } else if (obj instanceof QName) { + NamespaceContext namespaceContext = + (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class) : null); + return printQName((QName)obj, namespaceContext); + } + return obj.toString(); + } + + public static boolean isSimpleXSDType(QName typeName) { + return typeName.getNamespaceURI().equals(URI_2001_SCHEMA_XSD) + && XSD_SIMPLE_TYPES.get(typeName.getLocalPart()) != null; + } + + public int getByteEncoding() { + return byteEncoding; + } + + public void setByteEncoding(int byteEncoding) { + this.byteEncoding = byteEncoding; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/TransformerExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/TransformerExtension.java new file mode 100644 index 0000000000..374ac58e0d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/TransformerExtension.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.databinding.extension; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.TransformerRegistry; + +/** + * Base Implementation of Transformer which provides the registration to the transformer registry + * + * @version $Rev$ $Date$ + */ +@Service(Transformer.class) +@Scope("COMPOSITE") +@EagerInit +public abstract class TransformerExtension<S, T> implements Transformer { + + protected TransformerRegistry registry; + + protected TransformerExtension() { + super(); + } + + @Reference + public void setTransformerRegistry(TransformerRegistry registry) { + this.registry = registry; + } + + @Init + public void init() { + registry.registerTransformer(this); + } + + protected abstract Class getSourceType(); + + protected abstract Class getTargetType(); + + public String getSourceDataBinding() { + return getSourceType().getName(); + } + + public String getTargetDataBinding() { + return getTargetType().getName(); + } + + public int getWeight() { + // default to 50 + return 50; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverter.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverter.java new file mode 100644 index 0000000000..a0c75570bd --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverter.java @@ -0,0 +1,940 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.databinding.extension; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.text.FieldPosition; +import java.text.Format; +import java.text.ParsePosition; +import java.util.Calendar; +import java.util.TimeZone; +import javax.xml.XMLConstants; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.Duration; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; + +/** + * Utility class for XSD data type conversions + */ +public class XSDDataTypeConverter { + public static final class Base64Binary { + private static final char[] S_BASE64CHAR = + {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', + '5', '6', '7', '8', '9', '+', '/'}; + + private static final char S_BASE64PAD = '='; + + private static final byte[] S_DECODETABLE = new byte[128]; + + static { + for (int i = 0; i < S_DECODETABLE.length; i++) { + S_DECODETABLE[i] = Byte.MAX_VALUE; // 127 + } + for (int i = 0; i < S_BASE64CHAR.length; i++) { + // 0 to 63 + S_DECODETABLE[S_BASE64CHAR[i]] = (byte) i; + } + } + + private Base64Binary() { + } + + /** + * + */ + public static byte[] decode(char[] data, int off, int len) { + char[] ibuf = new char[4]; + int ibufcount = 0; + byte[] obuf = new byte[len / 4 * 3 + 3]; + int obufcount = 0; + for (int i = off; i < off + len; i++) { + char ch = data[i]; + if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { + ibuf[ibufcount++] = ch; + if (ibufcount == ibuf.length) { + ibufcount = 0; + obufcount += decode0(ibuf, obuf, obufcount); + } + } + } + if (obufcount == obuf.length) { + return obuf; + } + byte[] ret = new byte[obufcount]; + System.arraycopy(obuf, 0, ret, 0, obufcount); + return ret; + } + + /** + * + */ + public static void decode(char[] data, int off, int len, OutputStream ostream) throws IOException { + char[] ibuf = new char[4]; + int ibufcount = 0; + byte[] obuf = new byte[3]; + for (int i = off; i < off + len; i++) { + char ch = data[i]; + if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { + ibuf[ibufcount++] = ch; + if (ibufcount == ibuf.length) { + ibufcount = 0; + int obufcount = decode0(ibuf, obuf, 0); + ostream.write(obuf, 0, obufcount); + } + } + } + } + + /** + * + */ + public static byte[] decode(String data) { + char[] ibuf = new char[4]; + int ibufcount = 0; + byte[] obuf = new byte[data.length() / 4 * 3 + 3]; + int obufcount = 0; + for (int i = 0; i < data.length(); i++) { + char ch = data.charAt(i); + if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { + ibuf[ibufcount++] = ch; + if (ibufcount == ibuf.length) { + ibufcount = 0; + obufcount += decode0(ibuf, obuf, obufcount); + } + } + } + if (obufcount == obuf.length) { + return obuf; + } + byte[] ret = new byte[obufcount]; + System.arraycopy(obuf, 0, ret, 0, obufcount); + return ret; + } + + /** + * + */ + public static void decode(String data, OutputStream ostream) throws IOException { + char[] ibuf = new char[4]; + int ibufcount = 0; + byte[] obuf = new byte[3]; + for (int i = 0; i < data.length(); i++) { + char ch = data.charAt(i); + if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { + ibuf[ibufcount++] = ch; + if (ibufcount == ibuf.length) { + ibufcount = 0; + int obufcount = decode0(ibuf, obuf, 0); + ostream.write(obuf, 0, obufcount); + } + } + } + } + + private static int decode0(char[] ibuf, byte[] obuf, int index) { + int wp = index; + int outlen = 3; + if (ibuf[3] == S_BASE64PAD) { + outlen = 2; + } + if (ibuf[2] == S_BASE64PAD) { + outlen = 1; + } + int b0 = S_DECODETABLE[ibuf[0]]; + int b1 = S_DECODETABLE[ibuf[1]]; + int b2 = S_DECODETABLE[ibuf[2]]; + int b3 = S_DECODETABLE[ibuf[3]]; + switch (outlen) { + case 1: + obuf[wp] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3); + return 1; + case 2: + obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3); + obuf[wp] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf); + return 2; + case 3: + obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3); + obuf[wp++] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf); + obuf[wp] = (byte) (b2 << 6 & 0xc0 | b3 & 0x3f); + return 3; + default: + throw new IllegalArgumentException("The character sequence is not base64 encoded."); + } + } + + /** + * Returns base64 representation of specified byte array. + */ + public static String encode(byte[] data) { + return encode(data, 0, data.length); + } + + /** + * Returns base64 representation of specified byte array. + */ + public static String encode(byte[] data, int off, int len) { + if (len <= 0) { + return ""; + } + char[] out = new char[len / 3 * 4 + 4]; + int rindex = off; + int windex = 0; + int rest = len - off; + while (rest >= 3) { + int i = + ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8) + + (data[rindex + 2] & 0xff); + out[windex++] = S_BASE64CHAR[i >> 18]; + out[windex++] = S_BASE64CHAR[(i >> 12) & 0x3f]; + out[windex++] = S_BASE64CHAR[(i >> 6) & 0x3f]; + out[windex++] = S_BASE64CHAR[i & 0x3f]; + rindex += 3; + rest -= 3; + } + if (rest == 1) { + int i = data[rindex] & 0xff; + out[windex++] = S_BASE64CHAR[i >> 2]; + out[windex++] = S_BASE64CHAR[(i << 4) & 0x3f]; + out[windex++] = S_BASE64PAD; + out[windex++] = S_BASE64PAD; + } else if (rest == 2) { + int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff); + out[windex++] = S_BASE64CHAR[i >> 10]; + out[windex++] = S_BASE64CHAR[(i >> 4) & 0x3f]; + out[windex++] = S_BASE64CHAR[(i << 2) & 0x3f]; + out[windex++] = S_BASE64PAD; + } + return new String(out, 0, windex); + } + + /** + * Outputs base64 representation of the specified byte array to a byte stream. + */ + public static void encode(byte[] data, int off, int len, OutputStream ostream) throws IOException { + if (len <= 0) { + return; + } + byte[] out = new byte[4]; + int rindex = off; + int rest = len - off; + while (rest >= 3) { + int i = + ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8) + + (data[rindex + 2] & 0xff); + out[0] = (byte) S_BASE64CHAR[i >> 18]; + out[1] = (byte) S_BASE64CHAR[(i >> 12) & 0x3f]; + out[2] = (byte) S_BASE64CHAR[(i >> 6) & 0x3f]; + out[3] = (byte) S_BASE64CHAR[i & 0x3f]; + ostream.write(out, 0, 4); + rindex += 3; + rest -= 3; + } + if (rest == 1) { + int i = data[rindex] & 0xff; + out[0] = (byte) S_BASE64CHAR[i >> 2]; + out[1] = (byte) S_BASE64CHAR[(i << 4) & 0x3f]; + out[2] = (byte) S_BASE64PAD; + out[3] = (byte) S_BASE64PAD; + ostream.write(out, 0, 4); + } else if (rest == 2) { + int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff); + out[0] = (byte) S_BASE64CHAR[i >> 10]; + out[1] = (byte) S_BASE64CHAR[(i >> 4) & 0x3f]; + out[2] = (byte) S_BASE64CHAR[(i << 2) & 0x3f]; + out[3] = (byte) S_BASE64PAD; + ostream.write(out, 0, 4); + } + } + + /** + * Outputs base64 representation of the specified byte array to a character stream. + */ + public static void encode(byte[] data, int off, int len, Writer writer) throws IOException { + if (len <= 0) { + return; + } + char[] out = new char[4]; + int rindex = off; + int rest = len - off; + int output = 0; + while (rest >= 3) { + int i = + ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8) + + (data[rindex + 2] & 0xff); + out[0] = S_BASE64CHAR[i >> 18]; + out[1] = S_BASE64CHAR[(i >> 12) & 0x3f]; + out[2] = S_BASE64CHAR[(i >> 6) & 0x3f]; + out[3] = S_BASE64CHAR[i & 0x3f]; + writer.write(out, 0, 4); + rindex += 3; + rest -= 3; + output += 4; + if (output % 76 == 0) { + writer.write("\n"); + } + } + if (rest == 1) { + int i = data[rindex] & 0xff; + out[0] = S_BASE64CHAR[i >> 2]; + out[1] = S_BASE64CHAR[(i << 4) & 0x3f]; + out[2] = S_BASE64PAD; + out[3] = S_BASE64PAD; + writer.write(out, 0, 4); + } else if (rest == 2) { + int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff); + out[0] = S_BASE64CHAR[i >> 10]; + out[1] = S_BASE64CHAR[(i >> 4) & 0x3f]; + out[2] = S_BASE64CHAR[(i << 2) & 0x3f]; + out[3] = S_BASE64PAD; + writer.write(out, 0, 4); + } + } + } + + /** + * <p/> + * Utility class for xs:hexbinary. </p> + */ + public static final class HexBinary { + private HexBinary() { + } + + /** + * Converts the string <code>pValue</code> into an array of hex bytes. + */ + public static byte[] decode(String pValue) { + if ((pValue.length() % 2) != 0) { + throw new IllegalArgumentException("A HexBinary string must have even length."); + } + byte[] result = new byte[pValue.length() / 2]; + int j = 0; + int i = 0; + while (i < pValue.length()) { + byte b; + char c = pValue.charAt(i++); + char d = pValue.charAt(i++); + if (c >= '0' && c <= '9') { + b = (byte) ((c - '0') << 4); + } else if (c >= 'A' && c <= 'F') { + b = (byte) ((c - 'A' + 10) << 4); + } else if (c >= 'a' && c <= 'f') { + b = (byte) ((c - 'a' + 10) << 4); + } else { + throw new IllegalArgumentException("Invalid hex digit: " + c); + } + if (d >= '0' && d <= '9') { + b += (byte) (d - '0'); + } else if (d >= 'A' && d <= 'F') { + b += (byte) (d - 'A' + 10); + } else if (d >= 'a' && d <= 'f') { + b += (byte) (d - 'a' + 10); + } else { + throw new IllegalArgumentException("Invalid hex digit: " + d); + } + result[j++] = b; + } + return result; + } + + /** + * Converts the byte array <code>pHexBinary</code> into a string. + */ + public static String encode(byte[] pHexBinary) { + StringBuffer result = new StringBuffer(); + for (int i = 0; i < pHexBinary.length; i++) { + byte b = pHexBinary[i]; + byte c = (byte) ((b & 0xf0) >> 4); + if (c <= 9) { + result.append((char) ('0' + c)); + } else { + result.append((char) ('A' + c - 10)); + } + c = (byte) (b & 0x0f); + if (c <= 9) { + result.append((char) ('0' + c)); + } else { + result.append((char) ('A' + c - 10)); + } + } + return result.toString(); + } + + /** + * Creates a clone of the given byte array. + */ + public static byte[] getClone(byte[] pHexBinary) { + byte[] result = new byte[pHexBinary.length]; + System.arraycopy(pHexBinary, 0, result, 0, pHexBinary.length); + return result; + } + } + + public class XSDDateFormat extends XSDDateTimeFormat { + private static final long serialVersionUID = -1629412916827246627L; + + /** + * Creates a new instance. + */ + public XSDDateFormat() { + super(true, false); + } + } + + /** + * <p/> + * An instance of {@link java.text.Format}, which may be used to parse and format <code>xs:dateTime</code> values. + * </p> + */ + public static class XSDDateTimeFormat extends Format { + private static final long serialVersionUID = -1148332471737068969L; + + final boolean parseDate; + + final boolean parseTime; + + /** + * Creates a new instance. + */ + public XSDDateTimeFormat() { + this(true, true); + } + + XSDDateTimeFormat(boolean pParseDate, boolean pParseTime) { + parseDate = pParseDate; + parseTime = pParseTime; + } + + private void append(StringBuffer pBuffer, int pNum, int pMinLen) { + String s = Integer.toString(pNum); + for (int i = s.length(); i < pMinLen; i++) { + pBuffer.append('0'); + } + pBuffer.append(s); + } + + public StringBuffer format(Object pCalendar, StringBuffer pBuffer, FieldPosition pPos) { + assert pCalendar != null : "The Calendar argument must not be null."; + assert pBuffer != null : "The StringBuffer argument must not be null."; + assert pPos != null : "The FieldPosition argument must not be null."; + + Calendar cal = (Calendar) pCalendar; + if (parseDate) { + int year = cal.get(Calendar.YEAR); + if (year < 0) { + pBuffer.append('-'); + year = -year; + } + append(pBuffer, year, 4); + pBuffer.append('-'); + append(pBuffer, cal.get(Calendar.MONTH) + 1, 2); + pBuffer.append('-'); + append(pBuffer, cal.get(Calendar.DAY_OF_MONTH), 2); + if (parseTime) { + pBuffer.append('T'); + } + } + if (parseTime) { + append(pBuffer, cal.get(Calendar.HOUR_OF_DAY), 2); + pBuffer.append(':'); + append(pBuffer, cal.get(Calendar.MINUTE), 2); + pBuffer.append(':'); + append(pBuffer, cal.get(Calendar.SECOND), 2); + int millis = cal.get(Calendar.MILLISECOND); + if (millis > 0) { + pBuffer.append('.'); + append(pBuffer, millis, 3); + } + } + TimeZone tz = cal.getTimeZone(); + // JDK 1.4: int offset = tz.getOffset(cal.getTimeInMillis()); + int offset = cal.get(Calendar.ZONE_OFFSET); + if (tz.inDaylightTime(cal.getTime())) { + offset += cal.get(Calendar.DST_OFFSET); + } + if (offset == 0) { + pBuffer.append('Z'); + } else { + if (offset < 0) { + pBuffer.append('-'); + offset = -offset; + } else { + pBuffer.append('+'); + } + int minutes = offset / (60 * 1000); + int hours = minutes / 60; + minutes -= hours * 60; + append(pBuffer, hours, 2); + pBuffer.append(':'); + append(pBuffer, minutes, 2); + } + return pBuffer; + } + + private int parseInt(String pString, int offset, StringBuffer pDigits) { + int length = pString.length(); + int pOffset = offset; + pDigits.setLength(0); + while (pOffset < length) { + char c = pString.charAt(pOffset); + if (Character.isDigit(c)) { + pDigits.append(c); + ++pOffset; + } else { + break; + } + } + return pOffset; + } + + public Object parseObject(String pString, ParsePosition pParsePosition) { + assert pString != null : "The String argument must not be null."; + assert pParsePosition != null : "The ParsePosition argument must not be null."; + int offset = pParsePosition.getIndex(); + int length = pString.length(); + + boolean isMinus = false; + StringBuffer digits = new StringBuffer(); + int year = 0; + int month = 0; + int mday = 0; + if (parseDate) { + // Sign + if (offset < length) { + char c = pString.charAt(offset); + if (c == '+') { + ++offset; + } else if (c == '-') { + ++offset; + isMinus = true; + } + } + + offset = parseInt(pString, offset, digits); + if (digits.length() < 4) { + pParsePosition.setErrorIndex(offset); + return null; + } + year = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == '-') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + month = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == '-') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + mday = Integer.parseInt(digits.toString()); + + if (parseTime) { + if (offset < length && pString.charAt(offset) == 'T') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + } + } else { + year = month = mday = 0; + } + + int hour = 0; + int minute = 0; + int second = 0; + int millis = 0; + if (parseTime) { + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + hour = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == ':') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + minute = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == ':') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + second = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == '.') { + ++offset; + offset = parseInt(pString, offset, digits); + if (digits.length() > 0) { + millis = Integer.parseInt(digits.toString()); + } else { + millis = 0; + } + } else { + millis = 0; + } + } else { + hour = minute = second = millis = 0; + } + + digits.setLength(0); + digits.append("GMT"); + if (offset < length) { + char c = pString.charAt(offset); + if (c == 'Z') { + // Ignore UTC, it is the default + ++offset; + } else if (c == '+' || c == '-') { + digits.append(c); + ++offset; + for (int i = 0; i < 5; i++) { + if (offset >= length) { + pParsePosition.setErrorIndex(offset); + return null; + } + c = pString.charAt(offset); + if ((i != 2 && Character.isDigit(c)) || (i == 2 && c == ':')) { + digits.append(c); + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + ++offset; + } + } + } + + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(digits.toString())); + cal.set(isMinus ? -year : year, parseDate ? month - 1 : month, mday, hour, minute, second); + cal.set(Calendar.MILLISECOND, millis); + pParsePosition.setIndex(offset); + return cal; + } + } + + public static class XSDTimeFormat extends XSDDateTimeFormat { + private static final long serialVersionUID = 1346506860724640517L; + + /** + * Creates a new instance. + */ + public XSDTimeFormat() { + super(false, true); + } + } + + private static final long MAX_UNSIGNED_INT = (((long) Integer.MAX_VALUE) * 2) + 1; + + private static final int MAX_UNSIGNED_SHORT = Short.MAX_VALUE * 2 + 1; + + public String parseAnySimpleType(String value) { + return value; + } + + public byte[] parseBase64Binary(String value) { + return Base64Binary.decode(value); + } + + public boolean parseBoolean(String value) { + return Boolean.valueOf(value).booleanValue(); + } + + public byte parseByte(String value) { + return Byte.parseByte(value); + } + + public Calendar parseDate(String value) { + XSDDateFormat format = new XSDDateFormat(); + ParsePosition pos = new ParsePosition(0); + Calendar cal = (Calendar) format.parseObject(value, pos); + if (cal == null) { + throw new IllegalArgumentException("Failed to parse date " + value + " at:" + + value.substring(pos.getErrorIndex())); + } + return cal; + } + + public Calendar parseDateTime(String value) { + XSDDateTimeFormat format = new XSDDateTimeFormat(); + ParsePosition pos = new ParsePosition(0); + Calendar cal = (Calendar) format.parseObject(value, pos); + if (cal == null) { + throw new IllegalArgumentException("Failed to parse dateTime " + value + " at:" + + value.substring(pos.getErrorIndex())); + } + return cal; + } + + public BigDecimal parseDecimal(String value) { + return new BigDecimal(value); + } + + public double parseDouble(String value) { + if ("INF".equals(value)) { + return Double.POSITIVE_INFINITY; + } else if ("-INF".equals(value)) { + return Double.NEGATIVE_INFINITY; + } else if ("NaN".equals(value)) { + return Double.NaN; + } else { + return Double.parseDouble(value); + } + } + + public Duration parseDuration(String pDuration) { + try { + return DatatypeFactory.newInstance().newDuration(pDuration); + } catch (DatatypeConfigurationException e) { + throw new IllegalArgumentException(e); + } + } + + public float parseFloat(String value) { + if ("INF".equals(value)) { + return Float.POSITIVE_INFINITY; + } else if ("-INF".equals(value)) { + return Float.NEGATIVE_INFINITY; + } else if ("NaN".equals(value)) { + return Float.NaN; + } else { + return Float.parseFloat(value); + } + } + + public byte[] parseHexBinary(String value) { + return HexBinary.decode(value); + } + + public int parseInt(String value) { + return Integer.parseInt(value); + } + + public BigInteger parseInteger(String value) { + return new BigInteger(value); + } + + public long parseLong(String value) { + return Long.parseLong(value); + } + + public QName parseQName(String value, NamespaceContext context) { + int offset = value.indexOf(':'); + String uri; + String localName; + switch (offset) { + case -1: + localName = value; + uri = context.getNamespaceURI(""); + if (uri == null) { + // Should not happen, indicates an error in the + // NamespaceContext + // implementation + throw new IllegalArgumentException("The default prefix is not bound."); + } + break; + case 0: + throw new IllegalArgumentException("Default prefix must be indicated by not using a colon: " + + value); + default: + String prefix = value.substring(0, offset); + localName = value.substring(offset + 1); + uri = context.getNamespaceURI(prefix); + if (uri == null) { + throw new IllegalArgumentException("The prefix " + prefix + " is not bound."); + } + } + return new QName(uri, localName); + } + + public short parseShort(String value) { + return Short.parseShort(value); + } + + public String parseString(String value) { + return value; + } + + public Calendar parseTime(String value) { + XSDTimeFormat format = new XSDTimeFormat(); + ParsePosition pos = new ParsePosition(0); + Calendar cal = (Calendar) format.parseObject(value, pos); + if (cal == null) { + throw new IllegalArgumentException("Failed to parse time " + value + " at:" + + value.substring(pos.getErrorIndex())); + } + return cal; + } + + public long parseUnsignedInt(String value) { + long l = Long.parseLong(value); + if (l < 0) { + throw new IllegalArgumentException("Failed to parse UnsignedInt " + value + + ": result is negative"); + } + if (l > MAX_UNSIGNED_INT) { + throw new IllegalArgumentException("Failed to parse UnsignedInt " + value + + ": result exceeds maximum value " + MAX_UNSIGNED_INT); + } + return l; + } + + public int parseUnsignedShort(String value) { + int i = Integer.parseInt(value); + if (i < 0) { + throw new IllegalArgumentException("Failed to parse UnsignedShort " + value + + ": result is negative"); + } + if (i > MAX_UNSIGNED_SHORT) { + throw new IllegalArgumentException("Failed to parse UnsignedShort " + value + + ": result exceeds maximum value " + MAX_UNSIGNED_SHORT); + } + return i; + } + + public String printAnySimpleType(String value) { + return value; + } + + public String printBase64Binary(byte[] value) { + return Base64Binary.encode(value); + } + + public String printBoolean(boolean value) { + return (value ? Boolean.TRUE : Boolean.FALSE).toString(); + } + + public String printByte(byte value) { + return Byte.toString(value); + } + + public String printDate(Calendar value) { + return new XSDDateFormat().format(value); + } + + public String printDateTime(Calendar value) { + return new XSDDateTimeFormat().format(value); + } + + public String printDecimal(BigDecimal value) { + return value.toString(); + } + + public String printDouble(double value) { + return Double.toString(value); + } + + public String printDuration(Duration pDuration) { + return pDuration.toString(); + } + + public String printFloat(float value) { + return Float.toString(value); + } + + public String printHexBinary(byte[] value) { + return HexBinary.encode(value); + } + + public String printInt(int value) { + return Integer.toString(value); + } + + public String printInteger(BigInteger value) { + return value.toString(); + } + + public String printLong(long value) { + return Long.toString(value); + } + + public String printQName(QName value, NamespaceContext context) { + String prefix = context.getPrefix(value.getNamespaceURI()); + if (prefix == null) { + throw new IllegalArgumentException("The namespace URI " + value.getNamespaceURI() + + " is not bound."); + } else if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { + return value.getLocalPart(); + } else { + return prefix + ":" + value.getLocalPart(); + } + } + + public String printShort(short value) { + return Short.toString(value); + } + + public String printString(String value) { + return value; + } + + public String printTime(Calendar value) { + return new XSDTimeFormat().format(value); + } + + public String printUnsignedInt(long value) { + return Long.toString(value); + } + + public String printUnsignedShort(int value) { + return Integer.toString(value); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolver.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolver.java new file mode 100644 index 0000000000..bd4c29e48b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolver.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.deployer; + +import java.net.URL; +import java.util.Map; + +import org.apache.tuscany.spi.model.Contribution; + + +/** + * SCA Assemblies reference many artifacts of a wide variety of types. These + * include: + * <ul> + * <li> Reference from one SCA composite to another SCA composite + * <li> Reference to PolicySet files + * <li> Reference to interface definition files, either WSDL or Java interfaces + * <li> Reference to XSD files + * <li> Reference to any of a wide variety of implementation artifact files, + * including Java classes, BPEL scripts, C++ DLLs and classes, PHP scripts + * </ul> + * In the SCA assemblies, these various artifacts are referenced using either + * QNames or URIs that do not point to a specific entity. Resolution of these + * references to concrete artifacts is necessary as part of the operation of the + * SCA domain. + * + * @version $Rev$ $Date$ + */ +public interface ArtifactResolver { + /** + * Resolve an artifact by the qualified name + * + * @param contribution the model of the contribution + * @param modelClass The java type of the artifact + * @param namespace The namespace of the artifact + * @param name The name of the artifact + * @param attributes Additional attributes that can be used to constrain the + * resolution + * @param context The deployment context + * @return The resolved artifact + */ + <T> T resolve(Contribution contribution, + Class<T> modelClass, + String namespace, + String name, + Map attributes, + DeploymentContext context); + + /** + * Resolve an artifact by the URI. Some typical use cases are: + * <ul> + * <li>Reference a XML schema using + * {http://www.w3.org/2001/XMLSchema-instance}schemaLocation or + * <li>Reference a list of WSDLs using + * {http://www.w3.org/2004/08/wsdl-instance}wsdlLocation + * </ul> + * @param targetNamespace The target namespace of the referenced artifact, + * if the targetNamespace is null, then it's not specified + * @param location The URI of the referenced artifact, it can be absolute or + * relative + * @param baseURI The URI of the owning artifact + * + * @return The URI of the resolved artifact + */ + URL resolve(Contribution contribution, String targetNamespace, String location, String baseURI); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolverRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolverRegistry.java new file mode 100644 index 0000000000..f24fb7269a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolverRegistry.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.deployer; + + +/** + * Registry for artifact resolvers + * + * @version $Rev$ $Date$ + */ +public interface ArtifactResolverRegistry extends ArtifactResolver { + /** + * Register a resolver by the type of artifacts. For example, you can + * register a resolver to resolve WSDL model objects and other resolver + * for java classes + * + * @param modelClass The java type of the model object + * @param resolver The resolver + */ + void registerResolver(Class<?> modelClass, ArtifactResolver resolver); + + /** + * Unregister all resolvers for the given model class + * + * @param modelClass + */ + void unregisterResolver(Class<?> modelClass); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandler.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandler.java new file mode 100644 index 0000000000..fead0453be --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandler.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 org.apache.tuscany.spi.deployer; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.tuscany.host.deployment.DeploymentException; + +/** + * Interface implemented by services that process assembly change sets. + * + * @version $Rev$ $Date$ + */ +public interface ChangeSetHandler { + /** + * Returns the content type that this implementation can handle. + * + * @return the content type that this implementation can handle + */ + String getContentType(); + + /** + * Apply the changes in the supplied changeSet stream to an Assembly. + * The content on the stream must match the content type this implementation can handle. + * + * @param changeSet the set of changes to apply represented as the supported content type + * @throws DeploymentException if there was a problem applying the changes + * @throws IOException if there was a problem reading the stream + */ + void applyChanges(InputStream changeSet) throws DeploymentException, IOException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandlerRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandlerRegistry.java new file mode 100644 index 0000000000..df0bf4109b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandlerRegistry.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.deployer; + +/** + * Registry for ChangeSetHandler implementations. + * + * @version $Rev$ $Date$ + */ +public interface ChangeSetHandlerRegistry { + void register(ChangeSetHandler handler); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/CompositeClassLoader.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/CompositeClassLoader.java new file mode 100644 index 0000000000..732c70d40e --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/CompositeClassLoader.java @@ -0,0 +1,181 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.deployer; + +import java.io.IOException; +import java.net.URI; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collections; +import java.util.Enumeration; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * ClassLoader associated with a composite. + * Each classloader has a name that can be used to reference it in the runtime. + * The classloader supports multiple parents allowing application code to share selected + * libraries with the runtime infrastructure as determined by the component's implementation type. + * + * @version $Rev$ $Date$ + */ +public class CompositeClassLoader extends URLClassLoader { + private static final URL[] NOURLS = {}; + + private final URI name; + private final List<ClassLoader> parents = new CopyOnWriteArrayList<ClassLoader>(); + + /** + * Constructs a classloader with a name and a single parent. + * + * @param name a name used to identify this classloader + * @param parent the initial parent + */ + public CompositeClassLoader(URI name, ClassLoader parent) { + this(name, NOURLS, parent); + } + + /** + * Constructs a classloader with a name, a set of resources and a single parent. + * + * @param name a name used to identify this classloader + * @param urls the URLs from which to load classes and resources + * @param parent the initial parent + */ + public CompositeClassLoader(URI name, URL[] urls, ClassLoader parent) { + super(urls); + this.name = name; + if (parent != null) { + parents.add(parent); + } + } + + + /** + * Add a resource URL to this classloader's classpath. + * The "createClassLoader" RuntimePermission is required. + * + * @param url an additional URL from which to load classes and resources + */ + public void addURL(URL url) { + // Require RuntimePermission("createClassLoader") + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkCreateClassLoader(); + } + super.addURL(url); + } + + /** + * Add a parent to this classloader. + * The "createClassLoader" RuntimePermission is required. + * + * @param parent an additional parent classloader + */ + public void addParent(ClassLoader parent) { + // Require RuntimePermission("createClassLoader") + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkCreateClassLoader(); + } + if (parent != null) { + parents.add(parent); + } + } + + /** + * Returns the name of this classloader. + * + * @return the name of this classloader + */ + public URI getName() { + return name; + } + + protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { + // look for already loaded classes + Class clazz = findLoadedClass(name); + if (clazz != null) { + if (resolve) { + resolveClass(clazz); + } + return clazz; + } + + // look in our parents + for (ClassLoader parent : parents) { + try { + clazz = parent.loadClass(name); + if (resolve) { + resolveClass(clazz); + } + return clazz; + } catch (ClassNotFoundException e) { + continue; + } + } + + // look in our classpath + clazz = findClass(name); + if (resolve) { + resolveClass(clazz); + } + return clazz; + } + + + protected Class<?> findClass(String string) throws ClassNotFoundException { + return super.findClass(string); + } + + public URL findResource(String name) { + // look in our parents + for (ClassLoader parent : parents) { + URL resource = parent.getResource(name); + if (resource != null) { + return resource; + } + } + // look in our classpath + return super.findResource(name); + } + + public Enumeration<URL> findResources(String name) throws IOException { + // LinkedHashSet because we want all resources in the order found but no duplicates + Set<URL> resources = new LinkedHashSet<URL>(); + for (ClassLoader parent : parents) { + Enumeration<URL> parentResources = parent.getResources(name); + while (parentResources.hasMoreElements()) { + resources.add(parentResources.nextElement()); + } + } + Enumeration<URL> myResources = super.findResources(name); + while (myResources.hasMoreElements()) { + resources.add(myResources.nextElement()); + } + return Collections.enumeration(resources); + } + + + public String toString() { + return name.toString(); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java new file mode 100644 index 0000000000..d29f935dc4 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.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 org.apache.tuscany.spi.deployer;
+
+public interface ContentType {
+ /**
+ * Archive specific content types
+ */
+ public static final String JAR = "application/x-compressed";
+ public static final String FOLDER = "application/vnd.tuscany.folder";
+
+ /**
+ * Artifact/File specific content types
+ */
+ public static final String CONTRIBUTION_METADATA = "application/vnd.tuscany.contribution.metadata";
+ public static final String COMPOSITE = "application/vnd.tuscany.composite";
+ public static final String WSDL = "application/vnd.tuscany.wsdl";
+ public static final String JAVA = "application/java-vm";
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentTypeDescriber.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentTypeDescriber.java new file mode 100644 index 0000000000..e723080781 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentTypeDescriber.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.deployer; + +import java.net.URL; + +/** + * Provide content type for a given resource + * + * @version $Rev$ $Date$ + */ +public interface ContentTypeDescriber { + /** + * @param resourceURL the resource url + * @param defaultContentType the default content type + * @return the content type + */ + String getContentType(URL resourceURL, String defaultContentType); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java new file mode 100644 index 0000000000..a3d57870a7 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.deployer; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; + +import org.apache.tuscany.host.deployment.DeploymentException; +import org.apache.tuscany.spi.model.Contribution; + +/** + * Interface for services that can process contributions. + * + * @version $Rev$ $Date$ + */ +public interface ContributionProcessor { + /** + * Process a contribution or an artifact in the contribution from the input + * stream. The processor might add artifacts or model objects to the + * contribution object. + * + * @param contribution The contribution model that will be used to hold the + * results from the processing + * @param source The URI for the contribution/artifact + * @param inputStream The input stream for the contribution. The stream will + * not be closed but the read position after the call is + * undefined + * @throws DeploymentException if there was a problem with the contribution + * @throws IOException if there was a problem reading the stream + */ + void processContent(Contribution contribution, URI source, InputStream inputStream) throws DeploymentException, + IOException; + + /** + * Process a contribution from another model object. It will be used for the + * case that one artifact has other inline artifacts, for example, the WSDL + * with inline schemas. The schema contribution processor should be able to + * load the schema model from the WSDL definition. + * + * @param contribution The contribution model that will be used to hold the + * results from the processing + * @param source The URI for the contribution/artifact. + * @param modelObject A model object for further processing by the processor + * @throws DeploymentException + * @throws IOException + */ + void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException, + IOException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java new file mode 100644 index 0000000000..c1b6e93cb3 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.deployer; + +/** + * @version $Rev$ $Date$ + */ +public interface ContributionProcessorRegistry extends ContributionProcessor { + /** + * Register a ContributionProcessor using the content type as the key + * @param processor + */ + void register(String contentType, ContributionProcessor processor); + + /** + * Unregister a ContributionProcessor by content type + * @param contentType + */ + void unregister(String contentType); +}
\ No newline at end of file diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java new file mode 100644 index 0000000000..77a46237a0 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java @@ -0,0 +1,77 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.spi.deployer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+public interface ContributionRepository {
+ /**
+ * Get the URI of the SCA domain
+ *
+ * @return
+ */
+ URI getDomain();
+
+ /**
+ * Copies a contribution to the repository.
+ *
+ * @param contribution A URl pointing to the contribution being copied to
+ * the repository
+ * @param contributionStream InputStream with the content of the
+ * distribution
+ */
+ URL store(URI contribution, InputStream contributionStream) throws IOException;
+ /**
+ * Copy a contribution from the source URL to the repository
+ * @param contribution
+ * @param sourceURL
+ * @return
+ * @throws IOException
+ */
+ URL store(URI contribution, URL sourceURL) throws IOException;
+
+ /**
+ * Look up the contribution by URI
+ *
+ * @param contribution The URI of the contribution
+ * @return A URL pointing to the content of the contribution in the
+ * repository, it will be null if the contribution cannot be found
+ * in the repository
+ */
+ URL find(URI contribution);
+
+ /**
+ * Remove a contribution from the repository
+ *
+ * @param contribution The URI of the contribution to be removed
+ */
+ void remove(URI contribution);
+
+ /**
+ * Get list of URIs for all the contributions in the repository
+ *
+ * @return A list of contribution URIs
+ */
+ List<URI> list();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/Deployer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/Deployer.java new file mode 100644 index 0000000000..0b655fc5aa --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/Deployer.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 org.apache.tuscany.spi.deployer; + +import java.util.Collection; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.ComponentException; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.resolver.ResolutionException; + +/** + * Interface that can be used to deploy SCA bundles to a runtime. + * + * @version $Rev$ $Date$ + */ +public interface Deployer { + /** + * Deploy a component as a child of the supplied parent. This operation creates a new component in the runtime to + * represent the supplied component definition. The type of component created will depend on the component + * definition implementation; for example, if the implementation of the component definition is a composite then + * typically a CompositeComponent would be returned. + * + * @param parent the parent context + * @param componentDefinition the component definition as parsed from an assembly + * @return the newly deployed component + */ + <I extends Implementation<?>> Collection<Component> deploy(Component parent, + ComponentDefinition<I> componentDefinition) + throws LoaderException, BuilderException, ComponentException, ResolutionException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentContext.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentContext.java new file mode 100644 index 0000000000..5ed5992b8c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentContext.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.deployer; + +import java.net.URI; +import java.net.URL; +import java.util.Map; +import javax.xml.stream.XMLInputFactory; + +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.ScopeContainer; + +/** + * A holder that can be used during the load process to store information that is not part of the logical assembly + * model. This should be regarded as transient and references to this context should not be stored inside the model. + * + * @version $Rev$ $Date$ + */ +public interface DeploymentContext { + /** + * Returns the parent of this deployment context. Will be null for the context created at the root of a deployment. + * + * @return the parent of this deployment context; may be null + */ + DeploymentContext getParent(); + + /** + * Returns a class loader that can be used to load application resources. + * + * @return a class loader that can be used to load application resources + */ + ClassLoader getClassLoader(); + + /** + * Returns a factory that can be used to obtain an StAX XMLStreamReader. + * + * @return a factory that can be used to obtain an StAX XMLStreamReader + */ + XMLInputFactory getXmlFactory(); + + /** + * Returns the ScopeContainer for the COMPOSITE scope that will be associated with this deployment unit. + * + * @return the ScopeContainer for the COMPOSITE scope that will be associated with this deployment unit + */ + @Deprecated + ScopeContainer getCompositeScope(); + + /** + * Returns the URI of the composite scope group. + * @return the URI of the composite scope group + */ + URI getGroupId(); + + /** + * Returns the location of the SCDL definition being deployed. + * + * @return the location of the SCDL definition being deployed + */ + URL getScdlLocation(); + + /** + * Returns the URI of the composite component currently being deployed. + * + * @return the URI of the composite component currently being deployed + */ + URI getComponentId(); + + /** + * Returns true if the autowire is enabled for the current deployment. + * + * @return true if the autowire is enabled for the current deployment + */ + boolean isAutowire(); + + /** + * Sets if the autowire is enabled for the current deployment. + * + * @param autowire true if autowire is enabled + */ + void setAutowire(boolean autowire); + + @Deprecated + Map<URI, Component> getComponents(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentMonitor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentMonitor.java new file mode 100644 index 0000000000..12ce6e73e6 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentMonitor.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.deployer; + +import org.apache.tuscany.api.TuscanyException; +import org.apache.tuscany.api.annotation.LogLevel; + +/** + * @version $Rev$ $Date$ + */ +public interface DeploymentMonitor { + + @LogLevel("FINER") + void startDeployment(); + + @LogLevel("FINER") + void endDeployment(); + + @LogLevel("SEVERE") + void deploymentError(TuscanyException e); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/AbstractEventPublisher.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/AbstractEventPublisher.java new file mode 100644 index 0000000000..cc20866cbb --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/AbstractEventPublisher.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.event; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * Base implementation of an <code>EventPublisher</code> + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractEventPublisher implements EventPublisher { + protected static final EventFilter TRUE_FILTER = new TrueFilter(); + protected Map<EventFilter, List<RuntimeEventListener>> listeners; + + public void addListener(RuntimeEventListener listener) { + addListener(TRUE_FILTER, listener); + } + + public void removeListener(RuntimeEventListener listener) { + assert listener != null : "Listener cannot be null"; + synchronized (getListeners()) { + for (List<RuntimeEventListener> currentList : getListeners().values()) { + for (RuntimeEventListener current : currentList) { + if (current == listener) { + currentList.remove(current); + return; + } + } + } + } + } + + public void addListener(EventFilter filter, RuntimeEventListener listener) { + assert listener != null : "Listener cannot be null"; + synchronized (getListeners()) { + List<RuntimeEventListener> list = getListeners().get(filter); + if (list == null) { + list = new CopyOnWriteArrayList<RuntimeEventListener>(); + listeners.put(filter, list); + } + list.add(listener); + } + } + + public void publish(Event event) { + assert event != null : "Event object was null"; + for (Map.Entry<EventFilter, List<RuntimeEventListener>> entry : getListeners().entrySet()) { + if (entry.getKey().match(event)) { + for (RuntimeEventListener listener : entry.getValue()) { + listener.onEvent(event); + } + } + } + } + + protected Map<EventFilter, List<RuntimeEventListener>> getListeners() { + if (listeners == null) { + listeners = new ConcurrentHashMap<EventFilter, List<RuntimeEventListener>>(); + } + return listeners; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/Event.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/Event.java new file mode 100644 index 0000000000..b874ca43c9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/Event.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.event; + +/** + * Represents an event that is propagated in the runtime + * + * @version $$Rev$$ $$Date$$ + */ +public interface Event { + + /** + * Returns the source of the event + */ + Object getSource(); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventFilter.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventFilter.java new file mode 100644 index 0000000000..d61d04cdc8 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventFilter.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.event; + +/** + * Evaluates whether a {@link RuntimeEventListener} is applicable to a given runtime event + * + * @version $$Rev$$ $$Date$$ + */ +public interface EventFilter { + + /** + * Performs the actual evaluation on an event + */ + boolean match(Event event); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventPublisher.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventPublisher.java new file mode 100644 index 0000000000..35df22fb9c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventPublisher.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 org.apache.tuscany.spi.event; + +/** + * Publishes events in the runtime + * + * @version $$Rev$$ $$Date$$ + */ +public interface EventPublisher { + + /** + * Publish an event + */ + void publish(Event object); + + /** + * Registers a listener to receive notifications for the context + */ + void addListener(RuntimeEventListener listener); + + /** + * Registers a listener to receive notifications for the context + */ + void addListener(EventFilter filter, RuntimeEventListener listener); + + + /** + * Removes a previously registered listener + */ + void removeListener(RuntimeEventListener listener); + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/RuntimeEventListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/RuntimeEventListener.java new file mode 100644 index 0000000000..5146559098 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/RuntimeEventListener.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.event; + +import java.util.EventListener; + +/** + * Listeners observe events fired in the SCA runtime. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeEventListener extends EventListener { + + void onEvent(Event event); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/TrueFilter.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/TrueFilter.java new file mode 100644 index 0000000000..81382b86ac --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/TrueFilter.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.event; + +/** + * An event filter that always returns a true condition + * + * @version $$Rev$$ $$Date$$ + */ +public class TrueFilter implements EventFilter { + + public boolean match(Event event) { + return true; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java new file mode 100644 index 0000000000..46fa51711d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.osoa.sca.ComponentContext; + +import org.apache.tuscany.spi.component.AbstractSCAObject; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.DuplicateNameException; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.RegistrationException; +import org.apache.tuscany.spi.component.SCAObject; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.model.PropertyValue; + +/** + * @version Provides support for property accessors. + */ +public abstract class AbstractComponentExtension extends AbstractSCAObject implements Component { + protected final List<Service> services = new ArrayList<Service>(); + protected final List<Reference> references = new ArrayList<Reference>(); + protected final Map<String, SCAObject> children = new ConcurrentHashMap<String, SCAObject>(); + protected ScopeContainer scopeContainer; + private Map<String, PropertyValue<?>> defaultPropertyValues; + + /** + * Initializes component name and parent. + * + * @param name Name of the component. + */ + public AbstractComponentExtension(URI name) { + super(name); + } + + public ScopeContainer getScopeContainer() { + return scopeContainer; + } + + public void setScopeContainer(ScopeContainer scopeContainer) { + this.scopeContainer = scopeContainer; + } + + public Map<String, PropertyValue<?>> getDefaultPropertyValues() { + return defaultPropertyValues; + } + + public void setDefaultPropertyValues(Map<String, PropertyValue<?>> defaultPropertyValues) { + this.defaultPropertyValues = defaultPropertyValues; + } + + public boolean isOptimizable() { + return false; + } + + public Service getService(String name) { + if (name == null) { + if (services.size() == 1) { + return services.get(0); + } else { + return null; + } + } + SCAObject o = children.get(name); + if (o instanceof Service) { + return (Service) o; + } + return null; + } + + public Reference getReference(String name) { + if (name == null) { + if (references.size() == 1) { + return references.get(0); + } else { + return null; + } + } + SCAObject o = children.get(name); + if (o instanceof Reference) { + return (Reference) o; + } + return null; + } + + public void register(Service service) throws RegistrationException { + String name = service.getUri().getFragment(); + assert name != null; + if (children.get(name) != null) { + String uri = service.getUri().toString(); + throw new DuplicateNameException("A service or reference is already registered with the name", uri); + } + children.put(name, service); + synchronized (services) { + services.add(service); + } + } + + public void register(Reference reference) throws RegistrationException { + String name = reference.getUri().getFragment(); + assert name != null; + if (children.get(name) != null) { + String uri = reference.getUri().toString(); + throw new DuplicateNameException("A service or reference is already registered with the name", uri); + } + children.put(name, reference); + synchronized (services) { + references.add(reference); + } + } + + public ComponentContext getComponentContext() { + // by default, a component will not give out a component context + return null; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ArtifactResolverExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ArtifactResolverExtension.java new file mode 100644 index 0000000000..32d715e84b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ArtifactResolverExtension.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 org.apache.tuscany.spi.extension;
+
+import org.apache.tuscany.spi.deployer.ArtifactResolver;
+import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * The base class for ContributionProcessor implementations
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+@Service(ArtifactResolver.class)
+public abstract class ArtifactResolverExtension implements ArtifactResolver {
+ /**
+ * The ArtifactResolverRegistry that this resolver should register with; usually set by injection.
+ */
+ protected final ArtifactResolverRegistry registry;
+
+ /**
+ * @param registry the registry to set
+ */
+ @Constructor
+ public ArtifactResolverExtension(@Reference ArtifactResolverRegistry registry) {
+ this.registry = registry;
+ }
+
+ /**
+ * Initialize the resolver. It registers itself to the registry by model type it supports.
+ */
+ @Init
+ public void start() {
+ this.registry.registerResolver(this.getType(), this);
+ }
+
+ /**
+ * Destroy the resolver. It unregisters itself from the registry.
+ */
+ @Destroy
+ public void stop() {
+ registry.unregisterResolver(this.getType());
+ }
+
+ /**
+ * Returns the model type that this resolver can handle.
+ *
+ * @return the model type that this resolver can handle
+ */
+ public abstract Class<?> getType();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicComponentExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicComponentExtension.java new file mode 100644 index 0000000000..d3a835b5f5 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicComponentExtension.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.net.URI; + +import org.apache.tuscany.spi.CoreRuntimeException; +import org.apache.tuscany.spi.ObjectFactory; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.ComponentException; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.wire.ProxyService; + +/** + * An extension point for atomic component type, which new implementation types may extend + * + * @version $$Rev$$ $$Date$$ + */ +public abstract class AtomicComponentExtension extends AbstractComponentExtension implements AtomicComponent { + protected ScopeContainer scopeContainer; + protected Scope scope; + protected ProxyService proxyService; + protected WorkContext workContext; + protected final URI groupId; + private final int initLevel; + private final long maxIdleTime; + private final long maxAge; + + protected AtomicComponentExtension(URI name, + ProxyService proxyService, + WorkContext workContext, + URI groupId, + int initLevel) { + this(name, proxyService, workContext, groupId, initLevel, -1, -1); + } + + protected AtomicComponentExtension(URI name, + ProxyService proxyService, + WorkContext workContext, + URI groupId, + int initLevel, + long maxIdleTime, + long maxAge) { + super(name); + assert groupId != null; + assert !(maxIdleTime > 0 && maxAge > 0); + this.proxyService = proxyService; + this.workContext = workContext; + this.groupId = groupId; + this.initLevel = initLevel; + this.maxIdleTime = maxIdleTime; + this.maxAge = maxAge; + } + + public Scope getScope() { + return scope; + } + + public int getInitLevel() { + return initLevel; + } + + public boolean isEagerInit() { + return initLevel > 0; + } + + public long getMaxIdleTime() { + return maxIdleTime; + } + + public long getMaxAge() { + return maxAge; + } + + public void setScopeContainer(ScopeContainer scopeContainer) { + this.scopeContainer = scopeContainer; + scope = scopeContainer.getScope(); + } + + public void start() throws CoreRuntimeException { + super.start(); + scopeContainer.register(this, groupId); + } + + public void stop() { + scopeContainer.unregister(this); + super.stop(); + } + + public void removeInstance() throws ComponentException { + scopeContainer.remove(this); + } + + public ObjectFactory createObjectFactory() { + throw new UnsupportedOperationException(); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/BindingBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/BindingBuilderExtension.java new file mode 100644 index 0000000000..8490eb187d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/BindingBuilderExtension.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 org.apache.tuscany.spi.extension; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; + +import org.apache.tuscany.spi.builder.BindingBuilder; +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.builder.BuilderRegistry; +import org.apache.tuscany.spi.component.ReferenceBinding; +import org.apache.tuscany.spi.component.ServiceBinding; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.model.BindingDefinition; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ServiceDefinition; + +/** + * An extension point for binding builders. When adding support for new serviceBindings, implementations may extend this + * class as a convenience. + * + * @version $$Rev$$ $$Date$$ + */ +@EagerInit +public abstract class BindingBuilderExtension<B extends BindingDefinition> implements BindingBuilder<B> { + protected BuilderRegistry builderRegistry; + + @Reference + public void setBuilderRegistry(BuilderRegistry registry) { + this.builderRegistry = registry; + } + + @Init + public void init() { + builderRegistry.register(getBindingType(), this); + } + + public ServiceBinding build(ServiceDefinition serviceDefinition, B bindingDefinition, DeploymentContext context) + throws BuilderException { + return null; + } + + public ReferenceBinding build(ReferenceDefinition boundReferenceDefinition, + B bindingDefinition, + DeploymentContext context) throws BuilderException { + return null; + } + + protected abstract Class<B> getBindingType(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentBuilderExtension.java new file mode 100644 index 0000000000..203a703133 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentBuilderExtension.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; + +import org.apache.tuscany.spi.builder.BuilderRegistry; +import org.apache.tuscany.spi.builder.ComponentBuilder; +import org.apache.tuscany.spi.component.ScopeRegistry; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.policy.PolicyBuilderRegistry; +import org.apache.tuscany.spi.wire.ProxyService; + +/** + * An extension point for component builders. When adding support for new component types, implementations may extend + * this class as a convenience. + * + * @version $$Rev$$ $$Date$$ + */ +@EagerInit +public abstract class ComponentBuilderExtension<I extends Implementation<?>> implements ComponentBuilder<I> { + protected BuilderRegistry builderRegistry; + protected ScopeRegistry scopeRegistry; + protected ProxyService proxyService; + protected WorkContext workContext; + protected PolicyBuilderRegistry policyBuilderRegistry; + + @Reference + public void setBuilderRegistry(BuilderRegistry registry) { + this.builderRegistry = registry; + } + + @Reference + public void setScopeRegistry(ScopeRegistry scopeRegistry) { + this.scopeRegistry = scopeRegistry; + } + + @Reference + public void setProxyService(ProxyService proxyService) { + this.proxyService = proxyService; + } + + @Reference + public void setWorkContext(WorkContext workContext) { + this.workContext = workContext; + } + + @Reference + public void setPolicyBuilderRegistry(PolicyBuilderRegistry registry) { + policyBuilderRegistry = registry; + } + + @Init + public void init() { + builderRegistry.register(getImplementationType(), this); + } + + protected abstract Class<I> getImplementationType(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.java new file mode 100644 index 0000000000..097b94318a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +import org.apache.tuscany.spi.loader.ComponentTypeLoader; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.model.Implementation; + +/** + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +@EagerInit +public abstract class ComponentTypeLoaderExtension<I extends Implementation> implements ComponentTypeLoader<I> { + protected LoaderRegistry loaderRegistry; + + protected ComponentTypeLoaderExtension() { + } + + protected ComponentTypeLoaderExtension(LoaderRegistry loaderRegistry) { + this.loaderRegistry = loaderRegistry; + } + + @Reference + public void setLoaderRegistry(LoaderRegistry loaderRegistry) { + this.loaderRegistry = loaderRegistry; + } + + @Init + public void start() { + loaderRegistry.registerLoader(getImplementationClass(), this); + } + + @Destroy + public void stop() { + loaderRegistry.unregisterLoader(getImplementationClass()); + } + + protected abstract Class<I> getImplementationClass(); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java new file mode 100644 index 0000000000..5ca43b3e67 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.net.URI; + +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.ReferenceBinding; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.component.ServiceBinding; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.event.Event; +import org.apache.tuscany.spi.event.RuntimeEventListener; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.wire.TargetInvoker; + +/** + * An extension point for composite components, which new types may extend + * + * @version $$Rev$$ $$Date$$ + */ +public abstract class CompositeComponentExtension extends AbstractComponentExtension implements RuntimeEventListener { + + protected CompositeComponentExtension(URI name) { + super(name); + } + + public Scope getScope() { + return Scope.SYSTEM; + } + + public void onEvent(Event event) { + publish(event); + } + + public TargetInvoker createTargetInvoker(String name, Operation operation) + throws TargetInvokerCreationException { + Service service = getService(name); + if (service != null) { + if (service.getServiceBindings().isEmpty()) { + // for now, throw an assertion exception. + // We will need to choose bindings during allocation + throw new AssertionError(); + } + ServiceBinding binding = service.getServiceBindings().get(0); + return binding.createTargetInvoker(name, operation); + } + Reference reference = getReference(name); + if (reference != null) { + if (reference.getReferenceBindings().isEmpty()) { + // for now, throw an assertion exception. + // We will need to choose bindings during allocation + throw new AssertionError(); + } + ReferenceBinding binding = reference.getReferenceBindings().get(0); + binding.createTargetInvoker(name, operation); + } + return null; + } + + public TargetInvoker createTargetInvoker(String name, PhysicalOperationDefinition operation) + throws TargetInvokerCreationException { + Service service = getService(name); + if (service != null) { + if (service.getServiceBindings().isEmpty()) { + // for now, throw an assertion exception. + // We will need to choose bindings during allocation + throw new AssertionError(); + } + ServiceBinding binding = service.getServiceBindings().get(0); + return binding.createTargetInvoker(name, operation); + } + Reference reference = getReference(name); + if (reference != null) { + if (reference.getReferenceBindings().isEmpty()) { + // for now, throw an assertion exception. + // We will need to choose bindings during allocation + throw new AssertionError(); + } + ReferenceBinding binding = reference.getReferenceBindings().get(0); + binding.createTargetInvoker(name, operation); + } + return null; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ContributionProcessorExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ContributionProcessorExtension.java new file mode 100644 index 0000000000..8b9b1e8dc7 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ContributionProcessorExtension.java @@ -0,0 +1,76 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.spi.extension;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.deployer.ContributionProcessor;
+import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
+
+/**
+ * The base class for ContributionProcessor implementations
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+@Service(ContributionProcessor.class)
+public abstract class ContributionProcessorExtension implements ContributionProcessor {
+ /**
+ * The ContributionProcessorRegistry that this processor should register with; usually set by injection. This
+ * registry may also be used to process other sub-artifacts.
+ */
+ protected ContributionProcessorRegistry registry;
+
+ /**
+ * @param registry the registry to set
+ */
+ @Reference
+ public void setContributionProcessorRegistry(ContributionProcessorRegistry registry) {
+ this.registry = registry;
+ }
+
+ /**
+ * Initialize the processor. It registers itself to the registry by content type it supports.
+ */
+ @Init
+ public void start() {
+ registry.register(this.getContentType(), this);
+ }
+
+ /**
+ * Destroy the processor. It unregisters itself from the registry.
+ */
+ @Destroy
+ public void stop() {
+ registry.unregister(this.getContentType());
+ }
+
+ /**
+ * Returns the content type that this implementation can handle.
+ *
+ * @return the content type that this implementation can handle
+ */
+ public abstract String getContentType();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ExecutionMonitor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ExecutionMonitor.java new file mode 100644 index 0000000000..fc6e5b7a14 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ExecutionMonitor.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +/** + * A monitor used to log events during an invocation + * + * @version $$Rev$$ $$Date$$ + */ +public interface ExecutionMonitor { + + /** + * Logs an exception thrown during an invocation + */ + void executionError(Throwable e); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtension.java new file mode 100644 index 0000000000..85cd3a1fa2 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtension.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 org.apache.tuscany.spi.extension; + +import javax.xml.namespace.QName; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; + +import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilder; +import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilderRegistry; + +/** + * Abstract class interceptor builders may extend to handle registration with the interceptor builder registry + * + * @version $Rev$ $Date$ + */ +@EagerInit +public abstract class InterceptorBuilderExtension implements InterceptorBuilder { + protected InterceptorBuilderRegistry registry; + + @Reference(required = true) + public void setRegistry(InterceptorBuilderRegistry registry) { + this.registry = registry; + } + + @Init + public void init() { + registry.register(getName(), this); + } + + protected abstract QName getName(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/LoaderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/LoaderExtension.java new file mode 100644 index 0000000000..db041cd51d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/LoaderExtension.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 org.apache.tuscany.spi.extension; + +import javax.xml.namespace.QName; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; + +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.StAXElementLoader; +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Support class for extending the Loader mechanism. + * + * @version $Rev$ $Date$ + */ +@EagerInit +public abstract class LoaderExtension<T extends ModelObject> implements StAXElementLoader<T> { + /** + * The LoaderRegistry that this loader should register with; usually set by injection. This registry may also be + * used to load sub-elements. + */ + protected LoaderRegistry registry; + + /** + * Constructor specifies the registry to register with. + * + * @param registry the LoaderRegistry this loader should register with + */ + protected LoaderExtension(@Reference LoaderRegistry registry) { + this.registry = registry; + } + + /** + * Initialize the loader. The base implementation registers this loader with the registry as a handler for the XML + * type returned by {@link #getXMLType()}. Implementations may override this to register the loader as a handler for + * multiple XML types. + */ + @Init + public void start() { + registry.registerLoader(getXMLType(), this); + } + + /** + * Destroy the loader. The base implementation unregisters the loader from the regsitry based on the type returned + * by {@link #getXMLType()}. + */ + @Destroy + public void stop() { + registry.unregisterLoader(getXMLType(), this); + } + + /** + * Returns the QName of the element that this implementation handles. + * + * @return the QName of the element that this implementation handles + */ + public abstract QName getXMLType(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceBindingExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceBindingExtension.java new file mode 100644 index 0000000000..1f577a4104 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceBindingExtension.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 org.apache.tuscany.spi.extension; + +import java.net.URI; + +import org.apache.tuscany.spi.component.AbstractSCAObject; +import org.apache.tuscany.spi.component.ReferenceBinding; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.Wire; + +/** + * The default implementation of an SCA reference + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public abstract class ReferenceBindingExtension extends AbstractSCAObject implements ReferenceBinding { + protected Wire wire; + protected ServiceContract<?> bindingServiceContract; + protected URI targetUri; + + protected ReferenceBindingExtension(URI name, URI targetUri) { + super(name); + this.targetUri = targetUri; + } + + public ServiceContract<?> getBindingServiceContract() { + return bindingServiceContract; + } + + public Wire getWire() { + return wire; + } + + public void setWire(Wire wire) { + this.wire = wire; + } + + + public URI getTargetUri() { + return targetUri; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceBindingExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceBindingExtension.java new file mode 100644 index 0000000000..eb8aa5dac2 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceBindingExtension.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.net.URI; + +import org.apache.tuscany.spi.CoreRuntimeException; +import org.apache.tuscany.spi.component.AbstractSCAObject; +import org.apache.tuscany.spi.component.ServiceBinding; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.Wire; + +/** + * The default implementation of an SCA service + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public abstract class ServiceBindingExtension extends AbstractSCAObject implements ServiceBinding { + protected ServiceContract<?> bindingServiceContract; + protected Wire wire; + + public ServiceBindingExtension(URI name) throws CoreRuntimeException { + super(name); + } + + public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) + throws TargetInvokerCreationException { + throw new UnsupportedOperationException(); + } + + public ServiceContract<?> getBindingServiceContract() { + return bindingServiceContract; + } + + public Wire getWire() { + return wire; + } + + public void setWire(Wire wire) { + this.wire = wire; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/TargetInvokerExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/TargetInvokerExtension.java new file mode 100644 index 0000000000..1250907085 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/TargetInvokerExtension.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.TargetInvoker; + +/** + * The default implementation of a TargetInvoker + * + * @version $Rev$ $Date$ + */ +public abstract class TargetInvokerExtension implements TargetInvoker { + protected boolean cacheable; + + public Message invoke(Message msg) throws InvocationRuntimeException { + try { + Object messageId = msg.getMessageId(); + WorkContext workContext = msg.getWorkContext(); + if (messageId != null) { + workContext.setCorrelationId(messageId); + } + LinkedList<URI> callbackRoutingChain = msg.getCallbackUris(); + if (callbackRoutingChain != null) { + workContext.setCallbackUris(callbackRoutingChain); + } + Object resp = invokeTarget(msg.getBody(), msg.getConversationSequence(), workContext); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBodyWithFault(e.getCause()); + } + return msg; + } + + public boolean isCacheable() { + return cacheable; + } + + public void setCacheable(boolean cacheable) { + this.cacheable = cacheable; + } + + public boolean isOptimizable() { + return isCacheable(); + } + + public Object clone() throws CloneNotSupportedException { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + // TargetInvoker extends Cloneable so this should not have been thrown + throw new AssertionError(e); + } + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/BindingGenerator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/BindingGenerator.java new file mode 100644 index 0000000000..34b57bdb3f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/BindingGenerator.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.generator; + +import org.apache.tuscany.spi.model.BindingDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition; + +/** + * @version $Rev$ $Date$ + */ +public interface BindingGenerator { + + PhysicalWireSourceDefinition generateWireSource(BindingDefinition definition, GeneratorContext context) + throws GenerationException; + + PhysicalWireTargetDefinition generateWireTarget(BindingDefinition definition, GeneratorContext context) + throws GenerationException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ComponentGenerator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ComponentGenerator.java new file mode 100644 index 0000000000..583cd2574a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ComponentGenerator.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.generator; + +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ServiceDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition; + +/** + * Implementations are responsible for generating {@link org.apache.tuscany.spi.model.physical.PhysicalChangeSet} + * metadata used to provision components to service nodes + * + * @version $Rev$ $Date$ + */ +public interface ComponentGenerator<C extends ComponentDefinition<? extends Implementation>> { + + /** + * Generates an {@link org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition} based on a {@link + * org.apache.tuscany.spi.model.ComponentDefinition}. The resulting PhysicalComponentDefinition is added to the + * PhysicalChangeSet associated with the current GeneratorContext. + * + * @param definition the component definition to evaluate + * @param context the current generator context, which contains the PhysicalChangeSet to be marshalled + * @throws GenerationException if an error occurs during the generation process + */ + void generate(C definition, GeneratorContext context) throws GenerationException; + + /** + * Generates a {@link PhysicalWireSourceDefinition} used to attach a wire to a source component. Metadata contained + * in the PhysicalWireSourceDefinition is specific to the component implementation type and used when the wire is + * attached to its source on a service node. + * + * @param definition the component definition for the wire source + * @param referenceDefinition the source reference definition + * @param optimizable true is the wire may be optimized. ComponentGenerator implementations may decide to + * attach optimizable wires is a specialized manner, such as by not generating proxies + * @param context the current generator context + * @return the meta data used to attach the wire to its source on the service node + * @throws GenerationException if an error occurs during the generation process + */ + PhysicalWireSourceDefinition generateWireSource(C definition, + ReferenceDefinition referenceDefinition, + boolean optimizable, + GeneratorContext context) throws GenerationException; + + /** + * Generates a {@link PhysicalWireTargetDefinition} used to attach a wire to a target component. Metadata contained + * in the PhysicalWireSourceDefinition is specific to the component implementation type and used when the wire is + * attached to its target on a service node. + * + * @param definition the component definition for the wire source + * @param serviceDefinition the target refernce definition + * @param context the current generator context + * @return the meta data used to attach the wire to its target on the service node + * @throws GenerationException if an error occurs during the generation process + */ + PhysicalWireTargetDefinition generateWireTarget(C definition, + ServiceDefinition serviceDefinition, + GeneratorContext context) throws GenerationException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GenerationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GenerationException.java new file mode 100644 index 0000000000..33ab768494 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GenerationException.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.generator; + +import org.apache.tuscany.api.TuscanyException; + +/** + * Base generation exception + * + * @version $Rev$ $Date$ + */ +public abstract class GenerationException extends TuscanyException { + + public GenerationException() { + } + + public GenerationException(String message) { + super(message); + } + + public GenerationException(String message, String identifier) { + super(message, identifier); + } + + public GenerationException(String message, Throwable cause) { + super(message, cause); + } + + public GenerationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public GenerationException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorContext.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorContext.java new file mode 100644 index 0000000000..d1fb5e5a7a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorContext.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 org.apache.tuscany.spi.generator; + +import org.apache.tuscany.spi.model.physical.PhysicalChangeSet; + +/** + * A context used during generation of physical definitions + * + * @version $Rev$ $Date$ + */ +public interface GeneratorContext { + + /** + * Returns the current changeset. + * + * @return the current changeset + */ + PhysicalChangeSet getPhysicalChangeSet(); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorRegistry.java new file mode 100644 index 0000000000..a9c76d9fe4 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorRegistry.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.generator; + +import java.net.URI; + +import org.apache.tuscany.spi.model.BindingDefinition; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.model.IntentDefinition; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ResourceDefinition; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.ServiceDefinition; + +/** + * A registry for generators + * + * @version $Rev$ $Date$ + */ +public interface GeneratorRegistry { + + public <T extends Implementation<?>> void register(Class<T> clazz, + ComponentGenerator<ComponentDefinition<T>> generator); + + void register(Class<?> clazz, BindingGenerator generator); + + <T extends IntentDefinition> void register(Class<T> phase, InterceptorGenerator<T> generator); + + void register(Class<?> clazz, ResourceGenerator generator); + + /** + * Generates a PhysicalComponentDefinition + * + * @param definition + * @param context + * @throws GenerationException + */ + <C extends ComponentDefinition<? extends Implementation>> void generate(C definition, GeneratorContext context) + throws GenerationException; + + + /** + * Generates a PhysicalWireDefinition from a service binding to a component service + * + * @param contract + * @param bindingDefinition + * @param componentDefinition + * @param context + * @param serviceDefinition + * @throws GenerationException + */ + <C extends ComponentDefinition<? extends Implementation>> void generateWire(ServiceContract<?> contract, + BindingDefinition bindingDefinition, + ServiceDefinition serviceDefinition, + C componentDefinition, + GeneratorContext context) + throws GenerationException; + + + <C extends ComponentDefinition<? extends Implementation>> void generateWire(C componentDefinition, + ReferenceDefinition referenceDefinition, + BindingDefinition bindingDefinition, + GeneratorContext context) + throws GenerationException; + + <S extends ComponentDefinition<? extends Implementation>, T extends ComponentDefinition<? extends Implementation>> + void generateWire(S sourceDefinition, + ReferenceDefinition referenceDefinition, + ServiceDefinition serviceDefinition, + T targetDefinition, + GeneratorContext context) throws GenerationException; + + URI generate(ResourceDefinition definition, GeneratorContext context) throws GenerationException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/InterceptorGenerator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/InterceptorGenerator.java new file mode 100644 index 0000000000..7f93aa61ce --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/InterceptorGenerator.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.generator; + +import org.apache.tuscany.spi.model.IntentDefinition; +import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition; + +/** + * Implementations are responsible for generating physical interceptor definitions for a wire based on an intent. + * + * @version $Rev$ $Date$ + */ +public interface InterceptorGenerator<T extends IntentDefinition> { + + /** + * Generates the physical interceptor definition for a wire + * + * @param definition the intent definition + * @param context the current generator context + * @return the interceptor definition + * @throws GenerationException if an error occurs during the generation process + */ + PhysicalInterceptorDefinition generate(T definition, GeneratorContext context) throws GenerationException; + +} + diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ResourceGenerator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ResourceGenerator.java new file mode 100644 index 0000000000..2ef422c03d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ResourceGenerator.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.generator; + +import java.net.URI; + +import org.apache.tuscany.spi.model.ResourceDefinition; + +/** + * Implementations generate physical resource definitions + * + * @version $Rev$ $Date$ + */ +public interface ResourceGenerator { + + /** + * Updates the change set with a physical resource definition + * + * @param definition the logical resource definition to generate the physical definition from + * @param context the current generator context + * @return the id of the physical resource + * @throws GenerationException if an error occurs during the generation process + */ + URI generate(ResourceDefinition definition, GeneratorContext context) throws GenerationException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHost.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHost.java new file mode 100644 index 0000000000..b273ec6729 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHost.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.host; + +/** + * Interface implemented by host environments that allow for resolution of component implementation resources, e.g. + * items bound in a JNDI tree. + * + * @version $Rev$ $Date$ + */ +public interface ResourceHost { + + /** + * Resolve a resource matching the given type + * + * @param type the type of the resources + * @throws ResourceResolutionException if an error is encountered during resolution + */ + <T> T resolveResource(Class<T> type) throws ResourceResolutionException; + + /** + * Resolve a resource matching the given type and name + * + * @param type the type of the resources + * @param mappedName the mapped name of the resource + * @throws ResourceResolutionException if an error is encountered during resolution + */ + <T> T resolveResource(Class<T> type, String mappedName) throws ResourceResolutionException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java new file mode 100644 index 0000000000..b4964cce3b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.host; + +/** + * Implementations manage a registry of resources and resource hosts in the runtime + * + * @version $Rev$ $Date$ + */ +public interface ResourceHostRegistry { + /** + * Registers a resource host for the given uri prefix + * + * @param uri the uri prefix the host resolves resources for + * @param host the resource host + */ + void registerResourceHost(String uri, ResourceHost host); + + /** + * Removes a resource host registered for the given uri prefix + */ + void unregisterResourceHost(String uri); + + /** + * Register a resource by type + * + * @param type the type of the resource + * @param resource the resource + */ + void registerResource(Class<?> type, Object resource); + + /** + * Register a resource by type and name + * + * @param type the type of the resource + * @param name the mapped resource name + * @param resource the resource + */ + void registerResource(Class<?> type, String name, Object resource); + + /** + * Unregister a resource + * + * @param type the type the resource was registered with + * @param name the mapped name the resource was registered with + */ + void unregisterResource(Class<?> type, String name); + + /** + * Unregister a resource + * + * @param type the type the resource was registered with + */ + void unregisterResource(Class<?> type); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceResolutionException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceResolutionException.java new file mode 100644 index 0000000000..23c18f5115 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceResolutionException.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.host; + +import org.apache.tuscany.api.TuscanyException; + +/** + * @version $Rev$ $Date$ + */ +public class ResourceResolutionException extends TuscanyException { + + public ResourceResolutionException(String message, String identifier) { + super(message, identifier); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ServletHost.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ServletHost.java new file mode 100644 index 0000000000..37937808d4 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ServletHost.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.host; + +import javax.servlet.Servlet; + +/** + * Interface implemented by host environments that allow Servlets to be registered. + * <p/> + * This interface allows an SCA system service to register a servlet to handle inbound requests. + * + * @version $Rev$ $Date$ + */ +public interface ServletHost { + /** + * Register a mapping for an instance of a Servlet. This requests that the servlet container direct all requests to + * the designated mapping to the supplied Servlet instance. + * + * @param mapping the uri-mapping for the Servlet + * @param servlet the Servlet that should be invoked + */ + void registerMapping(String mapping, Servlet servlet); + + /** + * Unregister a servlet mapping. This directs the servlet contain not to direct any more requests to a previously + * registered Servlet. + * + * @param mapping the uri-mapping for the Servlet + * @return the servlet that was registered to the mapping, null if nothing was registered to the mapping + */ + Servlet unregisterMapping(String mapping); + + /** + * Check to see if a mapping exists. + * + * @param mapping the uri-mapping for the Servlet + * @return true if mapping is registered, false otherwise + */ + boolean isMappingRegistered(String mapping); + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ElementInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ElementInfo.java new file mode 100644 index 0000000000..5a0bd3bb5f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ElementInfo.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 org.apache.tuscany.spi.idl; + +import javax.xml.namespace.QName; + +/** + * An abstraction of XML schema elements + */ +public class ElementInfo { + private QName name; + private TypeInfo type; + + /** + * @param name + * @param type + */ + public ElementInfo(QName name, TypeInfo type) { + super(); + this.name = name; + this.type = type; + } + + /** + * @return the name + */ + public QName getQName() { + return name; + } + + /** + * @return the type + */ + public TypeInfo getType() { + return type; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidConversationalOperationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidConversationalOperationException.java new file mode 100644 index 0000000000..e2b4acec24 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidConversationalOperationException.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.idl; + +import java.lang.reflect.Method; + +/** + * Denotes an invalid conversational interface definition + * + * @version $Rev$ $Date$ + */ +public class InvalidConversationalOperationException extends InvalidServiceContractException { + private final Method operation; + + public InvalidConversationalOperationException(String message, String identifier, Method operation) { + super(message, identifier); + this.operation = operation; + } + + public Method getOperation() { + return operation; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidServiceContractException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidServiceContractException.java new file mode 100644 index 0000000000..e977592df0 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidServiceContractException.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 org.apache.tuscany.spi.idl; + +import org.apache.tuscany.api.TuscanyException; + +/** + * @version $Rev$ $Date$ + */ +public abstract class InvalidServiceContractException extends TuscanyException { + + public InvalidServiceContractException() { + } + + public InvalidServiceContractException(String message) { + super(message); + } + + protected InvalidServiceContractException(String message, String identifier) { + super(message, identifier); + } + + public InvalidServiceContractException(String message, Throwable cause) { + super(message, cause); + } + + protected InvalidServiceContractException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public InvalidServiceContractException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/OverloadedOperationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/OverloadedOperationException.java new file mode 100644 index 0000000000..b1d4cb4e7c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/OverloadedOperationException.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.idl; + +import java.lang.reflect.Method; + +/** + * Exception thrown to indicate that a service contract specification contains an overloaded method. + * + * @version $Rev$ $Date$ + */ +public class OverloadedOperationException extends InvalidServiceContractException { + private static final long serialVersionUID = -4658711318608885638L; + private final Method operation; + + public OverloadedOperationException(Method operation) { + super(null, operation.getDeclaringClass().getName()); + this.operation = operation; + } + + public Method getOperation() { + return operation; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java new file mode 100644 index 0000000000..559cf409cc --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.idl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.api.TuscanyException; + +/** + * The generic java exception to wrap service faults + * + * @version $Rev$ $Date$ + */ +public class ServiceFaultException extends TuscanyException { + private static final long serialVersionUID = -8002583655240625792L; + private Object faultInfo; + private QName logical; + + /** + * @param message + * @param faultInfo + */ + public ServiceFaultException(String message, Object faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * @param message + * @param faultInfo + * @param cause + */ + public ServiceFaultException(String message, Object faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * @return the faultInfo + */ + public Object getFaultInfo() { + return faultInfo; + } + + public QName getLogical() { + return logical; + } + + public void setLogical(QName logical) { + this.logical = logical; + } + + public boolean isMatchingType(Object type) { + if (logical == null) { + return false; + } + + if ((type instanceof QName) && logical.equals(type)) { + return true; + } + if (type instanceof XMLType && logical.equals(((XMLType)type).getElementName())) { + return true; + } + return false; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/TypeInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/TypeInfo.java new file mode 100644 index 0000000000..9bb107812c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/TypeInfo.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.idl; + +import javax.xml.namespace.QName; + +/** + * An abstraction of XML schema types + */ +public class TypeInfo { + private QName name; + + private boolean isSimpleType; + + private TypeInfo baseType; + + /** + * @param name + * @param isSimpleType + */ + public TypeInfo(QName name, boolean isSimpleType, TypeInfo baseType) { + super(); + this.name = name; + this.isSimpleType = isSimpleType; + this.baseType = baseType; + } + + /** + * @return the isSimpleType + */ + public boolean isSimpleType() { + return isSimpleType; + } + + /** + * @return the name + */ + public QName getQName() { + return name; + } + + /** + * @return the baseType + */ + public TypeInfo getBaseType() { + return baseType; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/XMLType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/XMLType.java new file mode 100644 index 0000000000..1d626516b0 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/XMLType.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.idl; + +import javax.xml.namespace.QName; + +/** + * The metadata for an XML element or type + */ +public class XMLType { + public static final XMLType UNKNOWN = new XMLType(null, null); + private QName element; + private QName type; + + /** + * @param element + */ + public XMLType(ElementInfo element) { + super(); + this.element = element.getQName(); + if (element.getType() != null) { + this.type = element.getType().getQName(); + } + } + + /** + * @param element + */ + public XMLType(TypeInfo type) { + this.element = null; + this.type = type.getQName(); + } + + public XMLType(QName element, QName type) { + this.element = element; + this.type = type; + } + + /** + * @return the type + */ + public QName getTypeName() { + return type; + } + + public boolean isElement() { + return element != null; + } + + public QName getElementName() { + return element; + } + + public static XMLType getType(QName type) { + return new XMLType(null, type); + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((element == null) ? 0 : element.hashCode()); + result = PRIME * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final XMLType other = (XMLType)obj; + if (element == null) { + if (other.element != null) { + return false; + } + } else if (!element.equals(other.element)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Element: " + element + " Type: " + type; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/InterfaceJavaIntrospector.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/InterfaceJavaIntrospector.java new file mode 100644 index 0000000000..13946793ea --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/InterfaceJavaIntrospector.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.idl.java; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; + +/** + * Processor for creating JavaServiceContract definitions from Java Classes. + * + * @version $Rev$ $Date$ + */ +public interface InterfaceJavaIntrospector { + + /** + * Introspect a Java interface and return a service contract definition. + * + * @param type the interface to inspect + * @return a JavaServiceContract corresponding to the Java interface + */ + <I> JavaServiceContract<I> introspect(Class<I> type) throws InvalidServiceContractException; + + /** + * Introspect a Java interface and return a service contract definition. + * + * @param type the interface to inspect + * @param callback the callback interface to inspec + * @return a JavaServiceContract corresponding to the Java interface + */ + <I, C> JavaServiceContract<I> introspect(Class<I> type, Class<C> callback) throws InvalidServiceContractException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java new file mode 100644 index 0000000000..83b8d19e79 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.idl.java; + +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; + +/** + * Contains methods for mapping between an operation in a {@link org.apache.tuscany.spi.model.ServiceContract} and a + * method defined by a Java interface + * + * @version $Rev$ $Date$ + */ +public final class JavaIDLUtils { + + private JavaIDLUtils() { + } + + /** + * Return the method on the implementation class that matches the operation. + * + * @param implClass the implementation class or interface + * @param operation the operation to match + * @return the method described by the operation + * @throws NoSuchMethodException if no such method exists + * @Deprecated + */ + public static <T> Method findMethod(Class<?> implClass, Operation<T> operation) throws NoSuchMethodException { + String name = operation.getName(); + Class<?>[] paramTypes = getPhysicalTypes(operation); + return implClass.getMethod(name, paramTypes); + } + + /** + * TODO JFM testme + */ + public static Method findMethod2(Class<?> implClass, PhysicalOperationDefinition operation) + throws NoSuchMethodException, ClassNotFoundException { + String name = operation.getName(); + List<String> params = operation.getParameters(); + Class<?>[] types = new Class<?>[params.size()]; + for (int i = 0; i < params.size(); i++) { + types[i] = implClass.getClassLoader().loadClass(params.get(i)); + } + return implClass.getMethod(name, types); + } + + + /** + * @Deprecated + */ + private static <T> Class<?>[] getPhysicalTypes(Operation<T> operation) { + DataType<List<DataType<T>>> inputType = operation.getInputType(); + List<DataType<T>> types = inputType.getLogical(); + Class<?>[] javaTypes = new Class<?>[types.size()]; + for (int i = 0; i < javaTypes.length; i++) { + Type physical = types.get(i).getPhysical(); + if (physical instanceof Class<?>) { + javaTypes[i] = (Class<?>) physical; + } else { + throw new UnsupportedOperationException(); + } + } + return javaTypes; + } + + /** + * Searches a collection of operations for a match against the given method + * + * @param method the method to match + * @param operations the operations to match against + * @return a matching operation or null + * @Deprecated + */ + public static Operation findOperation(Method method, Collection<Operation<?>> operations) { + for (Operation<?> operation : operations) { + if (match(operation, method)) { + return operation; + } + } + return null; + } + + public static PhysicalOperationDefinition findOperation2(Method method, + Collection<PhysicalOperationDefinition> operations) { + for (PhysicalOperationDefinition operation : operations) { + Class<?>[] params = method.getParameterTypes(); + List<String> types = operation.getParameters(); + boolean found = true; + if (types.size() == params.length && method.getName().equals(operation.getName())) { + for (int i = 0; i < params.length; i++) { + if (params[i].getName().equals(types.get(0))) { + found = false; + } + } + if (found) { + return operation; + } + } + } + return null; + } + + /** + * Determines if the given operation matches the given method + * + * @return true if the operation matches, false if does not + */ + private static <T> boolean match(Operation<T> operation, Method method) { + Class<?>[] params = method.getParameterTypes(); + DataType<List<DataType<T>>> inputType = operation.getInputType(); + List<DataType<T>> types = inputType.getLogical(); + boolean found = true; + if (types.size() == params.length && method.getName().equals(operation.getName())) { + for (int i = 0; i < params.length; i++) { + Class<?> clazz = params[i]; + if (!clazz.equals(operation.getInputType().getLogical().get(i).getPhysical())) { + found = false; + } + } + } else { + found = false; + } + return found; + + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessor.java new file mode 100644 index 0000000000..afe98f0773 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessor.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.idl.java; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; + +/** + * Implementations introspect metadata on a Java interface, populating the + * corresponding {@link JavaServiceContract} + * + * @version $Rev$ $Date$ + */ +public interface JavaInterfaceProcessor { + + void visitInterface(Class<?> clazz, Class<?> callbackClass, JavaServiceContract contract) + throws InvalidServiceContractException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorExtension.java new file mode 100644 index 0000000000..5c9ad40053 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorExtension.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.idl.java; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; + +/** + * A convenience class for <code>JavaInterfaceProcessor</code> extensions that performs autowiring + * + * @version $Rev$ $Date$ + */ +@EagerInit +public abstract class JavaInterfaceProcessorExtension implements JavaInterfaceProcessor { + + protected JavaInterfaceProcessorRegistry registry; + + @Reference + public void setRegistry(JavaInterfaceProcessorRegistry registry) { + this.registry = registry; + } + + @Init + public void init() { + registry.registerProcessor(this); + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorRegistry.java new file mode 100644 index 0000000000..38c64e6f88 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorRegistry.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.idl.java; + +/** + * A registry of {@link JavaInterfaceProcessor}s. Interface processors update a service contract definition based on a + * Java interface + * + * @version $Rev$ $Date$ + */ +public interface JavaInterfaceProcessorRegistry extends InterfaceJavaIntrospector { + + /** + * Registers the given processor + */ + void registerProcessor(JavaInterfaceProcessor processor); + + /** + * Deregisters the given processor + */ + void unregisterProcessor(JavaInterfaceProcessor processor); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaServiceContract.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaServiceContract.java new file mode 100644 index 0000000000..9571dd86cf --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaServiceContract.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.idl.java; + +import java.lang.reflect.Type; + +import org.apache.tuscany.spi.model.ServiceContract; + +/** + * Represents a service contract specified using a Java interface + * + * @version $Rev$ $Date$ + */ +public class JavaServiceContract<I> extends ServiceContract<Type> { + + public JavaServiceContract() { + } + + public JavaServiceContract(Class<I> interfaceClass) { + super(interfaceClass); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java new file mode 100644 index 0000000000..d81ec73ba1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Map; + +import org.apache.tuscany.spi.databinding.DataBinding; +import org.apache.tuscany.spi.deployer.DeploymentContext; + +import org.apache.tuscany.api.annotation.DataType; + +/** + * Base class for ImplementationProcessors that handle annotations that add Properties. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractPropertyProcessor<A extends Annotation> extends ImplementationProcessorExtension { + private final Class<A> annotationClass; + private ImplementationProcessorService service; + + protected AbstractPropertyProcessor(Class<A> annotationClass, ImplementationProcessorService service) { + this.annotationClass = annotationClass; + this.service = service; + } + + public void visitMethod( + Method method, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException { + A annotation = method.getAnnotation(annotationClass); + if (annotation == null) { + return; + } + + if (!Void.TYPE.equals(method.getReturnType())) { + throw new IllegalPropertyException("Method does not have void return type", method.toString()); + } + Class[] paramTypes = method.getParameterTypes(); + if (paramTypes.length != 1) { + throw new IllegalPropertyException("Method must have a single parameter", method.toString()); + } + Class<?> javaType = paramTypes[0]; + + String name = getName(annotation); + if (name == null || name.length() == 0) { + name = method.getName(); + if (name.startsWith("set")) { + name = toPropertyName(method.getName()); + } + } + + Map<String, JavaMappedProperty<?>> properties = type.getProperties(); + if (properties.containsKey(name)) { + throw new DuplicatePropertyException(name); + } + + Class<?> baseType = getBaseType(javaType, method.getGenericParameterTypes()[0]); + JavaMappedProperty<?> property = createProperty(name, baseType, method); + if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) { + property.setMany(true); + } + + //add databinding available as annotations, as extensions + DataType propertyDataBinding = method.getAnnotation(DataType.class); + if (propertyDataBinding != null) { + property.getExtensions().put(DataBinding.class.getName(), propertyDataBinding.name()); + } + initProperty(property, annotation, context); + properties.put(name, property); + } + + public void visitField( + Field field, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException { + + A annotation = field.getAnnotation(annotationClass); + if (annotation == null) { + return; + } + + Class<?> javaType = field.getType(); + + String name = getName(annotation); + if (name == null || name.length() == 0) { + name = field.getName(); + } + + Map<String, JavaMappedProperty<?>> properties = type.getProperties(); + if (properties.containsKey(name)) { + throw new DuplicatePropertyException(name); + } + + Class<?> baseType = getBaseType(javaType, field.getGenericType()); + JavaMappedProperty<?> property = createProperty(name, baseType, field); + if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) { + property.setMany(true); + } + + //add databinding available as annotations, as extensions + DataType propertyDataBinding = field.getAnnotation(DataType.class); + if (propertyDataBinding != null) { + property.getExtensions().put(DataBinding.class.getName(), propertyDataBinding.name()); + } + + initProperty(property, annotation, context); + properties.put(name, property); + } + + public <T> void visitConstructor(Constructor<T> constructor, + PojoComponentType<JavaMappedService, + JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException { + + ConstructorDefinition<?> definition = type.getConstructorDefinition(); + Class[] params = constructor.getParameterTypes(); + Map<String, JavaMappedProperty<?>> properties = type.getProperties(); + Annotation[][] annotations = constructor.getParameterAnnotations(); + for (int i = 0; i < params.length; i++) { + Class<?> param = params[i]; + Annotation[] paramAnnotations = annotations[i]; + for (Annotation annotation : paramAnnotations) { + if (annotation.annotationType().equals(annotationClass)) { + if (definition == null) { + definition = new ConstructorDefinition<T>(constructor); + type.setConstructorDefinition(definition); + } + A monitorAnnot = annotationClass.cast(annotation); + String name = getName(monitorAnnot); + if (name == null || name.length() == 0) { + name = param.getName(); + } + + Class<?> baseType = getBaseType(param, constructor.getGenericParameterTypes()[i]); + JavaMappedProperty<?> property = createProperty(name, baseType, constructor); + if (param.isArray() || Collection.class.isAssignableFrom(param)) { + property.setMany(true); + } + initProperty(property, monitorAnnot, context); + properties.put(name, property); + service.addName(definition.getInjectionNames(), i, name); + } + } + } + } + + protected abstract String getName(A annotation); + + protected <T> void initProperty(JavaMappedProperty<T> property, A annotation, DeploymentContext context) + throws ProcessingException { + } + + protected <T> JavaMappedProperty<T> createProperty(String name, Class<T> javaType, Member member) + throws ProcessingException { + return new JavaMappedProperty<T>(name, null, javaType, member); + } + + + public static String toPropertyName(String name) { + if (!name.startsWith("set")) { + return name; + } + return Character.toLowerCase(name.charAt(3)) + name.substring(4); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ConstructorDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ConstructorDefinition.java new file mode 100644 index 0000000000..94c185966f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ConstructorDefinition.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 org.apache.tuscany.spi.implementation.java; + +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; + +/** + * Hold injection information for the constructor used to instantiate a component implementation instance + * + * @version $Rev$ $Date$ + */ +public class ConstructorDefinition<T> { + + private Constructor<T> constructor; + private List<String> injectionNames; + + public ConstructorDefinition(Constructor<T> constructor) { + this.constructor = constructor; + injectionNames = new ArrayList<String>(); + } + + public Constructor<T> getConstructor() { + return constructor; + } + + public List<String> getInjectionNames() { + return injectionNames; + } + + public void setInjectionNames(List<String> injectionNames) { + this.injectionNames = injectionNames; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/DuplicatePropertyException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/DuplicatePropertyException.java new file mode 100644 index 0000000000..87c4074fe7 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/DuplicatePropertyException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +/** + * Thrown when an implementation has more than one property injection site with the same name + * + * @version $Rev$ $Date$ + */ +public class DuplicatePropertyException extends ProcessingException { + + public DuplicatePropertyException(String message) { + super(message); + } + + public DuplicatePropertyException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IllegalPropertyException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IllegalPropertyException.java new file mode 100644 index 0000000000..f251f60630 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IllegalPropertyException.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +/** + * Denotes an illegal property definition in a component type + * + * @version $Rev$ $Date$ + */ +public class IllegalPropertyException extends ProcessingException { + + public IllegalPropertyException(String message) { + super(message); + } + + + public IllegalPropertyException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessor.java new file mode 100644 index 0000000000..e886eb7e6b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessor.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.apache.tuscany.spi.deployer.DeploymentContext; + +/** + * Implementations process class-level metadata, typically parsing annotations and updating the corresponding + * <code>ComponentType</code>. A processor may, for example, create a {@link JavaMappedProperty} which is responsible + * for injecting a complex type on a component implementation instance when it is instantiated. + * <p/> + * Processors will receive callbacks as the implementation class is walked while evalauting an assembly. It is the + * responsibility of the parser to determine whether to perform an action during the callback. + * + * @version $Rev$ $Date$ + */ +public interface ImplementationProcessor { + + /** + * A callback received when the component implementation class is first loaded + * + * @param clazz the component implementation class + * @param type the incomplete component type associated with the implementation class + * @param context the current deployment context + * @throws ProcessingException if an error is encountered while processing metadata + */ + <T> void visitClass(Class<T> clazz, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException; + + /** + * A callback received as the component implementation class hierarchy is evaluated + * + * @param clazz the superclass in the component implmentation's class hierarchy + * @param type the incomplete component type associated with the implementation class + * @param context the current deployment context + * @throws ProcessingException if an error is encountered while processing metadata + */ + <T> void visitSuperClass( + Class<T> clazz, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException; + + /** + * A callback received as the component implementation's public and protected methods are evaluated + * + * @param method the current public or protected method being evaluated + * @param type the incomplete component type associated with the implementation class + * @param context the current deployment context + * @throws ProcessingException if an error is encountered while processing metadata + */ + void visitMethod( + Method method, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException; + + /** + * A callback received as the component implementation's constructor used for instantiation by the runtime is + * evaluated. If an implementation contains more than one constructor, the constructor passed to the callback will + * be chosen according to the algorithm described in the SCA Java Client and Implementation Model Specification. + * + * @param constructor the constructor used for instantiating component implementation instances + * @param type the incomplete component type associated with the implementation class + * @param context the current deployment context + * @throws ProcessingException if an error is encountered while processing metadata + */ + <T> void visitConstructor( + Constructor<T> constructor, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) + throws ProcessingException; + + /** + * A callback received as the component implementation's public and protected fields are evaluated + * + * @param field the current public or protected field being evaluated + * @param type the incomplete component type associated with the implementation class + * @param context the current deployment context + * @throws ProcessingException if an error is encountered while processing metadata + */ + void visitField( + Field field, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException; + + /** + * The final callback received when all other callbacks during evaluation of the component implementation have been + * issued + * + * @param clazz the component implementation class + * @param type the incomplete component type associated with the implementation class + * @param context the current deployment context + * @throws ProcessingException if an error is encountered while processing metadata + */ + <T> void visitEnd( + Class<T> clazz, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorExtension.java new file mode 100644 index 0000000000..66b973a179 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorExtension.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 org.apache.tuscany.spi.implementation.java; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Collection; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; + +import org.apache.tuscany.spi.deployer.DeploymentContext; + +/** + * A convenience class for annotation processors which alleviates the need to implement unused callbacks + * + * @version $Rev$ $Date$ + */ +@EagerInit +public abstract class ImplementationProcessorExtension implements ImplementationProcessor { + private IntrospectionRegistry registry; + + @Reference + public void setRegistry(IntrospectionRegistry registry) { + this.registry = registry; + } + + @Init + public void init() { + registry.registerProcessor(this); + } + + @Destroy + public void destroy() { + registry.unregisterProcessor(this); + } + + public <T> void visitClass(Class<T> clazz, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) + throws ProcessingException { + } + + public <T> void visitSuperClass(Class<T> clazz, + PojoComponentType<JavaMappedService, + JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) + throws ProcessingException { + } + + public void visitMethod(Method method, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) + throws ProcessingException { + } + + public <T> void visitConstructor(Constructor<T> constructor, + PojoComponentType<JavaMappedService, + JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) + throws ProcessingException { + } + + public void visitField(Field field, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException { + } + + public <T> void visitEnd(Class<T> clazz, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException { + + } + + protected static Class<?> getBaseType(Class<?> cls, Type genericType) { + if (cls.isArray()) { + return cls.getComponentType(); + } else if (Collection.class.isAssignableFrom(cls)) { + if (genericType == cls) { + return Object.class; + } else { + ParameterizedType parameterizedType = (ParameterizedType) genericType; + Type baseType = parameterizedType.getActualTypeArguments()[0]; + if (baseType instanceof Class) { + return (Class<?>) baseType; + } else if (baseType instanceof ParameterizedType) { + return (Class<?>) ((ParameterizedType) baseType).getRawType(); + } else { + return null; + } + } + } else { + return cls; + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorService.java new file mode 100644 index 0000000000..9dccfad23f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorService.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Member; +import java.lang.reflect.Type; +import java.util.List; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.model.ServiceContract; + +/** + * Provides utility methods for Java implementation processing + * + * @version $Rev$ $Date$ + */ +public interface ImplementationProcessorService { + + /** + * Introspects the given interface to produce a mapped service + */ + JavaMappedService createService(Class<?> interfaze) throws InvalidServiceContractException; + + JavaMappedReference createReference(String name, Member member, Class<?> paramType) throws ProcessingException; + + /** + * Processes the callback contract for a given interface type + * + * @param interfaze the interface type to examine + * @param contract the service contract the callback is associated wth + * @throws InvalidServiceContractException + * + */ + void processCallback(Class<?> interfaze, ServiceContract<?> contract) throws InvalidServiceContractException; + + /** + * Determines if all the members of a collection have unique types + * + * @param collection the collection to analyze + * @return true if the types are unique + */ + boolean areUnique(Class[] collection); + + /** + * Inserts a name at the specified position, paddiling the list if its size is less than the position + */ + void addName(List<String> names, int pos, String name); + + /** + * Processes a constructor parameter by introspecting its annotations + * + * @param param the parameter to process + * @param genericParam the generic type of the parameter + * @param paramAnnotations the parameter annotations + * @param constructorNames the array of constructorNames specified by + * @param pos the declaration position of the constructor parameter + * @param type the component type associated with implementation being reflected + * @param injectionNames the list of parameter constructorNames specified on parameter annotations + * @throws ProcessingException + */ + boolean processParam(Class<?> param, + Type genericParam, + Annotation[] paramAnnotations, + String[] constructorNames, + int pos, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + List<String> injectionNames) throws ProcessingException; + + /** + * Returns true if <code>@Property</code> or <code>@Reference</code> are present in the given array + * @return true if one of the annotations are present + */ + boolean injectionAnnotationsPresent(Annotation[][] annots); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IntrospectionRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IntrospectionRegistry.java new file mode 100644 index 0000000000..a6122a6ff1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IntrospectionRegistry.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +/** + * A system service which tracks {@link ImplementationProcessor}s + * + * @version $Rev$ $Date$ + */ +public interface IntrospectionRegistry extends Introspector { + + /** + * Registers the given processor and makes it available during assembly evaluation (i.e. build) + */ + void registerProcessor(ImplementationProcessor processor); + + /** + * Deregisters the given processor + */ + void unregisterProcessor(ImplementationProcessor processor); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Introspector.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Introspector.java new file mode 100644 index 0000000000..bb7550440b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Introspector.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import org.apache.tuscany.spi.deployer.DeploymentContext; + +/** + * Implementations are responsible for walking a component implementation class, adding additional component type + * information as appropriate + * + * @version $Rev$ $Date$ + */ +public interface Introspector { + + /** + * Walks the given component implementation class + * + * @param clazz the component implementation class + * @param type the component type associated with the implementation class + * @return the updated component type + * @throws ProcessingException if an error is encountered evaluating the implementation class + */ + PojoComponentType introspect(Class<?> clazz, + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type, + DeploymentContext context) throws ProcessingException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedComponentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedComponentType.java new file mode 100644 index 0000000000..34ac8f53f9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedComponentType.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import org.apache.tuscany.spi.model.ComponentType; + +/** + * A specialized component type definition whose services, references and properties can be mapped to the Java + * programming model. + * + * @version $Rev$ $Date$ + */ +public class JavaMappedComponentType< + S extends JavaMappedService, + R extends JavaMappedReference, + P extends JavaMappedProperty<?> + > extends ComponentType<S, R, P> { + + private Class<?> implClass; + + public JavaMappedComponentType() { + } + + public JavaMappedComponentType(Class<?> implClass) { + this.implClass = implClass; + } + + /** + * Returns the implementation class associated with this component type. + * + * @return the implementation class associated with this component type + */ + public Class<?> getImplClass() { + return implClass; + } + + /** + * Sets the implementation class associated with this component type. + * + * @param implClass the implementation class associated with this component type + */ + public void setImplClass(Class<?> implClass) { + this.implClass = implClass; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedProperty.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedProperty.java new file mode 100644 index 0000000000..6d1715a035 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedProperty.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.reflect.Member; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.Property; + +/** + * A Property definition that is mapped to a specific location in the implementation class. This location will typically + * be used to inject property values. + * + * @version $Rev$ $Date$ + */ +public class JavaMappedProperty<T> extends Property<T> { + private Member member; + + public JavaMappedProperty() { + } + + public JavaMappedProperty(String name, QName xmlType, Class<T> javaType) { + super(name, xmlType, javaType); + } + + public JavaMappedProperty(String name, QName xmlType, Class<T> javaType, Member member) { + super(name, xmlType, javaType); + this.member = member; + } + + /** + * Returns the Member that this property is mapped to. + * + * @return the Member that this property is mapped to + */ + public Member getMember() { + return member; + } + + /** + * Sets the Member that this property is mapped to + * + * @param member the Member that this property is mapped to + */ + public void setMember(Member member) { + this.member = member; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedReference.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedReference.java new file mode 100644 index 0000000000..26b79068c2 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedReference.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.reflect.Member; +import java.net.URI; + +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ServiceContract; + +/** + * A ReferenceDefinition definition that is mapped to a specific location in the implementation class. This location + * will typically be used to inject reference values. + * + * @version $Rev$ $Date$ + */ +public class JavaMappedReference extends ReferenceDefinition { + private Member member; + + public JavaMappedReference() { + } + + public JavaMappedReference(URI name, ServiceContract serviceContract, Member member) { + super(name, serviceContract); + this.member = member; + } + + /** + * Returns the Member that this reference is mapped to. + * + * @return the Member that this reference is mapped to + */ + public Member getMember() { + return member; + } + + /** + * Sets the Member that this reference is mapped to + * + * @param member the Member that this reference is mapped to + */ + public void setMember(Member member) { + this.member = member; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedService.java new file mode 100644 index 0000000000..d7675da4e9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedService.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.reflect.Member; +import java.net.URI; + +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.ServiceDefinition; + +/** + * A ServiceDefinition definition that is mapped to a Java interface. The mapped interface is not required to be the + * same as the interface specified in the service contract. This is to allow the service contract to be specified using + * different interface definition languages or, in the case were the IDL is Java, to allow the service definition to be + * loaded from a different classloader. + * + * @version $Rev$ $Date$ + */ +public class JavaMappedService extends ServiceDefinition { + private Class<?> serviceInterface; + private Member callbackMember; + + public JavaMappedService() { + } + + public JavaMappedService(Class<?> serviceInterface) { + this.serviceInterface = serviceInterface; + } + + public JavaMappedService(URI name, ServiceContract contract, boolean remotable) { + super(name, contract, remotable); + } + + public JavaMappedService(URI name, + ServiceContract contract, + boolean remotable, + String callbackRefName, + Member callbackMember) { + super(name, contract, remotable, callbackRefName); + this.callbackMember = callbackMember; + } + + /** + * Returns the Java interface for this service. This may be different from the interface that defines the service + * contract. + * + * @return the Java interface for this service + */ + public Class<?> getServiceInterface() { + return serviceInterface; + } + + /** + * Sets the Java interface for this service. This may be different from the interface used to define the service + * contract. + * + * @param serviceInterface the Java interface for this service + */ + public void setServiceInterface(Class<?> serviceInterface) { + this.serviceInterface = serviceInterface; + } + + public Member getCallbackMember() { + return callbackMember; + } + + public void setCallbackMember(Member callbackMember) { + this.callbackMember = callbackMember; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java new file mode 100644 index 0000000000..795e37e288 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.spi.model.ComponentType; +import org.apache.tuscany.spi.model.Property; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ServiceDefinition; + +/** + * A component type specialization for POJO implementations + * + * @version $$Rev$$ $$Date$$ + */ +public class PojoComponentType<S extends ServiceDefinition, R extends ReferenceDefinition, P extends Property<?>> + extends ComponentType<S, R, P> { + private Class<?> implClass; + private ConstructorDefinition<?> constructorDefinition; + private Method initMethod; + private Method destroyMethod; + private final Map<String, Resource> resources = new HashMap<String, Resource>(); + private Member conversationIDMember; + + /** + * Deprecated no-arg constructor, replaced with one that takes the POJO class. + */ + @Deprecated + public PojoComponentType() { + } + + /** + * Constructor specifying the java class for the POJO this is describing. + * + * @param implClass the java class for the POJO this is describing + */ + public PojoComponentType(Class<?> implClass) { + this.implClass = implClass; + } + + /** + * Returns the java class for the POJO this is describing. + * + * @return the java class for the POJO this is describing + */ + public Class<?> getImplClass() { + return implClass; + } + + /** + * Sets the java class for the POJO this is describing. + * + * @param implClass the java class for the POJO this is describing + */ + public void setImplClass(Class<?> implClass) { + this.implClass = implClass; + } + + /** + * Returns the constructor used to instantiate implementation instances. + * + * @return the constructor used to instantiate implementation instances + */ + public ConstructorDefinition<?> getConstructorDefinition() { + return constructorDefinition; + } + + /** + * Sets the constructor used to instantiate implementation instances + * + * @param definition the constructor used to instantiate implementation instances + */ + public void setConstructorDefinition(ConstructorDefinition<?> definition) { + this.constructorDefinition = definition; + } + + /** + * Returns the component initializer method. + * + * @return the component initializer method + */ + public Method getInitMethod() { + return initMethod; + } + + /** + * Sets the component initializer method. + * + * @param initMethod the component initializer method + */ + public void setInitMethod(Method initMethod) { + this.initMethod = initMethod; + } + + /** + * Returns the component destructor method. + * + * @return the component destructor method + */ + public Method getDestroyMethod() { + return destroyMethod; + } + + /** + * Sets the component destructor method. + * + * @param destroyMethod the component destructor method + */ + public void setDestroyMethod(Method destroyMethod) { + this.destroyMethod = destroyMethod; + } + + public Map<String, Resource> getResources() { + return resources; + } + + public void add(Resource resource) { + resources.put(resource.getName(), resource); + } + + public Member getConversationIDMember() { + return this.conversationIDMember; + } + + public void setConversationIDMember(Member conversationIDMember) { + this.conversationIDMember = conversationIDMember; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ProcessingException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ProcessingException.java new file mode 100644 index 0000000000..40fd1dfd15 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ProcessingException.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.reflect.Member; + +import org.apache.tuscany.spi.loader.LoaderException; + +/** + * Denotes a problem processing annotations on a POJO implementation + * + * @version $Rev$ $Date$ + */ +public class ProcessingException extends LoaderException { + private Member member; + + public ProcessingException() { + } + + public ProcessingException(String message) { + super(message); + } + + public ProcessingException(String message, String identifier) { + super(message, identifier); + } + + public ProcessingException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public ProcessingException(String message, Throwable cause) { + super(message, cause); + } + + public ProcessingException(Throwable cause) { + super(cause); + } + + + public Member getMemberName() { + return member; + } + + public void setMember(Member member) { + this.member = member; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java new file mode 100644 index 0000000000..61e2970bec --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.reflect.Member; + +import org.apache.tuscany.spi.ObjectFactory; + +/** + * A resource dependency declared by a Java component implementation + * + * @version $Rev$ $Date$ + * @param <T> the Java type of the resource + */ +public class Resource<T> { + + private String name; + private String mappedName; + private boolean optional; + private Member member; + private Class<T> type; + private ObjectFactory<T> objectFactory; + + public Resource(String name, Class<T> type, Member member) { + this.name = name; + this.type = type; + this.member = member; + } + + /** + * The name of the resource + * + * @return the name of the resource + */ + public String getName() { + return name; + } + + /** + * Sets the name of the resource + * + * @param name the name of the resource + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns the URI of the resource + * + * @return the URI of the resource + */ + public String getMappedName() { + return mappedName; + } + + /** + * Sets the resource URI + */ + public void setMappedName(String mappedName) { + this.mappedName = mappedName; + } + + /** + * If true, the resource is optional + * + * @return true if the resource is optional + */ + public boolean isOptional() { + return optional; + } + + /** + * Sets whether the resource is optional + */ + public void setOptional(boolean optional) { + this.optional = optional; + } + + /** + * Returns the Member that this resource is mapped to. + * + * @return the Member that this resource is mapped to + */ + public Member getMember() { + return member; + } + + /** + * Sets the Member that this resource is mapped to + * + * @param member the Member that this resource is mapped to + */ + public void setMember(Member member) { + this.member = member; + } + + /** + * Returns the resource type + * + * @return the resource type + */ + public Class<T> getType() { + return type; + } + + /** + * Sets the resource type + */ + public void setType(Class<T> type) { + this.type = type; + } + + /** + * Returns the obeject factory + * + * @return the object factory + */ + public ObjectFactory<T> getObjectFactory() { + return objectFactory; + } + + /** + * Sets the object factory + */ + public void setObjectFactory(ObjectFactory<T> objectFactory) { + this.objectFactory = objectFactory; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ComponentTypeLoader.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ComponentTypeLoader.java new file mode 100644 index 0000000000..f83b2fc5b3 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ComponentTypeLoader.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.model.Implementation; + +/** + * Loader that will load the ComponentType definition for the supplied implementation. The actual mechanism used to load + * that definition is determined by the Client and Implementation Specification for the implementaion type. In some + * cases the definition may be contained in a XML file related to the implementation artifact in some well defined + * manner; other implementations may obtain this information from introspection of the artifact itself (for example, by + * examining Java annotations). + * + * @version $Rev$ $Date$ + */ +public interface ComponentTypeLoader<I extends Implementation> { + /** + * Load the component type definition for the supplied implementation. + * + * @param implementation the implementation whose component type information should be loaded + * @param context the current deployment context + * @throws LoaderException if there was a problem loading the configuration type + */ + void load(I implementation, DeploymentContext context) throws LoaderException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/IllegalSCDLNameException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/IllegalSCDLNameException.java new file mode 100644 index 0000000000..7c944c6251 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/IllegalSCDLNameException.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * @version $Rev$ $Date$ + */ +public class IllegalSCDLNameException extends LoaderException { + public IllegalSCDLNameException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidConfigurationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidConfigurationException.java new file mode 100644 index 0000000000..1c7f3e073d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidConfigurationException.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * Denotes an invalid configuration artifact + * + * @version $Rev$ $Date$ + */ +public class InvalidConfigurationException extends LoaderException { + + public InvalidConfigurationException(String message) { + super(message); + } + + public InvalidConfigurationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidReferenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidReferenceException.java new file mode 100644 index 0000000000..b2a5a26fec --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidReferenceException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * @version $Rev$ $Date$ + */ +public class InvalidReferenceException extends LoaderException { + private static final long serialVersionUID = -4346666572527197558L; + + public InvalidReferenceException(String message) { + super(message); + } + + public InvalidReferenceException(String message, String identifier) { + super(message, identifier); + } + + public InvalidReferenceException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public InvalidReferenceException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidServiceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidServiceException.java new file mode 100644 index 0000000000..1717cae0c3 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidServiceException.java @@ -0,0 +1,30 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.loader;
+
+/**
+ * @version $Rev: 430937 $ $Date: 2006-08-12 06:47:56 +0530 (Sat, 12 Aug 2006) $
+ */
+public class InvalidServiceException extends LoaderException {
+
+ public InvalidServiceException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidValueException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidValueException.java new file mode 100644 index 0000000000..b0ad8594ca --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidValueException.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * Exception that indicates the loader encountered an invalid value. + * The message should be set to the invalid value. + * + * @version $Rev$ $Date$ + */ +public class InvalidValueException extends LoaderException { + + public InvalidValueException(String message) { + super(message); + } + + public InvalidValueException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidValueException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidWireException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidWireException.java new file mode 100644 index 0000000000..b26c81168f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidWireException.java @@ -0,0 +1,45 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.loader;
+
+/**
+ * @version $Rev: 430937 $ $Date: 2006-08-12 06:47:56 +0530 (Sat, 12 Aug 2006) $
+ */
+public class InvalidWireException extends LoaderException {
+
+ public InvalidWireException() {
+ }
+
+ public InvalidWireException(String message) {
+ super(message);
+ }
+
+
+ public InvalidWireException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public InvalidWireException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidWireException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/Loader.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/Loader.java new file mode 100644 index 0000000000..14e5a0ec57 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/Loader.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +import java.net.URL; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.model.ModelObject; + +/** + * System service for loading physical artifacts that represent SCDL configurations and creating the model objects that + * represent them. + * + * @version $Rev$ $Date$ + */ +public interface Loader { + /** + * Parse the supplied XML stream, dispatching to the appropriate registered loader for each element encountered in + * the stream. + * <p/> + * This method must be called with the XML cursor positioned on a START_ELEMENT event. When this method returns, the + * stream will be positioned on the corresponding END_ELEMENT event. + * + * @param object the model object to load configuration data into. If null, the loader dispatched to is + * responsible for creating a model object itself + * @param reader the XML stream to parse + * @param deploymentContext the current deployment context + * @return the model object obtained by parsing the current element on the stream + * @throws LoaderException if there was a problem loading the document + * @throws XMLStreamException if there was a problem reading the stream + */ + ModelObject load(ModelObject object, XMLStreamReader reader, DeploymentContext deploymentContext) + throws XMLStreamException, LoaderException; + + /** + * Load a model object from a specified location. + * + * @param object the model object to load configuration data into. If null, the loader dispatched to is responsible + * for creating a model object itself + * @param url the location of an XML document to be loaded + * @param type the type of ModelObject that is expected to be in the document + * @param context the current deployment context + * @return the model ojbect loaded from the document + * @throws LoaderException if there was a problem loading the document + */ + <MO extends ModelObject> MO load(ModelObject object, URL url, Class<MO> type, DeploymentContext context) + throws LoaderException; + + /** + * Load the component type definition for a given implementation. How the component type information is located is + * defined by the implementation specification. It may include loading from an XML sidefile, introspection of some + * artifact related to the implementation, some combination of those techniques or any other implementation-defined + * mechanism. + * + * @param implementation the implementation whose component type should be loaded + * @param context the current deployment context + * @throws LoaderException if there was a problem loading the component type definition + */ + <I extends Implementation<?>> void loadComponentType(I implementation, DeploymentContext context) + throws LoaderException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderException.java new file mode 100644 index 0000000000..defc6b06c9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderException.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +import org.apache.tuscany.api.TuscanyException; + +/** + * Base class for Exceptions raised during the loading process. Loader implementations should throw a subclass of this + * to indicate the actual problem. + * + * @version $Rev$ $Date$ + */ +public class LoaderException extends TuscanyException { + public static final int UNDEFINED = -1; + private static final long serialVersionUID = -7459051598906813461L; + private String resourceURI; + private int line = UNDEFINED; + private int column = UNDEFINED; + + public LoaderException() { + } + + public LoaderException(String message) { + super(message); + } + + public LoaderException(String message, String identifier) { + super(message, identifier); + } + + public LoaderException(String message, Throwable cause) { + super(message, cause); + } + + public LoaderException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public LoaderException(Throwable cause) { + super(cause); + } + + /** + * Returns the location of the resource that was being loaded. + * + * @return the location of the resource that was being loaded + */ + public String getResourceURI() { + return resourceURI; + } + + /** + * Sets the location of the resource that was being loaded. + * + * @param resourceURI the location of the resource that was being loaded + */ + public void setResourceURI(String resourceURI) { + this.resourceURI = resourceURI; + } + + public int getLine() { + return line; + } + + public void setLine(int line) { + this.line = line; + } + + public int getColumn() { + return column; + } + + public void setColumn(int column) { + this.column = column; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderRegistry.java new file mode 100644 index 0000000000..ea88b99b22 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderRegistry.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Registry for XML loaders that can parse a StAX input stream and return model objects. + * <p/> + * Loaders will typically be contributed to the system by any extension that needs to handle extension specific + * information contained in some XML configuration file. The loader can be contributed as a system component with an + * autowire reference to this builderRegistry which is used during initialization to actually register. </p> This + * builderRegistry can also be used to parse an input stream, dispatching to the appropriate loader for each element + * accepted. Loaders can call back to the builderRegistry to load sub-elements that they are not able to handle + * directly. + * + * @version $Rev$ $Date$ + */ +public interface LoaderRegistry extends Loader { + /** + * Register a loader. This operation will typically be called by a loader during its initialization. + * + * @param element the element that should be delegated to the contibuted loader + * @param loader a loader that is being contributed to the system + */ + <T extends ModelObject> void registerLoader(QName element, StAXElementLoader<T> loader); + + /** + * Unregister a loader. This will typically be called by a loader as it is being destroyed. + * + * @param element the element that was being delegated to the contibuted loader + * @param loader a loader that should no longer be used + */ + <T extends ModelObject> void unregisterLoader(QName element, StAXElementLoader<T> loader); + + /** + * Regsiter a component type loader. + * + * @param key a type of implementation this loader can load component types for + * @param loader the loader that is being contributed to the system + */ + <I extends Implementation<?>> void registerLoader(Class<I> key, ComponentTypeLoader<I> loader); + + /** + * Unregister a component type loader form the system. + * + * @param key a type of implementation whose loader should be unregistered + */ + <I extends Implementation<?>> void unregisterLoader(Class<I> key); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderUtil.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderUtil.java new file mode 100644 index 0000000000..bf48f91a74 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderUtil.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamConstants; + +/** + * Utility functions to support loader implementations. + * + * @version $Rev$ $Date$ + */ +public final class LoaderUtil { + private LoaderUtil() { + } + + /** + * Advance the stream to the next END_ELEMENT event skipping any nested content. + * + * @param reader the reader to advance + * @throws XMLStreamException if there was a problem reading the stream + */ + public static void skipToEndElement(XMLStreamReader reader) throws XMLStreamException { + int depth = 0; + while (true) { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + depth++; + } else if (event == XMLStreamConstants.END_ELEMENT) { + if (depth == 0) { + return; + } + depth--; + } + } + } + + /** + * Load the class using the supplied ClassLoader. + * The class will be defined so any initializers present will be fired. + * As the class is being loaded, the Thread context ClassLoader will be + * set to the supplied classloader. + * + * @param name the name of the class to load + * @param cl the classloader to use to load it + * @return the class + * @throws MissingResourceException if the class could not be found + */ + public static Class<?> loadClass(String name, ClassLoader cl) throws MissingResourceException { + final Thread thread = Thread.currentThread(); + final ClassLoader oldCL = thread.getContextClassLoader(); + try { + thread.setContextClassLoader(cl); + return Class.forName(name, true, cl); + } catch (ClassNotFoundException e) { + throw new MissingResourceException(name, e); + } finally { + thread.setContextClassLoader(oldCL); + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingImplementationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingImplementationException.java new file mode 100644 index 0000000000..89a44083cc --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingImplementationException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * Exception that indicates that an implementation was not provided. + * + * @version $Rev$ $Date$ + */ +public class MissingImplementationException extends LoaderException { + private static final long serialVersionUID = -2917278473974880124L; + + /** + * Default constructor. + */ + public MissingImplementationException() { + super(); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingIncludeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingIncludeException.java new file mode 100644 index 0000000000..10e40f9288 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingIncludeException.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * Exception that indicates that an include was not provided. + * + * @version $Rev$ $Date$ + */ +public class MissingIncludeException extends LoaderException { + private static final long serialVersionUID = -2917278473974880124L; + + public MissingIncludeException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingPromoteException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingPromoteException.java new file mode 100644 index 0000000000..325de281a7 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingPromoteException.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * Denotes a missing promote attribute in a SCDL configuration + * + * @version $Rev$ $Date$ + */ +public class MissingPromoteException extends LoaderException { + + public MissingPromoteException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingReferenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingReferenceException.java new file mode 100644 index 0000000000..7bc206de34 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingReferenceException.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * Indicates a required reference was not configured + * + * @version $Rev$ $Date$ + */ +public class MissingReferenceException extends LoaderException { + + public MissingReferenceException(String message) { + super(message); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingRequiredPropertyException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingRequiredPropertyException.java new file mode 100644 index 0000000000..30955bb4e5 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingRequiredPropertyException.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * @version $Rev$ $Date$ + */ +public class MissingRequiredPropertyException extends LoaderException { + + public MissingRequiredPropertyException(String name) { + super(name); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingResourceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingResourceException.java new file mode 100644 index 0000000000..3b6a21aa74 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingResourceException.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 org.apache.tuscany.spi.loader; + +/** + * Exception that indicates an expected resource could not be found. The message should be set to the name of the + * resource. + * + * @version $Rev$ $Date$ + */ +public class MissingResourceException extends LoaderException { + private static final long serialVersionUID = 3775013318397916445L; + + /** + * Constructor that indicates which resource could not be found. The supplied parameter is also returned as the + * message. + * + * @param resource the resource that could not be found + */ + public MissingResourceException(String resource) { + super("Missing resource", resource); + } + + public MissingResourceException(String message, String identifier) { + super(message, identifier); + } + + /** + * Constructor that indicates which resource could not be found. The supplied parameter is also returned as the + * message. + * + * @param resource the resource that could not be found + * @param cause the error thrown resolving the resource + */ + public MissingResourceException(String resource, Throwable cause) { + super("Missing resource", resource, cause); + } + + + /** + * Constructor that indicates which resource could not be found. The supplied parameter is also returned as the + * message. + * + * @param message the message set on the exception + * @param identifier the resource that could not be found + * @param cause the error thrown resolving the resource + */ + public MissingResourceException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/PropertyObjectFactory.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/PropertyObjectFactory.java new file mode 100644 index 0000000000..8b569d76fb --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/PropertyObjectFactory.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +import org.apache.tuscany.spi.ObjectFactory; +import org.apache.tuscany.spi.model.Property; +import org.apache.tuscany.spi.model.PropertyValue; + +/** + * A factory that will create an ObjectFactory for a property + * + * @version $Rev$ $Date$ + */ +public interface PropertyObjectFactory { + /** + * Return an ObjectFactory for instances of a property defined in an XML. The ObjectFactory must return instances + * that can safely be supplied to component implementations. If the instance is mutable and isolation between + * components is required, then the factory must clone or otherwise protect the implementation from unexpected + * modifications by other implementation instances. + * + * @param property the Property definition that the resulting ObjectFactory must be able to assign to + * @param propertyValue The component configuration of the property + * @return an ObjectFactory that can produce instances that can be assigned to the supplied Property + * @throws LoaderException if there is a problem creating the ObjectFactory + */ + <T> ObjectFactory<T> createObjectFactory(Property<T> property, PropertyValue<T> propertyValue) + throws LoaderException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ReferenceMultiplicityViolationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ReferenceMultiplicityViolationException.java new file mode 100644 index 0000000000..ce9acb8750 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ReferenceMultiplicityViolationException.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 org.apache.tuscany.spi.loader; + +import org.apache.tuscany.spi.model.Multiplicity; + +/** + * Denote the violation of multiplicity declaration for a reference + * + * @version $Rev $Date + */ +public class ReferenceMultiplicityViolationException extends LoaderException { + private static final long serialVersionUID = -4049116356211578827L; + + private final Multiplicity multiplicity; + private final int numberOfTargets; + + /** + * @param message + * @param identifier + * @param multiplicity + * @param numberOfTargets + */ + public ReferenceMultiplicityViolationException(String message, + String identifier, + Multiplicity multiplicity, + int numberOfTargets) { + super(message, identifier); + this.multiplicity = multiplicity; + this.numberOfTargets = numberOfTargets; + } + + /** + * @param identifier + * @param multiplicity + * @param numberOfTargets + */ + public ReferenceMultiplicityViolationException(String identifier, Multiplicity multiplicity, int numberOfTargets) { + this("Multiplicity is violated", identifier, multiplicity, numberOfTargets); + } + + /** + * Get the multiplicity for the reference definition + * + * @return multiplicity of the reference definition + */ + public Multiplicity getMultiplicity() { + return multiplicity; + } + + /** + * Get the number of targets defined for this reference + * @return number of targets for this reference + */ + public int getNumberOfTargets() { + return numberOfTargets; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/StAXElementLoader.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/StAXElementLoader.java new file mode 100644 index 0000000000..9f0ad909f9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/StAXElementLoader.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.model.ModelObject; + +/** + * A loader that creates a model object from a StAX input stream. + * + * @version $Rev$ $Date$ + */ +public interface StAXElementLoader<T extends ModelObject> { + /** + * Create the model object for an element in an XML stream. When this method returns the stream will be positioned + * on the corresponding END_ELEMENT. + * + * @param object the model object to load configuration data into. An implementation may choose to return a + * different model object than the one passed in, in which case it is responsible for copying data. + * If null, the loader is responsible for creating a model object itself + * @param reader the XML stream reader positioned on the applicable START_ELEMENT + * @param context the context for the load operation + * @return the model object for that element + */ + T load(ModelObject object, XMLStreamReader reader, DeploymentContext context) + throws XMLStreamException, LoaderException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedPropertyException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedPropertyException.java new file mode 100644 index 0000000000..bf3aa205d2 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedPropertyException.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * @version $Rev$ $Date$ + */ +public class UndefinedPropertyException extends LoaderException { + public UndefinedPropertyException(String name) { + super("Property not found on implementation", name); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedReferenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedReferenceException.java new file mode 100644 index 0000000000..f9aa8812ac --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedReferenceException.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * @version $Rev$ $Date$ + */ +public class UndefinedReferenceException extends LoaderException { + private static final long serialVersionUID = -2897448857974015706L; + + public UndefinedReferenceException(String name) { + super("Reference not found on implementation", name); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedComponentTypeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedComponentTypeException.java new file mode 100644 index 0000000000..750762d839 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedComponentTypeException.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +/** + * Exception that indicates an component type was encountered that could not be handled. + * + * @version $Rev$ $Date$ + */ +public class UnrecognizedComponentTypeException extends LoaderException { + private final Class<?> type; + + /** + * Constructor that indicates which component type loader could not be found. + * + * @param type the component type type that could not be handled + */ + public UnrecognizedComponentTypeException(Class<?> type) { + super("Unrecognized element", type.getName()); + this.type = type; + } + + public Class<?> getType() { + return type; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedElementException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedElementException.java new file mode 100644 index 0000000000..7991105da8 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedElementException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +import javax.xml.namespace.QName; + +/** + * Exception that indicates an element was encountered that could not be handled. + * + * @version $Rev$ $Date$ + */ +public class UnrecognizedElementException extends LoaderException { + private static final long serialVersionUID = 2549543622209829032L; + private final QName element; + + /** + * Constructor that indicates which resource could not be found. The supplied parameter is also returned as the + * message. + * + * @param element the element that could not be handled + */ + public UnrecognizedElementException(QName element) { + super("Unrecognized element", element.toString()); + this.element = element; + } + + public QName getElement() { + return element; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/MarshalException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/MarshalException.java new file mode 100644 index 0000000000..0cdf5d399a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/MarshalException.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.marshaller; + +import org.apache.tuscany.api.TuscanyException; + +/** + * Super class for all marshalling/unmarshalling exceptions. + * + * @version $Rev$ $Date$ + */ +@SuppressWarnings("serial") +public class MarshalException extends TuscanyException { + + /** + * Initializes the exception message. + * + * @param message Message for the exception. + */ + public MarshalException(String message) { + super(message); + } + + /** + * Initializes the root cause. + * + * @param cause Root cause for the exception. + */ + public MarshalException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshaller.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshaller.java new file mode 100644 index 0000000000..4827112c94 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshaller.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.marshaller; + +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Interface for marshalling/unmarshalling internal physical component definitions. + * + * @version $Rev$ $Date$ + * + */ +public interface ModelMarshaller<MD extends ModelObject> { + + /** + * Marshalls the physical component definition to the specified stream writer. + * + * @param modelObject Physical component definition to be serialized. + * @param writer Stream writer to which the infoset is serialized. + * @throws MarshalException In case of any marshalling error. + */ + void marshal(MD modelObject, XMLStreamWriter writer) throws MarshalException; + + /** + * Unmarshalls an XML stream to a model object. + * + * @param reader XML stream from where the marshalled XML is read. + * @return Physical component definition. + * @throws MarshalException In case of any unmarshalling error. + */ + MD unmarshal(XMLStreamReader reader) throws MarshalException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java new file mode 100644 index 0000000000..9174884c30 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.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 org.apache.tuscany.spi.marshaller; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * A registry for model object marshallers. + * + * @version $Rev$ $Date$ + */ +public interface ModelMarshallerRegistry { + + /** + * Registers a model object marshaller. + * + * @param <MD> Model object type. + * @param modelClass Model obejct class. + * @param qname Qualified name of the root element of the marshalled XML. + * @param marshaller Model object marshaller. + */ + <MD extends ModelObject> void registerMarshaller(Class<MD> modelClass, QName qname, ModelMarshaller<MD> marshaller); + + /** + * Marshalls a model object. + * + * @param modelObject Model object to be marshalled. + * @param writer Writer to which marshalled information is written. + */ + void marshall(ModelObject modelObject, XMLStreamWriter writer) throws MarshalException; + + /** + * Unmarshalls an XML stream to a model object. + * + * @param reader Reader from which marshalled information is read. + * @return Model object from the marshalled stream. + */ + ModelObject unmarshall(XMLStreamReader reader) throws MarshalException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/AtomicImplementation.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/AtomicImplementation.java new file mode 100644 index 0000000000..8e12e970ae --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/AtomicImplementation.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +/** + * The base representation of an atomic component implementation + * + * @version $Rev$ $Date$ + */ +public abstract class AtomicImplementation<T extends ComponentType> extends Implementation<T> { + protected AtomicImplementation() { + } + + protected AtomicImplementation(T componentType) { + super(componentType); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/BindingDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/BindingDefinition.java new file mode 100644 index 0000000000..4b17181442 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/BindingDefinition.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.net.URI; + +/** + * The base representation of a binding specified in an assembly + * + * @version $Rev$ $Date$ + */ +public abstract class BindingDefinition extends ModelObject { + private URI targetUri; + + protected BindingDefinition() { + } + + public BindingDefinition(URI targetUri) { + this.targetUri = targetUri; + } + + public URI getTargetUri() { + return targetUri; + } + + public void setTargetUri(URI targetUri) { + this.targetUri = targetUri; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentDefinition.java new file mode 100644 index 0000000000..233376a645 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentDefinition.java @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +/** + * Represents a component. <p>A component is a configured instance of an implementation. The services provided and + * consumed and the available configuration properties are defined by the implementation (represented by its + * componentType).</p> <p>Every component has a name which uniquely identifies it within the scope of the composite that + * contains it; the name must be different from the names of all other components, services and references immediately + * contained in the composite (directly or through an <include> element).</p> <p>A component may define a {@link + * PropertyValue} that overrides the default value of a {@link Property} defined in the componentType.</p> <p>It may + * also define a {@link ReferenceTarget} for a {@link ReferenceDefinition} defined in the componentType. The + * ReferenceTarget must resolve to another component or a reference in the enclosing composite.</p> <p>Components may + * specify an initialization level that will determine the order in which it will be eagerly initialized relative to + * other components from the enclosing composite that are in the same scope. This can be used to define a startup + * sequence for components that are otherwise independent. Any initialization required to resolve references between + * components will override this initialization order.</p> + * + * @version $Rev$ $Date$ + */ +public class ComponentDefinition<I extends Implementation<?>> extends ModelObject { + private URI uri; + private URI runtimeId; + private boolean autowire; + private Integer initLevel; + private final I implementation; + private final Map<String, ReferenceTarget> referenceTargets = new HashMap<String, ReferenceTarget>(); + private final Map<String, PropertyValue<?>> propertyValues = new HashMap<String, PropertyValue<?>>(); + + /** + * Constructor specifying the component's name and implementation. + * + * @param uri the name of this component + * @param implementation the implementation of this component + */ + public ComponentDefinition(URI uri, I implementation) { + this.uri = uri; + this.implementation = implementation; + } + + /** + * Constructor specifying the implementation of this component. + * + * @param implementation the implementation of this component + */ + public ComponentDefinition(I implementation) { + this.implementation = implementation; + } + + /** + * Returns the {@link Implementation} of this component. + * + * @return the implementation of this component + */ + public I getImplementation() { + return implementation; + } + + /** + * Returns the name of this component. + * + * @return the name of this component + */ + public URI getUri() { + return uri; + } + + /** + * Sets the name of this component. + * + * @param uri the name of this component + */ + public void setUri(URI uri) { + this.uri = uri; + } + + /** + * Returns the id of the node the component is to be provisioned to. + * + * @return the id of the node the component is to be provisioned to + */ + public URI getRuntimeId() { + return runtimeId; + } + + /** + * Sets the id of the node the component is to be provisioned to. + * + * @param id the id of the node the component is to be provisioned to + */ + public void setRuntimeId(URI id) { + this.runtimeId = id; + } + + /** + * Returns true if autowire is enabled for the component. + * + * @return true if autowire is enabled for the component. + */ + public boolean getAutowire() { + return autowire; + } + + /** + * Sets autowire enablement for the component. + * + * @param autowire true if autowire is enabled. + */ + public void setAutowire(boolean autowire) { + this.autowire = autowire; + } + + /** + * Returns the initialization level of this component. + * + * @return the initialization level of this component + */ + public Integer getInitLevel() { + return initLevel; + } + + /** + * Sets the initialization level of this component. If set to null then the level from the componentType is used. If + * set to zero or a negative value then the component will not be eagerly initialized. + * + * @param initLevel the initialization level of this component + */ + public void setInitLevel(Integer initLevel) { + this.initLevel = initLevel; + } + + /** + * Returns a live Map of the {@link ReferenceTarget targets} configured by this component definition. + * + * @return the reference targets configured by this component + */ + public Map<String, ReferenceTarget> getReferenceTargets() { + return referenceTargets; + } + + /** + * Add a reference target configuration to this component. Any existing configuration for the reference named in the + * target is replaced. + * + * @param target the target to add + */ + public void add(ReferenceTarget target) { + referenceTargets.put(target.getReferenceName().getFragment(), target); + } + + /** + * Returns a live Map of {@link PropertyValue property values} configured by this component definition. + * + * @return the property values configured by this component + */ + public Map<String, PropertyValue<?>> getPropertyValues() { + return propertyValues; + } + + /** + * Add a property value configuration to this component. Any existing configuration for the property names in the + * property value is replaced. + * + * @param value the property value to add + */ + public void add(PropertyValue<?> value) { + propertyValues.put(value.getName(), value); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentType.java new file mode 100644 index 0000000000..b4e2db485e --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentType.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.HashMap; +import java.util.Map; + +/** + * <p>The definition of the configurable aspects of an implementation in terms of the services it exposes, the services + * it references, and properties that can be used to configure it.</p> <p>A service represents an addressable interface + * provided by the implementation. Such a service may be the target of a wire from another component.</p> <p>A reference + * represents a requirement that an implementation has on a service provided by another component or by a resource + * outside the SCA system. Such a reference may be the source of a wire to another component.</p> <p>A property allows + * the behaviour of the implementation to be configured through externally set values.</p> <p>A component type may also + * declare that it wishes to be initialized upon activation of the scope that contains it and may specify an order + * relative to other eagerly initializing components. For example, an implementation that pre-loads some form of cache + * could declare that it should be eagerly initialized at the start of the scope so that the cache load occured on + * startup rather than first use.</p> + * + * @version $Rev$ $Date$ + */ +public class ComponentType<S extends ServiceDefinition, R extends ReferenceDefinition, P extends Property<?>> + extends ModelObject { + protected Scope implementationScope = Scope.UNDEFINED; + private int initLevel; + private long maxAge = -1; + private long maxIdleTime = -1; + private final Map<String, S> services = new HashMap<String, S>(); + private final Map<String, R> references = new HashMap<String, R>(); + private final Map<String, P> properties = new HashMap<String, P>(); + + /** + * Returns the component implementation scope + */ + public Scope getImplementationScope() { + return implementationScope; + } + + /** + * Sets the component implementation scope + */ + public void setImplementationScope(Scope implementationScope) { + this.implementationScope = implementationScope; + } + + /** + * Returns the default initialization level for components of this type. A value greater than zero indicates that + * components should be eagerly initialized. + * + * @return the default initialization level + */ + public int getInitLevel() { + return initLevel; + } + + /** + * Sets the default initialization level for components of this type. A value greater than zero indicates that + * components should be eagerly initialized. + * + * @param initLevel default initialization level for components of this type + */ + public void setInitLevel(int initLevel) { + this.initLevel = initLevel; + } + + /** + * Returns true if this component should be eagerly initialized. + * + * @return true if this component should be eagerly initialized + */ + public boolean isEagerInit() { + return initLevel > 0; + } + + /** + * Returns the idle time allowed between operations in milliseconds if the implementation is conversational + * + * @return the idle time allowed between operations in milliseconds if the implementation is conversational + */ + public long getMaxIdleTime() { + return maxIdleTime; + } + + /** + * Sets the idle time allowed between operations in milliseconds if the implementation is conversational + */ + public void setMaxIdleTime(long maxIdleTime) { + this.maxIdleTime = maxIdleTime; + } + + /** + * Returns the maximum age a conversation may remain active in milliseconds if the implementation is conversational + * + * @return the maximum age a conversation may remain active in milliseconds if the implementation is conversational + */ + public long getMaxAge() { + return maxAge; + } + + /** + * Sets the maximum age a conversation may remain active in milliseconds if the implementation is conversational + */ + public void setMaxAge(long maxAge) { + this.maxAge = maxAge; + } + + /** + * Returns a live Map of the services provided by the implementation. + * + * @return a live Map of the services provided by the implementation + */ + public Map<String, S> getServices() { + return services; + } + + /** + * Add a service to those provided by the implementation. Any existing service with the same name is replaced. + * + * @param service a service provided by the implementation + */ + public void add(S service) { + services.put(service.getUri().getFragment(), service); + } + + /** + * Returns a live Map of references to services consumed by the implementation. + * + * @return a live Map of references to services consumed by the implementation + */ + public Map<String, R> getReferences() { + return references; + } + + /** + * Add a reference to a service consumed by the implementation. Any existing reference with the same name is + * replaced. + * + * @param reference a reference to a service consumed by the implementation + */ + public void add(R reference) { + references.put(reference.getUri().getFragment(), reference); + } + + /** + * Returns a live Map of properties that can be used to configure the implementation. + * + * @return a live Map of properties that can be used to configure the implementation + */ + public Map<String, P> getProperties() { + return properties; + } + + /** + * Add a property that can be used to configure the implementation. Any existing property with the same name is + * replaced. + * + * @param property a property that can be used to configure the implementation + */ + public void add(P property) { + properties.put(property.getName(), property); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeComponentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeComponentType.java new file mode 100644 index 0000000000..464b5758b7 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeComponentType.java @@ -0,0 +1,236 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.util.UriHelper; + +/** + * A specialization of component type for composite components. + * + * @version $Rev$ $Date$ + */ +public class CompositeComponentType<S extends ServiceDefinition, + R extends ReferenceDefinition, + P extends Property<?>> extends ComponentType<S, R, P> { + + private QName name; + private boolean autowire; + private final Map<String, ComponentDefinition<? extends Implementation<?>>> components = + new HashMap<String, ComponentDefinition<? extends Implementation<?>>>(); + private final Map<String, Include> includes = new HashMap<String, Include>(); + private final List<WireDefinition> wires = new ArrayList<WireDefinition>(); + + public CompositeComponentType() { + implementationScope = Scope.SYSTEM; + } + + /** + * Constructor defining the composite name. + * + * @param name the qualified name of this composite + */ + public CompositeComponentType(QName name) { + this(); + this.name = name; + } + + /** + * Returns the qualified name of this composite. + * The namespace portion of this name is the targetNamespace for other qualified names used in the composite. + * + * @return the qualified name of this composite + */ + public QName getName() { + return name; + } + + /** + * Set the qualified name of this composite. + * + * @param name the qualified name of this composite + */ + public void setName(QName name) { + this.name = name; + } + + /** + * Returns if autowire is set of for composite + * + * @return true if autowire is set for the composite + */ + public boolean isAutowire() { + return autowire; + } + + /** + * Sets autowire for the composite + * + * @param autowire true if autowire is enabled for the composite + */ + public void setAutowire(boolean autowire) { + this.autowire = autowire; + } + + @Override + @SuppressWarnings("unchecked") + /** + * Get all properties including the ones are from included composites + * @return + */ + public Map<String, P> getProperties() { + Map<String, P> view = new HashMap<String, P>(super.getProperties()); + for (Include i : includes.values()) { + view.putAll(i.getIncluded().getProperties()); + } + return Collections.unmodifiableMap(view); + } + + @Override + @SuppressWarnings("unchecked") + /** + * Get all references including the ones are from included composites + * @return + */ + public Map<String, R> getReferences() { + Map<String, R> view = new HashMap<String, R>(super.getReferences()); + for (Include i : includes.values()) { + view.putAll(i.getIncluded().getReferences()); + } + return Collections.unmodifiableMap(view); + } + + @SuppressWarnings("unchecked") + @Override + /** + * Get all services including the ones are from included composites + * @return + */ + public Map<String, S> getServices() { + Map<String, S> view = new HashMap<String, S>(super.getServices()); + for (Include i : includes.values()) { + view.putAll(i.getIncluded().getServices()); + } + return Collections.unmodifiableMap(view); + } + + /** + * Get all components including the ones are from included composites + */ + @SuppressWarnings("unchecked") + public Map<String, ComponentDefinition<? extends Implementation<?>>> getComponents() { + Map<String, ComponentDefinition<? extends Implementation<?>>> view = + new HashMap<String, ComponentDefinition<? extends Implementation<?>>>(components); + for (Include i : includes.values()) { + view.putAll(i.getIncluded().getComponents()); + } + return Collections.unmodifiableMap(view); + } + + + /** + * Get all wires including the ones are from included composites + */ + @SuppressWarnings("unchecked") + public List<WireDefinition> getWires() { + List<WireDefinition> view = + new ArrayList<WireDefinition>(wires); + for (Include i : includes.values()) { + view.addAll(i.getIncluded().getWires()); + } + return Collections.unmodifiableList(view); + } + + /** + * Get declared properties in this composite type, included doesn't count + */ + public Map<String, P> getDeclaredProperties() { + return super.getProperties(); + } + + /** + * Get declared references in this composite type, included doesn't count + */ + public Map<String, R> getDeclaredReferences() { + return super.getReferences(); + } + + /** + * Get declared services in this composite type, included doesn't count + */ + public Map<String, S> getDeclaredServices() { + return super.getServices(); + } + + /** + * Get declared components in this composite type, included doesn't count + */ + public Map<String, ComponentDefinition<? extends Implementation<?>>> getDeclaredComponents() { + return components; + } + + /** + * Get declared wires in this composite type, included doesn't count + */ + public List<WireDefinition> getDeclaredWires() { + return wires; + } + + public void add(WireDefinition wireDefn) { + wires.add(wireDefn); + } + + + public void add(ComponentDefinition<? extends Implementation<?>> componentDefinition) { + components.put(UriHelper.getBaseName(componentDefinition.getUri()), componentDefinition); + } + + public Map<String, Include> getIncludes() { + return includes; + } + + public void add(Include include) { + includes.put(include.getName(), include); + } + + + public int hashCode() { + return name.hashCode(); + } + + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + CompositeComponentType that = (CompositeComponentType) o; + return name.equals(that.name); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeImplementation.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeImplementation.java new file mode 100644 index 0000000000..6948c52286 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeImplementation.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.net.URL; + +/** + * A specialization of an implementation associated with composite components + * + * @version $Rev$ $Date$ + */ +public class CompositeImplementation extends Implementation<CompositeComponentType> { + private String name; + private URL scdlLocation; + private ClassLoader classLoader; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public URL getScdlLocation() { + return scdlLocation; + } + + public void setScdlLocation(URL scdlLocation) { + this.scdlLocation = scdlLocation; + } + + public ClassLoader getClassLoader() { + return classLoader; + } + + public void setClassLoader(ClassLoader classLoader) { + this.classLoader = classLoader; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Contribution.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Contribution.java new file mode 100644 index 0000000000..374f441ea3 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Contribution.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.model; + +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +/** + * The representation of a deployed contribution + * + * @version $Rev$ $Date$ + */ +public class Contribution extends DeployedArtifact { + public static final String SCA_CONTRIBUTION_META = "META-INF/sca-contribution.xml"; + public static final String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml"; + + protected List<String> exports = new ArrayList<String>(); + protected List<ContributionImport> imports = new ArrayList<ContributionImport>(); + protected List<QName> deployables = new ArrayList<QName>(); + + /** + * A list of artifacts in the contribution + */ + protected Map<URI, DeployedArtifact> artifacts = new HashMap<URI, DeployedArtifact>(); + + public Contribution() { + super(); + } + + /** + * @param uri + */ + public Contribution(URI uri) { + super(uri); + if (uri != null) { + artifacts.put(uri, this); + } + } + + public URI getUri() { + return uri; + } + + public void setURI(URI uri) { + super.setUri(uri); + if (uri != null) { + artifacts.put(uri, this); + } + } + + public List<String> getExports() { + return exports; + } + + public List<ContributionImport> getImports() { + return imports; + } + + public List<QName> getDeployables() { + return deployables; + } + + public Map<URI, DeployedArtifact> getArtifacts() { + return Collections.unmodifiableMap(artifacts); + } + + public void addArtifact(DeployedArtifact artifact) { + artifact.setContribution(this); + artifacts.put(artifact.getUri(), artifact); + } + + public DeployedArtifact getArtifact(URI uri) { + return artifacts.get(uri); + } + + /** + * @return the location + */ + public URL getLocation() { + return location; + } + + /** + * @param location the location to set + */ + public void setLocation(URL location) { + this.location = location; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ContributionImport.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ContributionImport.java new file mode 100644 index 0000000000..a678adbdc8 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ContributionImport.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 org.apache.tuscany.spi.model; + +import java.net.URI; + +/** + * The representation of an import for the contribution + * + * @version $Rev$ $Date$ + */ +public class ContributionImport extends ModelObject { + private String namespace; // The namespace to be imported + private URI location; // Optional location to hint the where it should be imported + + // TODO: We might need the field to point to the imported artifact/model + + public URI getLocation() { + return location; + } + + public void setLocation(URI location) { + this.location = location; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java new file mode 100644 index 0000000000..72effb52e2 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java @@ -0,0 +1,249 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.Map; + +/** + * Representation of the type of data associated with an operation. Data is represented in two forms: the physical form + * used by the runtime and a logical form used by the assembly. The physical form is a Java Type because the runtime is + * written in Java. This may be the same form used by the application but it may not; for example, an application that + * is performing stream processing may want a physical form such as an {@link java.io.InputStream InputStream} to + * semantially operate on application data such as a purchase order. The logical description is that used by the + * assembly model and is an identifier into some well-known type space; examples may be a Java type represented by its + * Class or an XML type represented by its QName. Every data type may also contain metadata describing the expected + * data; for example, it could specify a preferred data binding technology or the size of a typical instance. + * + * @version $Rev$ $Date$ + */ +public class DataType<L> extends ModelObject implements Cloneable { + private String dataBinding; + + private final Type physical; + + private L logical; + + private Map<String, Object> metadata = new HashMap<String, Object>(); + + private Operation operation; + + /** + * Construct a data type specifying the physical and logical types. + * + * @param physical the physical class used by the runtime + * @param logical the logical type + * @see #getLogical() + */ + public DataType(Type physical, L logical) { + this.physical = physical; + this.logical = logical; + if (physical instanceof Class) { + this.dataBinding = ((Class) physical).getName(); + } + } + + public DataType(String dataBinding, Type physical, L logical) { + this.dataBinding = dataBinding; + this.physical = physical; + this.logical = logical; + } + + /** + * Returns the physical type used by the runtime. + * + * @return the physical type used by the runtime + */ + public Type getPhysical() { + return physical; + } + + /** + * Returns the logical identifier used by the assembly. The type of this value identifies the logical type system in + * use. Known values are: <ul> <li>a java.lang.reflect.Type identifies a Java type by name and ClassLoader; this + * includes Java Classes as they are specializations of Type</li> <li>a javax.xml.namespace.QName identifies an XML + * type by local name and namespace</li> </ul> + * + * @return the logical type name + */ + public L getLogical() { + return logical; + } + + /** + * Returns all metadata about this type. + * + * @return all metadata about this type + */ + public Map<String, ?> getMetadata() { + return metadata; + } + + /** + * Returns the specified metadata item or null if not present. + * + * @param name the name of the metadata item + * @return the value, or null if not present + */ + public Object getMetadata(String name) { + return metadata.get(name); + } + + /** + * Sets the specified metadata value. A null value undefines it. + * + * @param name the name of the metadata item + * @param value the value, or null to undefine + * @return the old value for the item, or null if not present + */ + public Object setMetadata(String name, Object value) { + if (value == null) { + return metadata.remove(name); + } else { + return metadata.put(name, value); + } + } + + public String getDataBinding() { + if (dataBinding == null) { + // databinding is not set at the DataType level, check the operation + Operation<?> operation = (Operation<?>) getOperation(); + if (operation != null) { + return operation.getDataBinding(); + } + } + return dataBinding; + } + + /** + * @param dataBinding the dataBinding to set + */ + public void setDataBinding(String dataBinding) { + this.dataBinding = dataBinding; + } + + public int hashCode() { + int result; + result = dataBinding != null ? dataBinding.hashCode() : 0; + result = 29 * result + (physical != null ? physical.hashCode() : 0); + result = 29 * result + (logical != null ? logical.hashCode() : 0); + // Commented the following line out since it causes infinite loop from Operation.hashCode() + // if the metadata map contains the Operation + // result = 29 * result + (metadata != null ? metadata.hashCode() : 0); + return result; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + final DataType dataType = (DataType) o; + + if (dataBinding != null ? !dataBinding.equals(dataType.dataBinding) : dataType.dataBinding != null) { + return false; + } + if (logical != null ? !logical.equals(dataType.logical) : dataType.logical != null) { + return false; + } + return !(physical != null ? !physical.equals(dataType.physical) : dataType.physical != null); + + } + +// @SuppressWarnings("unchecked") +// public boolean equals(Object o) { +// if (this == o) { +// return true; +// } +// if (o == null || getClass() != o.getClass()) { +// return false; +// } +// +// final DataType dataType = (DataType) o; +// +// if (logical instanceof Class && dataType.logical instanceof Class) { +// Class<?> logicalClass = (Class<?>) logical; +// Class<?> targetLogicalClass = (Class<?>) dataType.logical; +// if (!logicalClass.isAssignableFrom(targetLogicalClass)) { +// return false; +// } +// } else { +// if (logical != null ? !logical.equals(dataType.logical) : dataType.logical != null) { +// return false; +// } +// } +// if (physical instanceof Class && dataType.physical instanceof Class) { +// Class<?> physicalClass = (Class<?>) physical; +// Class<?> physicalTargetClass = (Class<?>) dataType.physical; +// if (dataBinding != null +// && dataType.dataBinding != null +// && dataBinding.equals(physicalClass.getName()) +// && dataType.dataBinding.equals(physicalTargetClass.getName())) { +// return physicalClass.isAssignableFrom(physicalTargetClass); +// } +// if (!physicalClass.isAssignableFrom(physicalTargetClass)) { +// return false; +// } +// return !(dataBinding != null ? !dataBinding.equals(dataType.dataBinding) : dataType.dataBinding != null); +// +// +// } +// +// if (dataBinding != null ? !dataBinding.equals(dataType.dataBinding) : dataType.dataBinding != null) { +// return false; +// } +// +// return !(physical != null ? !physical.equals(dataType.physical) : dataType.physical != null); +// } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(physical).append(" ").append(dataBinding).append(" ").append(logical); + return sb.toString(); + } + + @SuppressWarnings("unchecked") + @Override + public Object clone() throws CloneNotSupportedException { + DataType<L> copy = (DataType<L>) super.clone(); + assert this.metadata instanceof HashMap; + copy.metadata = (HashMap<String, Object>) ((HashMap) this.metadata).clone(); + return copy; + } + + public Operation getOperation() { + return operation; + } + + public void setOperation(Operation operation) { + this.operation = operation; + } + + /** + * @param logical the logical to set + */ + public void setLogical(L logical) { + this.logical = logical; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DeployedArtifact.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DeployedArtifact.java new file mode 100644 index 0000000000..60722d4ad6 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DeployedArtifact.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.model; + +import java.net.URI; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +/** + * Representation of a deployed artifact + * + * @version $Rev$ $Date$ + */ +public class DeployedArtifact extends ModelObject { + protected Contribution contribution; + protected URI uri; + protected URL location; + /** + * The map keeps all the model objects loaded/introspected from this artifact. The objects + * are keyed by the java type of the model such as javax.wsdl.ModelObject. The value is also + * a map with namespace as the key and the model object as the value. + */ + protected Map<Class, Map<String, Object>> modelObjects = new HashMap<Class, Map<String, Object>>(); + + public DeployedArtifact() { + super(); + } + /** + * @param uri the artifact uri + */ + public DeployedArtifact(URI uri) { + super(); + this.uri = uri; + } + /** + * Get the absolute URI as the unique id for the artifact + * @return + */ + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + /** + * @return the location + */ + public URL getLocation() { + return location; + } + + /** + * @param location the location to set + */ + public void setLocation(URL location) { + this.location = location; + } + + public Contribution getContribution() { + return contribution; + } + + public void setContribution(Contribution contribution) { + this.contribution = contribution; + } + public Map<Class, Map<String, Object>> getModelObjects() { + return modelObjects; + } + + public Map<String, Object> getModelObjects(Class type) { + return modelObjects.get(type); + } + + public Object getModelObject(Class type, String namespace) { + Map<String, Object> map = modelObjects.get(type); + if (map == null) { + return null; + } else { + return map.get(namespace); + } + } + + public void addModelObject(Class type, String namespace, Object modelObject) { + Map<String, Object> map = modelObjects.get(type); + if (map == null) { + map = new HashMap<String, Object>(); + modelObjects.put(type, map); + } + map.put(namespace, modelObject); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ElementInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ElementInfo.java new file mode 100644 index 0000000000..31c2f9428f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ElementInfo.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 org.apache.tuscany.spi.model; + +import javax.xml.namespace.QName; + +/** + * An abstraction of XML schema elements + */ +public class ElementInfo { + private QName name; + private TypeInfo type; + + /** + * @param name + * @param type + */ + public ElementInfo(QName name, TypeInfo type) { + super(); + this.name = name; + this.type = type; + } + + /** + * @return the name + */ + public QName getQName() { + return name; + } + + /** + * @return the type + */ + public TypeInfo getType() { + return type; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("Element: ").append(name).append(" ").append(type); + return sb.toString(); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Implementation.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Implementation.java new file mode 100644 index 0000000000..8520ab49e8 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Implementation.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +/** + * Represents a component implementation + * + * @version $Rev$ $Date$ + */ +public abstract class Implementation<T extends ComponentType> extends ModelObject { + private T componentType; + + protected Implementation() { + } + + protected Implementation(T componentType) { + this.componentType = componentType; + } + + public T getComponentType() { + return componentType; + } + + public void setComponentType(T componentType) { + this.componentType = componentType; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Include.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Include.java new file mode 100644 index 0000000000..ac320a2b5c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Include.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.net.URL; + +/** + * Model object that represents the include of a composite by value. + * + * @version $Rev$ $Date$ + */ +public class Include extends ModelObject { + private String name; + private URL scdlLocation; + private CompositeComponentType included; + + /** + * Returns the name of the composite that is being included. + * @return the name of the composite that is being included + */ + public String getName() { + return name; + } + + /** + * Sets the name of the composite that is being included. + * @param name the name of the composite that is being included + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns the location of the SCDL for composite being included. + * @return the location of the SCDL for composite being included + */ + public URL getScdlLocation() { + return scdlLocation; + } + + /** + * Sets the location of the SCDL for composite being included. + * @param scdlLocation the location of the SCDL for composite being included + */ + public void setScdlLocation(URL scdlLocation) { + this.scdlLocation = scdlLocation; + } + + /** + * Returns the composite that was included. + * @return the composite that was included + */ + public CompositeComponentType getIncluded() { + return included; + } + + /** + * Sets the composite that was included. + * @param included the composite that was included + */ + public void setIncluded(CompositeComponentType included) { + this.included = included; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java new file mode 100644 index 0000000000..9f3ee78a23 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.ArrayList; +import static java.util.Collections.unmodifiableList; +import java.util.List; +import javax.xml.namespace.QName; + +/** + * Model representation for intent. This class is used by intent loader only, other SCA model classes will not reference + * this class directly. + * + * @version $Rev$ $Date$ + */ +public class Intent { + + /** + * name of intent. + */ + protected IntentName name; + + /** + * Description for this intent + */ + protected String description; + + /** + * QNames of artifacts this intent can apply to + */ + protected List<QName> appliedArtifacts = new ArrayList<QName>(); + + /** + * intents required by this intent, only useful when this intent is a profile intent + */ + protected List<IntentName> requriedIntents = new ArrayList<IntentName>(); + + /** + * Create a policy intent. + * + * @param name name of the intent. + * @param description description of the intent. + */ + public Intent(IntentName name, String description) { + this.name = name; + this.description = description; + } + + public List<QName> getAppliedArtifacts() { + return unmodifiableList(appliedArtifacts); + } + + public String getDescription() { + return description; + } + + public IntentName getName() { + return name; + } + + public List<IntentName> getRequriedIntents() { + return unmodifiableList(requriedIntents); + } + + public void addRequriedIntents(IntentName intent) { + requriedIntents.add(intent); + } + + public void addAppliedArtifacts(QName artifactName) { + appliedArtifacts.add(artifactName); + } + + public boolean isProfileIntent() { + return !requriedIntents.isEmpty(); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentDefinition.java new file mode 100644 index 0000000000..35d55a3153 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentDefinition.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +/** + * Base model class for intent meta-data + * + * @version $Rev$ $Date$ + */ +public class IntentDefinition extends ModelObject { +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java new file mode 100644 index 0000000000..cbfba86dfe --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.ArrayList; +import java.util.Collection; +import static java.util.Collections.unmodifiableCollection; + +/** + * Represents an IntentMap within PolicySet. + * + * @version $Rev$ $Date$ + */ +public class IntentMap extends PolicyModel { + + /* Name of default intent provied by this IntentMap */ + private String defaultProvideIntent; + + /* Name of intent provided by this IntentMap */ + private Collection<String> provideIntents = new ArrayList<String>(); + + /* Qualifiers of this IntentMap */ + private Collection<Qualifier> qualifiers = new ArrayList<Qualifier>(); + + public IntentMap(String defaultProvideIntent, Collection<String> provideIntents) { + super(); + this.defaultProvideIntent = defaultProvideIntent; + this.provideIntents.addAll(provideIntents); + } + + public Collection<String> getProvideIntents() { + return unmodifiableCollection(provideIntents); + } + + public void addQualifier(Qualifier qualifier) { + qualifiers.add(qualifier); + } + + public Collection<Qualifier> getQualifiers() { + return unmodifiableCollection(qualifiers); + } + + public String getDefaultProvideIntent() { + return defaultProvideIntent; + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java new file mode 100644 index 0000000000..eb69b44b37 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.Arrays; + +/** + * Model class represents a name of a intent. An intent name has a domain name and one or more qualified names. For + * example, in "sec.confidentiality/message/body", the domain name is sec, and the qualified names are confidentiality, + * message and body + */ +@SuppressWarnings({"SerializableHasSerializationMethods"}) +public class IntentName implements java.io.Serializable { + private static final String QUALIFIED_SEPARATOR = "/"; + private static final String DOMAIN_SEPARATOR = "."; + private static final long serialVersionUID = -7030021353149084879L; + + /** + * domain of the intent + */ + private String domain; + + private String[] qualifiedNames; + + /** + * Construct a IntentName from a string representation. + * + * @param intent string representation for a intent. + */ + public IntentName(String intent) { + parse(intent); + } + + /** + * Construct a IntentName from domain name and qualified names + * + * @param domain domain name of the intent + * @param qualifiedNames qualified names of the intent + */ + public IntentName(String domain, String[] qualifiedNames) { + this.domain = domain; + this.qualifiedNames = qualifiedNames; + } + + public String getDomain() { + return domain; + } + + public String[] getQualifiedNames() { + String[] results = new String[qualifiedNames.length]; + System.arraycopy(qualifiedNames, 0, results, 0, qualifiedNames.length); + return results; + } + + @Override + public String toString() { + return getName(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final IntentName other = (IntentName) obj; + if (domain == null) { + if (other.domain != null) { + return false; + } + } else if (!domain.equals(other.domain)) { + return false; + } + return Arrays.equals(qualifiedNames, other.qualifiedNames); + } + + @Override + public int hashCode() { + final int PRIME = 17; + int result = 1; + result = PRIME * result + ((domain == null) ? 0 : domain.hashCode()); + result = PRIME * result + Arrays.hashCode(qualifiedNames); + return result; + } + + private String getName() { + StringBuilder sbd = new StringBuilder(domain); + for (int i = 0; i < qualifiedNames.length; i++) { + if (i == 0) { + sbd.append(DOMAIN_SEPARATOR); + } else { + sbd.append(QUALIFIED_SEPARATOR); + } + sbd.append(qualifiedNames[i]); + } + + return sbd.toString(); + } + + /** + * Parse a string representation of intent. + * + * @param intent string representation of intent + */ + private void parse(String intent) { + String iname = validateFormat(intent); + int domainIdx = iname.indexOf(DOMAIN_SEPARATOR); + domain = iname.substring(0, domainIdx); + String qualifNamesStr = iname.substring(domainIdx + 1); + qualifiedNames = qualifNamesStr.split(QUALIFIED_SEPARATOR); + + } + + private String validateFormat(String intent) { + // TODO validate and canonicalize intent name + return intent; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java new file mode 100644 index 0000000000..2d5a0802e6 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.HashMap; +import java.util.Map; + +/** + * The base class for assembly model subtypes + * + * @version $Rev$ $Date$ + */ +public abstract class ModelObject { + private final Map<Object, Object> extensions = new HashMap<Object, Object>(); + + protected ModelObject() { + } + + public Map<Object, Object> getExtensions() { + return extensions; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Multiplicity.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Multiplicity.java new file mode 100644 index 0000000000..f7ec8759f8 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Multiplicity.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 org.apache.tuscany.spi.model; + +/** + * Enumeration for multiplicity. + */ +public enum Multiplicity { + /** + * Indicates a relationship that is optionally connected to the requestor and which, if supplied, must be connected + * to exactly one provider. + */ + ZERO_ONE, + + /** + * Indicates a relationship that must be connected between exactly one requestor and exactly one provider. + */ + ONE_ONE, + + /** + * Indicates a relationship that is optionally connects the requestor to zero to unbounded providers. + */ + ZERO_N, + + /** + * Indicates a relationship that must be connected at the requestor and which connects it to zero to unbounded + * providers. + */ + ONE_N + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java new file mode 100644 index 0000000000..70c309609f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java @@ -0,0 +1,406 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * Represents an operation that is part of a service contract. The type paramter of this operation identifies the + * logical type system for all data types. + * + * @version $Rev$ $Date$ + */ +public class Operation<T> extends ModelObject implements Cloneable { + public static final int NO_CONVERSATION = -1; + public static final int CONVERSATION_CONTINUE = 1; + public static final int CONVERSATION_END = 2; + + protected Map<String, Object> metaData; + private final String name; + private ServiceContract<T> contract; + private DataType<T> outputType; + private DataType<List<DataType<T>>> inputType; + private List<DataType<T>> faultTypes; + private String dataBinding; + private boolean wrapperStyle; + private WrapperInfo wrapper; + private boolean callback; + private boolean nonBlocking; + private int conversationSequence = NO_CONVERSATION; + + /** + * Construct a minimally-specified operation + * + * @param name the name of the operation + * @param inputType the data types of parameters passed to the operation + * @param outputType the data type returned by the operation + * @param faultTypes the data type of faults raised by the operation + */ + public Operation(String name, + DataType<List<DataType<T>>> inputType, + DataType<T> outputType, + List<DataType<T>> faultTypes) { + this(name, inputType, outputType, faultTypes, false, null, NO_CONVERSATION); + } + + /** + * Construct an operation + * + * @param name the name of the operation + * @param inputType the data types of parameters passed to the operation + * @param outputType the data type returned by the operation + * @param faultTypes the data type of faults raised by the operation + * @param nonBlocking if the operation is non-blocking + * @param dataBinding the data-binding type required by the operation + * @param sequence the conversational attributes of the operation, {@link NO_CONVERSATION}, {@link + * CONVERSATION_CONTINUE}, or {@link CONVERSATION_END} + */ + public Operation(final String name, + final DataType<List<DataType<T>>> inputType, + final DataType<T> outputType, + final List<DataType<T>> faultTypes, + boolean nonBlocking, + String dataBinding, + int sequence) { + super(); + this.name = name; + List<DataType<T>> types = Collections.emptyList(); + this.inputType = (inputType != null) ? inputType : new DataType<List<DataType<T>>>(Object[].class, types); + this.outputType = (outputType != null) ? outputType : new DataType<T>(void.class, null); + this.faultTypes = (faultTypes == null) ? types : faultTypes; + this.nonBlocking = nonBlocking; + this.dataBinding = dataBinding; + this.conversationSequence = sequence; + // Register the operation with the types + this.inputType.setOperation(this); + for (DataType<?> d : this.inputType.getLogical()) { + d.setOperation(this); + } + this.outputType.setOperation(this); + for (DataType<?> d : this.faultTypes) { + d.setOperation(this); + } + } + + /** + * Returns the service contract the operation is part of. + * + * @return the service contract the operation is part of. + */ + public ServiceContract<T> getServiceContract() { + return contract; + } + + /** + * Sets the service contract the operation is part of. + * + * @param contract the service contract the operation is part of. + */ + public void setServiceContract(ServiceContract<T> contract) { + this.contract = contract; + } + + /** + * Returns true if the operation is part of the callback contract. + * + * @return true if the operation is part of the callback contract. + */ + public boolean isCallback() { + return callback; + } + + /** + * Sets whether the operation is part of the callback contract. + * + * @param callback whether the operation is part of the callback contract. + */ + public void setCallback(boolean callback) { + this.callback = callback; + } + + /** + * Returns the name of the operation. + * + * @return the name of the operation + */ + public String getName() { + return name; + } + + /** + * Returns the data type returned by the operation. + * + * @return the data type returned by the operation + */ + public DataType<T> getOutputType() { + return outputType; + } + + /** + * Returns the data types of the parameters passed to the operation. + * <p/> + * The inputType's logical type is a list of DataTypes which describes the parameter types + * + * @return the data types of the parameters passed to the operation + */ + public DataType<List<DataType<T>>> getInputType() { + return inputType; + } + + /** + * Returns the data types of the faults raised by the operation. + * + * @return the data types of the faults raised by the operation + */ + public List<DataType<T>> getFaultTypes() { + if (faultTypes == null) { + return Collections.emptyList(); + } + return faultTypes; + } + + /** + * Returns true if the operation is non-blocking. A non-blocking operation may not have completed execution at the + * time an invocation of the operation returns. + * + * @return true if the operation is non-blocking + */ + public boolean isNonBlocking() { + return nonBlocking; + } + + /** + * Sets if the operation is non-blocking + */ + public void setNonBlocking(boolean nonBlocking) { + this.nonBlocking = nonBlocking; + } + + /** + * Returns the sequence the operation is called in a conversation, {@link NO_CONVERSATION}, {@link + * CONVERSATION_CONTINUE}, or {@link CONVERSATION_END} + * + * @return the sequence the operation is called in a conversation + */ + public int getConversationSequence() { + return conversationSequence; + } + + /** + * Sets the sequence the operation is called in a conversation, {@link NO_CONVERSATION}, {@link + * CONVERSATION_CONTINUE}, or {@link CONVERSATION_END} + */ + public void setConversationSequence(int conversationSequence) { + this.conversationSequence = conversationSequence; + } + + /** + * Returns the data binding type specified for the operation or null. + * + * @return the data binding type specified for the operation or null. + */ + public String getDataBinding() { + return (dataBinding == null && contract != null) ? contract.getDataBinding() : dataBinding; + } + + /** + * Set the databinding for this operation + * + * @param dataBinding The databinding + */ + public void setDataBinding(String dataBinding) { + this.dataBinding = dataBinding; + } + + /** + * Returns a map of metadata key to value mappings for the operation. + * + * @return a map of metadata key to value mappings for the operation. + */ + public Map<String, Object> getMetaData() { + if (metaData == null) { + return Collections.emptyMap(); + } + return metaData; + } + + /** + * Adds metadata associated with the operation. + * + * @param key the metadata key + * @param val the metadata value + */ + public void setMetaData(String key, Object val) { + if (metaData == null) { + metaData = new HashMap<String, Object>(); + } + metaData.put(key, val); + } + + public String toString() { + return name; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + final Operation operation = (Operation) o; + + if (name != null ? !name.equals(operation.name) : operation.name != null) { + return false; + } + + // HACK: If the operation is mappable, then the equality test is relaxed + if (isMappable()) { + return true; + } + + // FIXME: TUSCANY-1111, currently comparing different IDLs fail + if (contract != null && contract.getClass() != operation.getServiceContract().getClass()) { + return true; + } + + if (faultTypes == null && operation.faultTypes != null) { + return false; + } else if (faultTypes != null + && operation.faultTypes != null + && faultTypes.size() != 0 + && operation.faultTypes.size() != 0) { + if (faultTypes.size() < operation.faultTypes.size()) { + return false; + } else { + //noinspection ForLoopReplaceableByForEach + for (int i = 0; i < operation.faultTypes.size(); i++) { + if (!faultTypes.get(i).equals(operation.faultTypes.get(i))) { + return false; + } + } + } + } + + if (inputType != null ? !inputType.equals(operation.inputType) : operation.inputType != null) { + return false; + } + return !(outputType != null ? !outputType.equals(operation.outputType) : operation.outputType != null); + } + + public int hashCode() { + int result; + result = name != null ? name.hashCode() : 0; + // HACK: + if (isMappable()) { + return result; + } + result = 29 * result + (outputType != null ? outputType.hashCode() : 0); + result = 29 * result + (inputType != null ? inputType.hashCode() : 0); + result = 29 * result + (faultTypes != null ? faultTypes.hashCode() : 0); + return result; + } + + /** + * Returns true if the operation may be mapped to another target operation through an mediation + */ + private boolean isMappable() { + if (contract != null) { + return contract.isRemotable(); + } else { + return false; + } + } + + /** + * Returns true if the operation is wrapper style + * + * @return the wrapperStyle + */ + public boolean isWrapperStyle() { + return wrapperStyle; + } + + /** + * Return the Wrapper information for this operation is it's wrapper style + * + * @return The Wrapper + */ + public WrapperInfo getWrapper() { + if (!isWrapperStyle()) { + throw new IllegalStateException("The operation is not wrapper style."); + } else { + return wrapper; + } + } + + /** + * @param wrapper the wrapper to set + */ + public void setWrapper(WrapperInfo wrapper) { + this.wrapper = wrapper; + } + + /** + * @param wrapperStyle the wrapperStyle to set + */ + public void setWrapperStyle(boolean wrapperStyle) { + this.wrapperStyle = wrapperStyle; + } + + @SuppressWarnings("unchecked") + @Override + public Operation<T> clone() throws CloneNotSupportedException { + Operation<T> copy = (Operation<T>) super.clone(); + final List<DataType<T>> clonedFaultTypes = new ArrayList<DataType<T>>(this.faultTypes.size()); + for (DataType<T> t : this.faultTypes) { + clonedFaultTypes.add((DataType<T>) t.clone()); + } + + List<DataType<T>> clonedTypes = new ArrayList<DataType<T>>(); + for (DataType<T> t : inputType.getLogical()) { + DataType<T> type = (DataType<T>) t.clone(); + clonedTypes.add(type); + } + + DataType<List<DataType<T>>> clonedInputType = + new DataType<List<DataType<T>>>(inputType.getPhysical(), clonedTypes); + clonedInputType.setDataBinding(inputType.getDataBinding()); + + DataType<T> clonedOutputType = (DataType<T>) this.outputType.clone(); + + copy.inputType = clonedInputType; + copy.outputType = clonedOutputType; + copy.faultTypes = clonedFaultTypes; + + if (this.metaData != null) { + assert this.metaData instanceof HashMap; + copy.metaData = (HashMap) ((HashMap) this.metaData).clone(); + } + return copy; + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java new file mode 100644 index 0000000000..fee13f7205 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.Collection; +/** +* +* Represents capability of being attached with Intent and PolicySet. +* +*/ +public interface PolicyAttachable { + /** + * Get the name of PolicySet attached + * @return the name of PolicySet + */ + String getPolicySet(); + /** + * Get collection contains <code>IntentName</code> required. + * @return collection contains <code>IntentName</code> required. + */ + Collection<IntentName> getRequiredIntents(); + +}
\ No newline at end of file diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java new file mode 100644 index 0000000000..3ebbfb16d7 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.Collection; + +/** + * Base class for model classes which can be associated with Intent and PolicySet by specifing requires and policySet + * attributes on xml element. + */ + +public abstract class PolicyAttachableModel extends ModelObject implements PolicyAttachable { + protected Collection<IntentName> requiredIntent; + protected String policySet; + + public String getPolicySet() { + return policySet; + } + + public void setPolicySet(String policySet) { + this.policySet = policySet; + } + + public Collection<IntentName> getRequiredIntents() { + return requiredIntent; + } + + public void addRequiredIntent(IntentName requiredIntent) { + this.requiredIntent.add(requiredIntent); + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java new file mode 100644 index 0000000000..7d2412ee8d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.ArrayList; +import java.util.Collection; +import static java.util.Collections.unmodifiableCollection; + +/** + * PolicyModel which contains concrete policy content in form of WSPolicyAttachment or other extensions. + */ +public abstract class PolicyContentModel extends PolicyModel { + /* WSPolicyAttachment contained in this Model */ + protected Collection<WSPolicyAttachment> wsPolicyAttachments = new ArrayList<WSPolicyAttachment>(); + /* Any policy model extensions besides standard intentMap, ws-policyattachment, etc. */ + protected Collection<PolicyModel> extensions = new ArrayList<PolicyModel>(); + + public Collection<PolicyModel> getPolicyExtensions() { + return extensions; + } + + public Collection<WSPolicyAttachment> getWsPolicyAttachments() { + return unmodifiableCollection(wsPolicyAttachments); + } + + public void addWsPolicyAttachment(WSPolicyAttachment attachment) { + wsPolicyAttachments.add(attachment); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java new file mode 100644 index 0000000000..17bd8f0b7e --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + + +/** + * An abstract base class for all policy model representations. + * <p/> + * $Version$ $Date$ + */ +public abstract class PolicyModel extends ModelObject { + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySet.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySet.java new file mode 100644 index 0000000000..7545f234e1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySet.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.ArrayList; +import java.util.Collection; +import static java.util.Collections.unmodifiableCollection; +import static java.util.Collections.unmodifiableList; +import java.util.List; +import javax.xml.namespace.QName; + +/** + * Model representation for PolicySet. + * <p/> + * $Rev$ $Date$ + */ +public class PolicySet extends PolicyContentModel { + + /** + * QNames of artifacts to which this Policy can apply + */ + protected List<QName> appliedArtifacts = new ArrayList<QName>(); + + /** + * IntentMap contained in this PolicySet + */ + private Collection<IntentMap> intentMaps = new ArrayList<IntentMap>(); + + /** + * Name for PolicySet, corresponding to name attribute of PolicySet element in SCDL + */ + private QName name; + + /** + * References to other PolicySet + */ + private Collection<PolicySetReference> policySetReferences = new ArrayList<PolicySetReference>(); + + /** + * Name of intents provided by this PolicySet + */ + private Collection<IntentName> provideIntents = new ArrayList<IntentName>(); + + public PolicySet(QName name, List<IntentName> providesIntent) { + super(); + this.name = name; + this.provideIntents.addAll(providesIntent); + } + + + public void addPolicySetReference(PolicySetReference ref) { + policySetReferences.add(ref); + } + + public void addAppliedArtifacts(QName artifactName) { + appliedArtifacts.add(artifactName); + } + + public List<QName> getAppliedArtifacts() { + return unmodifiableList(appliedArtifacts); + } + + public void addIntentMap(IntentMap intentMap) { + intentMaps.add(intentMap); + } + + public Collection<IntentMap> getIntentMaps() { + return unmodifiableCollection(intentMaps); + } + + public QName getName() { + return name; + } + + public Collection<PolicySetReference> getPolicySetReferences() { + return unmodifiableCollection(policySetReferences); + } + + public Collection<IntentName> getProvideIntents() { + return unmodifiableCollection(provideIntents); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySetReference.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySetReference.java new file mode 100644 index 0000000000..46924910d0 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySetReference.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import javax.xml.namespace.QName; + +/** + * Presents a PolicySetReference. + */ +public class PolicySetReference extends PolicyModel { + + private QName reference; + + public PolicySetReference(QName reference) { + super(); + this.reference = reference; + } + + public QName getReference() { + return reference; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Property.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Property.java new file mode 100644 index 0000000000..9b6e192c17 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Property.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import javax.xml.namespace.QName; + +import org.w3c.dom.Document; + +import org.apache.tuscany.spi.ObjectFactory; + +/** + * A component property + * + * @version $Rev$ $Date$ + */ +public class Property<T> extends ModelObject { + private String name; + private boolean required; + private ObjectFactory<T> defaultValueFactory; + private QName xmlType; + private Class<T> javaType; + private boolean many; + private Document defaultValue; + + public Property() { + } + + public Property(String name, QName xmlType, Class<T> javaType) { + this.name = name; + this.xmlType = xmlType; + this.javaType = javaType; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isRequired() { + return required; + } + + public void setRequired(boolean required) { + this.required = required; + } + + public ObjectFactory<T> getDefaultValueFactory() { + return defaultValueFactory; + } + + public void setDefaultValueFactory(ObjectFactory<T> factory) { + this.defaultValueFactory = factory; + } + + public QName getXmlType() { + return xmlType; + } + + public void setXmlType(QName xmlType) { + this.xmlType = xmlType; + } + + public Class<T> getJavaType() { + return javaType; + } + + public void setJavaType(Class<T> javaType) { + this.javaType = javaType; + } + + public boolean isMany() { + return many; + } + + public void setMany(boolean many) { + this.many = many; + } + + public Document getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(Document defaultValue) { + this.defaultValue = defaultValue; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java new file mode 100644 index 0000000000..93eaa74f52 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import org.apache.tuscany.spi.ObjectFactory; +import org.w3c.dom.Document; + +/** + * Represents a configured component property + * + * @version $Rev$ $Date$ + */ +public class PropertyValue<T> extends ModelObject { + private String name; + private String source; + private String file; + private Document value; + private ObjectFactory<T> valueFactory; + + public PropertyValue() { + } + + /** + * Constructor specifying the name of a property and the XPath source expression. + * + * @param name the name of the property which this value is for + * @param source an XPath expression whose result will be the actual value + * @param file A URI that the property value can be loaded from + */ + public PropertyValue(String name, String source, String file) { + this.name = name; + this.source = source; + this.file = file; + } + + /** + * @param name + * @param value + */ + public PropertyValue(String name, Document value) { + this.name = name; + this.value = value; + } + + public PropertyValue(String name, ObjectFactory<T> valueFactory) { + this.name = name; + this.valueFactory = valueFactory; + } + + /** + * Returns the name of the property that this value is for. + * @return the name of the property that this value is for + */ + public String getName() { + return name; + } + + /** + * Sets the name of the property that this value is for. + * @param name the name of the property that this value is for + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns an XPath expression that should be evaluated to get the actual property value. + * + * @return an XPath expression that should be evaluated to get the actual property value + */ + public String getSource() { + return source; + } + + /** + * Sets an XPath expression that should be evaluated to get the actual property value. + * @param source an XPath expression that should be evaluated to get the actual property value + */ + public void setSource(String source) { + this.source = source; + } + + public ObjectFactory<T> getValueFactory() { + return valueFactory; + } + + public void setValueFactory(ObjectFactory<T> valueFactory) { + this.valueFactory = valueFactory; + } + + public Document getValue() { + return value; + } + + public void setValue(Document value) { + this.value = value; + } + + /** + * @return the file + */ + public String getFile() { + return file; + } + + /** + * @param file the file to set + */ + public void setFile(String file) { + this.file = file; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Qualifier.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Qualifier.java new file mode 100644 index 0000000000..8a7d709bd9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Qualifier.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 org.apache.tuscany.spi.model; + +/** + * Model reprentation for qualifier + */ + +public class Qualifier extends PolicyContentModel { + + private String name; + + /** + * IntentMap contained in this Qualifier + */ + private IntentMap intentMap; + + public Qualifier(String name) { + super(); + this.name = name; + } + + public String getName() { + return name; + } + + public IntentMap getIntentMap() { + return intentMap; + } + + public void setIntentMap(IntentMap intentMap) { + this.intentMap = intentMap; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java new file mode 100644 index 0000000000..46dfd8e0a0 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Represents a component reference + * + * @version $Rev$ $Date$ + */ +public class ReferenceDefinition extends ModelObject { + private URI uri; + private ServiceContract serviceContract; + private Multiplicity multiplicity; + private boolean required; + private List<BindingDefinition> bindings; + + public ReferenceDefinition() { + multiplicity = Multiplicity.ONE_ONE; + bindings = new ArrayList<BindingDefinition>(); + } + + public ReferenceDefinition(URI uri, ServiceContract serviceContract) { + this.uri = uri; + this.serviceContract = serviceContract; + bindings = new ArrayList<BindingDefinition>(); + multiplicity = Multiplicity.ONE_ONE; + } + + public ReferenceDefinition(URI uri, ServiceContract serviceContract, Multiplicity multiplicity) { + this.uri = uri; + this.serviceContract = serviceContract; + this.multiplicity = multiplicity; + bindings = new ArrayList<BindingDefinition>(); + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public ServiceContract<?> getServiceContract() { + return serviceContract; + } + + public void setServiceContract(ServiceContract serviceContract) { + this.serviceContract = serviceContract; + } + + public Multiplicity getMultiplicity() { + return multiplicity; + } + + public void setMultiplicity(Multiplicity multiplicity) { + this.multiplicity = multiplicity; + } + + public boolean isRequired() { + return required; + } + + public void setRequired(boolean required) { + this.required = required; + } + + public List<BindingDefinition> getBindings() { + return Collections.unmodifiableList(bindings); + } + + public void addBinding(BindingDefinition binding) { + this.bindings.add(binding); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceTarget.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceTarget.java new file mode 100644 index 0000000000..bc721ea02c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceTarget.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +/** + * Represents the set of targets configured on a reference + * + * @version $Rev$ $Date$ + */ +public class ReferenceTarget extends ModelObject { + private URI referenceName; + private boolean autowire; + private List<URI> targets = new ArrayList<URI>(); + + public URI getReferenceName() { + return referenceName; + } + + public void setReferenceName(URI referenceName) { + this.referenceName = referenceName; + } + + /** + * Returns true if autowire is enabled for the reference. + * + * @return true if autowire is enabled for the reference. + */ + public boolean isAutowire() { + return autowire; + } + + /** + * Sets autowire enablement for the reference. + * + * @param autowire true if autowire is enabled. + */ + public void setAutowire(boolean autowire) { + this.autowire = autowire; + } + + public List<URI> getTargets() { + return targets; + } + + public void addTarget(URI target) { + targets.add(target); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ResourceDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ResourceDefinition.java new file mode 100644 index 0000000000..02da577656 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ResourceDefinition.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +/** + * Represents a resource definition. Resources are provisioned to runtime nodes. + * + * @version $Rev$ $Date$ + */ +public class ResourceDefinition { +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Scope.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Scope.java new file mode 100644 index 0000000000..450839dd03 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Scope.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +/** + * The default implementation scopes supported by assemblies. + * + * @version $Rev$ $Date$ + */ +public class Scope { + public static final Scope STATELESS = new Scope("STATELESS"); + public static final Scope REQUEST = new Scope("REQUEST"); + public static final Scope SESSION = new Scope("SESSION"); + public static final Scope CONVERSATION = new Scope("CONVERSATION"); + public static final Scope COMPOSITE = new Scope("COMPOSITE"); + public static final Scope SYSTEM = new Scope("SYSTEM"); + public static final Scope UNDEFINED = new Scope("UNDEFINED"); + + private String scope; + + public Scope(String scope) { + this.scope = scope.toUpperCase().intern(); + } + + public String getScope() { + return scope; + } + + @SuppressWarnings({"StringEquality"}) + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final Scope scope1 = (Scope) o; + return !(scope != null ? scope != scope1.scope.intern() : scope1.scope != null); + } + + public int hashCode() { + return scope != null ? scope.hashCode() : 0; + } + + public String toString() { + return scope; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java new file mode 100644 index 0000000000..d2c7df55ff --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java @@ -0,0 +1,283 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Base class representing service contract information + * + * @version $Rev$ $Date$ + */ +public abstract class ServiceContract<T> extends ModelObject implements Cloneable { + protected boolean conversational; + protected boolean remotable; + protected Class<?> interfaceClass; + protected String interfaceName; + protected String callbackName; + protected Class<?> callbackClass; + protected Map<String, Operation<T>> operations; + protected Map<String, Operation<T>> callbackOperations; + protected String dataBinding; + protected Map<String, Object> metaData; + + protected ServiceContract() { + } + + protected ServiceContract(Class<?> interfaceClass) { + this.interfaceClass = interfaceClass; + } + + protected ServiceContract(String interfaceName) { + this.interfaceName = interfaceName; + } + + /** + * Returns the interface name for the contract + * + * @return the interface name for the contract + */ + public String getInterfaceName() { + return interfaceName; + } + + /** + * Sets the interface name for the contract + */ + public void setInterfaceName(String interfaceName) { + this.interfaceName = interfaceName; + } + + /** + * Returns the class used to represent the service contract + */ + public Class<?> getInterfaceClass() { + return interfaceClass; + } + + /** + * Sets the class used to represent the service contract + */ + public void setInterfaceClass(Class<?> interfaceClass) { + this.interfaceClass = interfaceClass; + } + + /** + * Returns true if the service contract is conversational + * + * @return true if the service contract is conversational + */ + public boolean isConversational() { + return conversational; + } + + /** + * Sets if the service contract is conversational + * + * @param conversational the conversational attribute + */ + public void setConversational(boolean conversational) { + this.conversational = conversational; + } + + /** + * @return the remotable + */ + public boolean isRemotable() { + return remotable; + } + + /** + * @param remotable the remotable to set + */ + public void setRemotable(boolean remotable) { + this.remotable = remotable; + } + + /** + * Returns the name of the callback or null if the contract is unidirectional + */ + public String getCallbackName() { + return callbackName; + } + + /** + * Sets the name of the callback service + */ + public void setCallbackName(String callbackName) { + this.callbackName = callbackName; + } + + /** + * Returns the name of the callback service + */ + public Class<?> getCallbackClass() { + return callbackClass; + } + + public void setCallbackClass(Class<?> callbackClass) { + this.callbackClass = callbackClass; + } + + public Operation getOperation(String name) { + return operations == null ? null : operations.get(name); + } + + public Map<String, Operation<T>> getOperations() { + if (operations == null) { + return Collections.emptyMap(); + } + return Collections.unmodifiableMap(operations); + } + + public void setOperations(Map<String, Operation<T>> operations) { + for (Operation<T> operation : operations.values()) { + operation.setServiceContract(this); + } + this.operations = operations; + } + + public Map<String, Operation<T>> getCallbackOperations() { + if (callbackOperations == null) { + return Collections.emptyMap(); + } + return Collections.unmodifiableMap(callbackOperations); + } + + public void setCallbackOperations(Map<String, Operation<T>> callbacksOperations) { + for (Operation<T> operation : callbacksOperations.values()) { + operation.setServiceContract(this); + operation.setCallback(true); + } + this.callbackOperations = callbacksOperations; + } + + public String getDataBinding() { + return dataBinding; + } + + public void setDataBinding(String dataBinding) { + this.dataBinding = dataBinding; + } + + /** + * Returns a map of metadata key to value mappings for the operation. + * + * @return a map of metadata key to value mappings for the operation. + */ + public Map<String, Object> getMetaData() { + if (metaData == null) { + return Collections.emptyMap(); + } + return metaData; + } + + /** + * Adds metadata associated with the operation. + * + * @param key the metadata key + * @param val the metadata value + */ + public void setMetaData(String key, Object val) { + if (metaData == null) { + metaData = new HashMap<String, Object>(); + } + metaData.put(key, val); + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + final ServiceContract that = (ServiceContract) o; + + if (callbackName != null ? !callbackName.equals(that.callbackName) : that.callbackName != null) { + return false; + } + if (callbackOperations != null ? !callbackOperations.equals(that.callbackOperations) + : that.callbackOperations != null) { + return false; + } + if (interfaceClass != null ? !interfaceClass.equals(that.interfaceClass) : that.interfaceClass != null) { + return false; + } + if (interfaceName != null ? !interfaceName.equals(that.interfaceName) : that.interfaceName != null) { + return false; + } + return !(operations != null ? !operations.equals(that.operations) : that.operations != null); + + } + + public int hashCode() { + int result; + result = interfaceClass != null ? interfaceClass.hashCode() : 0; + result = 29 * result + (interfaceName != null ? interfaceName.hashCode() : 0); + result = 29 * result + (callbackName != null ? callbackName.hashCode() : 0); + result = 29 * result + (operations != null ? operations.hashCode() : 0); + result = 29 * result + (callbackOperations != null ? callbackOperations.hashCode() : 0); + return result; + } + + public String toString() { + if (interfaceName != null) { + return new StringBuilder().append("ServiceContract[").append(interfaceName).append("]").toString(); + } else if (interfaceClass != null) { + return new StringBuilder().append("ServiceContract[").append(interfaceClass.getName()).append("]") + .toString(); + } else { + return super.toString(); + } + + } + + @SuppressWarnings("unchecked") + @Override + public Object clone() throws CloneNotSupportedException { + ServiceContract<T> copy = (ServiceContract<T>) super.clone(); + + if (operations != null) { + Map<String, Operation<T>> clonedOperations = new HashMap<String, Operation<T>>(); + for (Operation<T> o : operations.values()) { + clonedOperations.put(o.getName(), (Operation<T>)o.clone()); + } + copy.setOperations(clonedOperations); + } + + if (callbackOperations != null) { + Map<String, Operation<T>> clonedCallbackOperations = new HashMap<String, Operation<T>>(); + for (Operation<T> o : callbackOperations.values()) { + clonedCallbackOperations.put(o.getName(), (Operation<T>)o.clone()); + } + copy.setCallbackOperations(clonedCallbackOperations); + } + + if (this.metaData != null) { + assert this.metaData instanceof HashMap; + copy.metaData = (HashMap) ((HashMap) this.metaData).clone(); + } + + return copy; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceDefinition.java new file mode 100644 index 0000000000..25c1beffe1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceDefinition.java @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Represents a service offered by a component + * + * @version $Rev$ $Date$ + */ +public class ServiceDefinition extends ModelObject { + private URI uri; + private ServiceContract serviceContract; + private boolean remotable; + private String callbackRefName; + private List<BindingDefinition> bindings; + private URI target; + + public ServiceDefinition() { + bindings = new ArrayList<BindingDefinition>(); + } + + public ServiceDefinition(URI uri, ServiceContract serviceContract, boolean remotable) { + bindings = new ArrayList<BindingDefinition>(); + this.uri = uri; + this.serviceContract = serviceContract; + this.remotable = remotable; + } + + public ServiceDefinition(URI uri, ServiceContract serviceContract, boolean remotable, String callbackRefName) { + bindings = new ArrayList<BindingDefinition>(); + this.uri = uri; + this.serviceContract = serviceContract; + this.remotable = remotable; + this.callbackRefName = callbackRefName; + } + + /** + * Returns the service name + * + * @return the service name + */ + public URI getUri() { + return uri; + } + + /** + * Sets the service name + * + * @param uri the service name + */ + public void setUri(URI uri) { + this.uri = uri; + } + + /** + * Returns the service contract + * + * @return the service contract + */ + public ServiceContract<?> getServiceContract() { + return serviceContract; + } + + /** + * Sets the service contract + * + * @param contract the service contract + */ + public void setServiceContract(ServiceContract contract) { + this.serviceContract = contract; + } + + /** + * Returns true if the service is remotable + * + * @return true if the service is remotable + */ + public boolean isRemotable() { + return remotable; + } + + /** + * Sets if the service is remotable + * + * @param remotable if the service is remotable + */ + public void setRemotable(boolean remotable) { + this.remotable = remotable; + } + + /** + * Returns the callback name. + */ + public String getCallbackReferenceName() { + return callbackRefName; + } + + /** + * Sets the callback name + */ + public void setCallbackReferenceName(String name) { + this.callbackRefName = name; + } + + /** + * Returns the bindings configured for the service + * + * @return the bindings configured for the service + */ + public List<BindingDefinition> getBindings() { + return Collections.unmodifiableList(bindings); + } + + /** + * Configures the service with a binding + * + * @param binding the binding + */ + public void addBinding(BindingDefinition binding) { + this.bindings.add(binding); + } + + /** + * Returns the target URI the service is wired to + * + * @return the target URI the service is wired to + */ + public URI getTarget() { + return target; + } + + /** + * Sets the target URI the service is wired to + * + * @param target the target URI the service is wired to + */ + public void setTarget(URI target) { + this.target = target; + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/TypeInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/TypeInfo.java new file mode 100644 index 0000000000..12ea9fa8ce --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/TypeInfo.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.model; + +import javax.xml.namespace.QName; + +/** + * An abstraction of XML schema types + */ +public class TypeInfo { + private QName name; + + private boolean isSimpleType; + + private TypeInfo baseType; + + /** + * @param name + * @param isSimpleType + */ + public TypeInfo(QName name, boolean isSimpleType, TypeInfo baseType) { + super(); + this.name = name; + this.isSimpleType = isSimpleType; + this.baseType = baseType; + } + + /** + * @return the isSimpleType + */ + public boolean isSimpleType() { + return isSimpleType; + } + + /** + * @return the name + */ + public QName getQName() { + return name; + } + + /** + * @return the baseType + */ + public TypeInfo getBaseType() { + return baseType; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("Type: ").append(name); + return sb.toString(); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WSPolicyAttachment.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WSPolicyAttachment.java new file mode 100644 index 0000000000..ff1a6cf791 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WSPolicyAttachment.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +/* + * Presents a ws-policy attachment. + */ +public class WSPolicyAttachment<T> extends PolicyModel { + private T content; + + public T getContent() { + return content; + } + + public void setContent(T content) { + this.content = content; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WireDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WireDefinition.java new file mode 100644 index 0000000000..7ae91811b6 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WireDefinition.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 org.apache.tuscany.spi.model; + +import java.net.URI; + +/** + * Represents a wire specified in an assembly + * + * @version $Rev$ $Date$ + */ +public class WireDefinition extends ModelObject { + private URI source; + private URI target; + + public URI getSource() { + return source; + } + + public void setSource(URI source) { + this.source = source; + } + + public URI getTarget() { + return target; + } + + public void setTarget(URI target) { + this.target = target; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WrapperInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WrapperInfo.java new file mode 100644 index 0000000000..acdb5d7deb --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WrapperInfo.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.model; + +import java.util.ArrayList; +import java.util.List; + +/** + * The "Wrapper Style" WSDL operation is defined by The Java API for XML-Based + * Web Services (JAX-WS) 2.0 specification, section 2.3.1.2 Wrapper Style. <p/> + * A WSDL operation qualifies for wrapper style mapping only if the following + * criteria are met: + * <ul> + * <li>(i) The operation’s input and output messages (if present) each contain + * only a single part + * <li>(ii) The input message part refers to a global element declaration whose + * localname is equal to the operation name + * <li>(iii) The output message part refers to a global element declaration + * <li>(iv) The elements referred to by the input and output message parts + * (henceforth referred to as wrapper elements) are both complex types defined + * using the xsd:sequence compositor + * <li>(v) The wrapper elements only contain child elements, they must not + * contain other structures such as wildcards (element or attribute), + * xsd:choice, substitution groups (element references are not permitted) or + * attributes; furthermore, they must not be nillable. + * </ul> + * + * @version $Rev$ $Date$ + */ +public class WrapperInfo { + private ElementInfo inputWrapperElement; + + private ElementInfo outputWrapperElement; + + private List<ElementInfo> inputChildElements; + + private List<ElementInfo> outputChildElements; + + private DataType<List<DataType<XMLType>>> unwrappedInputType; + + private DataType<XMLType> unwrappedOutputType; + + private String dataBinding; + + public WrapperInfo(String dataBinding, + ElementInfo inputWrapperElement, + ElementInfo outputWrapperElement, + List<ElementInfo> inputElements, + List<ElementInfo> outputElements) { + super(); + this.dataBinding = dataBinding; + this.inputWrapperElement = inputWrapperElement; + this.outputWrapperElement = outputWrapperElement; + this.inputChildElements = inputElements; + this.outputChildElements = outputElements; + } + + /** + * @return the inputElements + */ + public List<ElementInfo> getInputChildElements() { + return inputChildElements; + } + + /** + * @return the inputWrapperElement + */ + public ElementInfo getInputWrapperElement() { + return inputWrapperElement; + } + + /** + * @return the outputElements + */ + public List<ElementInfo> getOutputChildElements() { + return outputChildElements; + } + + /** + * @return the outputWrapperElement + */ + public ElementInfo getOutputWrapperElement() { + return outputWrapperElement; + } + + /** + * @return the unwrappedInputType + */ + public DataType<List<DataType<XMLType>>> getUnwrappedInputType() { + if (unwrappedInputType == null) { + List<DataType<XMLType>> childTypes = new ArrayList<DataType<XMLType>>(); + for (ElementInfo element : getInputChildElements()) { + DataType<XMLType> type = new DataType<XMLType>(dataBinding, Object.class, new XMLType(element)); + type.setMetadata(ElementInfo.class.getName(), element); + childTypes.add(type); + } + unwrappedInputType = new DataType<List<DataType<XMLType>>>("idl:unwrapped.input", Object[].class, + childTypes); + } + return unwrappedInputType; + } + + /** + * @return the unwrappedOutputType + */ + public DataType<XMLType> getUnwrappedOutputType() { + if (unwrappedOutputType == null) { + List<ElementInfo> elements = getOutputChildElements(); + if (elements != null && elements.size() > 0) { + if (elements.size() > 1) { + // We don't support output with multiple parts + throw new IllegalArgumentException("Multi-part output is not supported"); + } + ElementInfo element = elements.get(0); + + unwrappedOutputType = new DataType<XMLType>(dataBinding, Object.class, new XMLType(element)); + unwrappedOutputType.setMetadata(ElementInfo.class.getName(), element); + } + } + return unwrappedOutputType; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/XMLType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/XMLType.java new file mode 100644 index 0000000000..f780c7c5f5 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/XMLType.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.model; + +import javax.xml.namespace.QName; + +/** + * The metadata for an XML element or type + */ +public class XMLType { + public static final XMLType UNKNOWN = new XMLType(null, null); + protected QName element; + protected QName type; + + /** + * @param element + */ + public XMLType(ElementInfo element) { + super(); + this.element = element.getQName(); + if (element.getType() != null) { + this.type = element.getType().getQName(); + } + } + + /** + * @param element + */ + public XMLType(TypeInfo type) { + this.element = null; + this.type = type.getQName(); + } + + public XMLType(QName element, QName type) { + this.element = element; + this.type = type; + } + + /** + * @return the type + */ + public QName getTypeName() { + return type; + } + + public boolean isElement() { + return element != null; + } + + public QName getElementName() { + return element; + } + + public static XMLType getType(QName type) { + return new XMLType(null, type); + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((element == null) ? 0 : element.hashCode()); + result = PRIME * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final XMLType other = (XMLType)obj; + if (element == null) { + if (other.element != null) { + return false; + } + } else if (!element.equals(other.element)) { + return false; + } + if (type == null) { + if (other.type != null) { + return false; + } + } else if (!type.equals(other.type)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Element: " + element + " Type: " + type; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/InstanceFactoryProviderDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/InstanceFactoryProviderDefinition.java new file mode 100644 index 0000000000..45314daaee --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/InstanceFactoryProviderDefinition.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.model.physical; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Base class for instance factory provider definition. + * + * @version $Revsion$ $Date$ + * @param + */ +public class InstanceFactoryProviderDefinition<T> extends ModelObject { + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/POJOComponentDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/POJOComponentDefinition.java new file mode 100644 index 0000000000..be68ad9f61 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/POJOComponentDefinition.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model.physical; + +import java.net.URI; + +/** + * Definition of a physical component based on a POJO. + * + * @version $Rev$ $Date$ + * @param <T> the implementation class (if known) + */ +public abstract class POJOComponentDefinition<T> extends PhysicalComponentDefinition { + + private InstanceFactoryProviderDefinition<T> instanceFactoryProviderDefinition; + private URI classLoaderId; + + /** + * Gets the instance factory provider definition. + * @return Instance factory provider definition. + */ + public InstanceFactoryProviderDefinition<T> getInstanceFactoryProviderDefinition() { + return instanceFactoryProviderDefinition; + } + + /** + * Sets the instance factory provider definition. + * @param instanceFactoryProviderDefinition Instance factory provider definition. + */ + public void setInstanceFactoryProviderDefinition( + InstanceFactoryProviderDefinition<T> instanceFactoryProviderDefinition) { + this.instanceFactoryProviderDefinition = instanceFactoryProviderDefinition; + } + + /** + * Gets the classloader id. + * + * @return Classloader id. + */ + public URI getClassLoaderId() { + return classLoaderId; + } + + /** + * Set the classloader id. + * + * @param classLoaderId Classloader id. + */ + public void setClassLoaderId(URI classLoaderId) { + this.classLoaderId = classLoaderId; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java new file mode 100644 index 0000000000..658800769a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model.physical; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Models a physical change set, sent from the master to the slave. + * + * @version $Revsion$ $Date$ + * + */ +public class PhysicalChangeSet extends ModelObject { + + // Set of physical component definitions + private Set<PhysicalComponentDefinition> componentDefinitions = new HashSet<PhysicalComponentDefinition>(); + + // Set of wire definitions + private Set<PhysicalWireDefinition> wireDefinitions = new HashSet<PhysicalWireDefinition>(); + + /** + * Get all the physical component definitions. + * @return Physical component definitions in the changeset. + */ + public Set<PhysicalComponentDefinition> getComponentDefinitions() { + return Collections.unmodifiableSet(componentDefinitions); + } + + /** + * Get all the wire definitions. + * @return Wire definitions in the changeset. + */ + public Set<PhysicalWireDefinition> getWireDefinitions() { + return Collections.unmodifiableSet(wireDefinitions); + } + + /** + * Adds a physical component definition to the physical change set. + * @param componentDefinition Physical component definition. + */ + public void addComponentDefinition(PhysicalComponentDefinition componentDefinition) { + componentDefinitions.add(componentDefinition); + } + + /** + * Adds a physical wire definition to the physical change set. + * @param wireDefinition Physical wire definition. + */ + public void addWireDefinition(PhysicalWireDefinition wireDefinition) { + wireDefinitions.add(wireDefinition); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalComponentDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalComponentDefinition.java new file mode 100644 index 0000000000..ab78fe44dd --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalComponentDefinition.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model.physical; + +import java.net.URI; + +import org.apache.tuscany.spi.model.ModelObject; +import org.apache.tuscany.spi.model.Scope; + +/** + * Represents a physical component model. + * + * @version $Rev$ $Date$ + */ +public abstract class PhysicalComponentDefinition extends ModelObject { + + private URI componentId; + private Scope scope; + private URI groupId; + private int initLevel; + + /** + * Gets the component id. + * + * @return Component id. + */ + public URI getComponentId() { + return componentId; + } + + /** + * Sets the component id. + * + * @param componentId the component id + */ + public void setComponentId(URI componentId) { + this.componentId = componentId; + } + + /** + * Returns the id of the component group this component belongs to. + * @return the id of the component group this component belongs to + */ + public URI getGroupId() { + return groupId; + } + + /** + * Sets the id of the component group this component belongs to. + * @param groupId the id of the component group this component belongs to + */ + public void setGroupId(URI groupId) { + this.groupId = groupId; + } + + public int getInitLevel() { + return initLevel; + } + + public void setInitLevel(int initLevel) { + this.initLevel = initLevel; + } + + /** + * Gets the scope for the component. + * + * @return The scope for the component. + */ + @Deprecated + public Scope getScope() { + return scope; + } + + /** + * Sets the scope for the component. + * + * @param scope The scope for the component. + */ + @Deprecated + public void setScope(Scope scope) { + this.scope = scope; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalInterceptorDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalInterceptorDefinition.java new file mode 100644 index 0000000000..0cecc640ba --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalInterceptorDefinition.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model.physical; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Model class representing the portable definition of an interceptor. This class is used to describe the interceptors + * around inbound and outbound wires on a physical component definition. + * + * @version $Rev$ $Date$ + */ +public class PhysicalInterceptorDefinition extends ModelObject { + + // The qualified name of the interceptor builder + private QName builder; + + public PhysicalInterceptorDefinition(QName builder) { + this.builder = builder; + } + + /** + * Gets the qualified name of the builder. + * + * @return Qualified name of the builder. + */ + public QName getBuilder() { + return builder; + } + + /** + * Sets the qualified name of the builder. + * + * @param builder Qualified name of the builder. + */ + public void setBuilder(QName builder) { + this.builder = builder; + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java new file mode 100644 index 0000000000..852e71490b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model.physical; + +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Represents an operation. + * + * @version $Revision$ $Date$ + * <p/> + * TODO Discuss with Jeremy/Jim on how to model MEPs, INOUT parameters, faults etc + */ +public class PhysicalOperationDefinition extends ModelObject { + + // Parameters + private List<String> parameterTypes = new LinkedList<String>(); + + // Return + private String returnType; + + // Name of the operation + private String name; + + // Callback + private boolean callback; + + private int conversationSequence; + + // Interceptors defined against the operation + private Set<PhysicalInterceptorDefinition> interceptors = new HashSet<PhysicalInterceptorDefinition>(); + + /** + * Returns the fully qualified parameter types for this operation. + * + * @return Parameter types. + */ + public List<String> getParameters() { + return Collections.unmodifiableList(parameterTypes); + } + + /** + * Add the fully qualified parameter type to the operation. + * + * @param parameter Parameter type to be added. + */ + public void addParameter(String parameter) { + parameterTypes.add(parameter); + } + + /** + * Gets the fuly qualified return type for this operation. + * + * @return Return type for this operation. + */ + public String getReturnType() { + return returnType; + } + + /** + * Sets the fully qualified return type for this operation. + * + * @param returnType Return type for this operation. + */ + public void setReturnType(String returnType) { + this.returnType = returnType; + } + + /** + * Returns the interceptor definitions available for this operation. + * + * @return Inteceptor definitions for this operation. + */ + public Set<PhysicalInterceptorDefinition> getInterceptors() { + return Collections.unmodifiableSet(interceptors); + } + + /** + * Adds an interceptor definition to the operation. + * + * @param interceptor Interceptor definition to be added. + */ + public void addInterceptor(PhysicalInterceptorDefinition interceptor) { + interceptors.add(interceptor); + } + + /** + * Gets the name of the operation. + * + * @return Operation name. + */ + public String getName() { + return name; + } + + /** + * Sets the name of the operation. + * + * @param name Operation name. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Checks whether the operation is a callback. + * + * @return True if this is a callback. + */ + public boolean isCallback() { + return callback; + } + + /** + * Sets whether this is a callback operation or not. + * + * @param callback True if this is a callback. + */ + public void setCallback(boolean callback) { + this.callback = callback; + } + + + public int getConversationSequence() { + return conversationSequence; + } + + public void setConversationSequence(int conversationSequence) { + this.conversationSequence = conversationSequence; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireDefinition.java new file mode 100644 index 0000000000..b26c9ad736 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireDefinition.java @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model.physical; + +import java.net.URI; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Model class representing the portable definition of a wire. This class is used to describe the inbound and outbound + * wires on a physical component definition. + * + * @version $Rev$ $Date$ + */ +public class PhysicalWireDefinition extends ModelObject { + + // Target definition + private PhysicalWireTargetDefinition target; + + // Source definition + private PhysicalWireSourceDefinition source; + + // Collection of operations + private Set<PhysicalOperationDefinition> operations = new HashSet<PhysicalOperationDefinition>(); + + /** + * Adds an operation definition. + * + * @param operation Operation to be added. + */ + public void addOperation(PhysicalOperationDefinition operation) { + operations.add(operation); + } + + + /** + * Returns a read-only view of the available operations. + * + * @return Collection of operations. + */ + public Set<PhysicalOperationDefinition> getOperations() { + return Collections.unmodifiableSet(operations); + } + + + /** + * Returns a read-only view of the available non callback operations. + * + * @return Collection of non-callback operations. + */ + public Set<PhysicalOperationDefinition> getNonCallbackOperations() { + Set<PhysicalOperationDefinition> nonCallbackOperations = new HashSet<PhysicalOperationDefinition>(); + for (PhysicalOperationDefinition operation : operations) { + if (!operation.isCallback()) { + nonCallbackOperations.add(operation); + } + } + return nonCallbackOperations; + } + + /** + * Returns a read-only view of the available callback operations. + * + * @return Collection of callback operations. + */ + public Set<PhysicalOperationDefinition> getCallbackOperations() { + Set<PhysicalOperationDefinition> callbackOperations = new HashSet<PhysicalOperationDefinition>(); + for (PhysicalOperationDefinition operation : operations) { + if (operation.isCallback()) { + callbackOperations.add(operation); + } + } + return callbackOperations; + } + + /** + * Gets the Wire source URI. + * + * @return Wire source URI. + */ + public URI getSourceUri() { + return source.getUri(); + } + + /** + * Gets the Wire target URI. + * + * @return Wire target URI. + */ + public URI getTargetUri() { + return target.getUri(); + } + + /** + * Gets the wire source. + * + * @return Wire source. + */ + public PhysicalWireSourceDefinition getSource() { + return source; + } + + /** + * Sets the wire source. + * + * @param source Wire source. + */ + public void setSource(PhysicalWireSourceDefinition source) { + this.source = source; + } + + /** + * Gets the wire target. + * + * @return Wire target. + */ + public PhysicalWireTargetDefinition getTarget() { + return target; + } + + /** + * Sets the wire target. + * + * @param target Wire target. + */ + public void setTarget(PhysicalWireTargetDefinition target) { + this.target = target; + + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java new file mode 100644 index 0000000000..12ec8e141d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.model.physical; + +import java.net.URI; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Represents a physical wire source definition. + * + * @version $Revision$ $Date$ + */ +public class PhysicalWireSourceDefinition extends ModelObject { + + // URI + private URI uri; + private URI callbackUri; + private boolean optimizable; + private boolean conversational; + + /** + * Gets the URI. + * + * @return the URI. + */ + public URI getUri() { + return uri; + } + + /** + * Sets the URI. + * + * @param uri the URI. + */ + public void setUri(URI uri) { + this.uri = uri; + } + + /** + * Gets the callback URI. + * + * @return the callback URI. + */ + public URI getCallbackUri() { + return callbackUri; + } + + /** + * Sets the URI. + * + * @param uri the callback URI. + */ + public void setCallbackUri(URI uri) { + this.callbackUri = uri; + } + + + /** + * Returns true if the wire may be optimized + * + * @return true if the wire may be optimized + */ + public boolean isOptimizable() { + return optimizable; + } + + /** + * Setting to true indicates the wire may be optimized + * + * @param optimizable if the wire can be optimized + */ + public void setOptimizable(boolean optimizable) { + this.optimizable = optimizable; + } + + public boolean isConversational() { + return conversational; + } + + public void setConversational(boolean conversational) { + this.conversational = conversational; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireTargetDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireTargetDefinition.java new file mode 100644 index 0000000000..e36ffde24a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireTargetDefinition.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.model.physical; + +import java.net.URI; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Represents a physical wire target definition. + * + * @version $Revision$ $Date$ + */ +public class PhysicalWireTargetDefinition extends ModelObject { + + // URI + private URI uri; + + /** + * Gets the URI. + * @return Gets the URI. + */ + public URI getUri() { + return uri; + } + + /** + * Sets the URI. + * @param uri Sets the URI. + */ + public void setUri(URI uri) { + this.uri = uri; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/package-info.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/package-info.java new file mode 100644 index 0000000000..710c0984be --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/package-info.java @@ -0,0 +1,23 @@ +/* + * 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. + */ + +/** + * Overview of Apache Tuscany SPI for extensions. + */ +package org.apache.tuscany.spi;
\ No newline at end of file diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/IntentRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/IntentRegistry.java new file mode 100644 index 0000000000..8517977f0d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/IntentRegistry.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.policy; + +import java.util.Collection; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.Intent; +import org.apache.tuscany.spi.model.IntentName; + +/** + * The registry for intents. + * + * @version $Rev$ $Date$ + */ +public interface IntentRegistry { + + /** + * Register a intent. + * + * @param intent intent to register + */ + void register(Intent intent); + + /** + * Unregister a intent. + * + * @param intent intent to unregister + */ + void unRegister(Intent intent); + + /** + * Replace the profile intents in intentNameList with the real concrete intent. + * + * @param intentNameList intent list that may contains profile intents + * @param artifact QName of SCA artifact + * @return concrete intents list + */ + Collection<IntentName> inlineProfileIntent(Collection<IntentName> intentNameList, QName artifact); + + /** + * Whether the intent is appplicable for specified SCA artifact. + * + * @param intentName name of intent + * @param artifact QName of SCA artifact + * @return Whether the intent is appplicable for specified SCA artifact + */ + boolean isApplicable(IntentName intentName, QName artifact); + + /** + * Get a list including all qualified intents for a qulifiable intent. + * + * @param qualifiable qualifiable intent + * @param artifact QName of SCA artifact + * @return list including all qualified intents for a qulifiable intent. + */ + Collection<IntentName> getQualifiedIntents(IntentName qualifiable, QName artifact); + + /** + * Whether the intent is a qualified. + * + * @param name intent name. + * @return whether the intent is a qualified + */ + boolean isQualifiedIntent(IntentName name); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyBuilderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyBuilderRegistry.java new file mode 100644 index 0000000000..c7f8016cfa --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyBuilderRegistry.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.policy; + +/** + * A registry for policy builders that dispatches to the appropriate builder when converting an assembly to runtime + * artifacts. Policy builders operate on either a source- or target-side wires. + * + * @version $Rev$ $Date$ + * @deprecated + */ +public interface PolicyBuilderRegistry { + + int INITIAL = 0; + int EXTENSION = 1; + int FINAL = 2; + + /** + * Registers a target-side policy builder. Called by extensions to register their builders. + * + * @param phase the phase hwne the builder must be run + * @param builder the builder to register + */ + void registerTargetBuilder(int phase, TargetPolicyBuilder builder); + + /** + * Registers a source-side policy builder. Called by extensions to register their builders. + * + * @param phase the phase hwne the builder must be run + * @param builder the builder to register + */ + void registerSourceBuilder(int phase, SourcePolicyBuilder builder); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyEngine.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyEngine.java new file mode 100644 index 0000000000..fd4ba129d5 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyEngine.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.policy; + +import java.util.Collection; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.IntentName; +import org.apache.tuscany.spi.model.PolicyModel; + +/** + * Responsible for matching concrete policy artifacts required by abstract intent name. + */ +public interface PolicyEngine { + + /** + * Retrieve policies which match the intents requirement on a SCA artifact. See SCA policy frame spec. 1.4.5 Guided + * Selection of PolicySets using Intents + * + * @param requires Intent names requred by the SCA artifact + * @param policySetName PolicySet names specify on the SCA artifact explicitly + * @param artifactType QName of SCA artifact type, which may be a abstract artifact type + * @return Collection contains all policy matching the intent requirement + */ + Collection<PolicyModel> getPolicy(IntentName[] requires, QName[] policySetName, QName artifactType); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicySetContainer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicySetContainer.java new file mode 100644 index 0000000000..f7a9e0922a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicySetContainer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.policy; + +import java.util.Collection; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.PolicySet; + +/** + * The host for PolicySet. + */ +public interface PolicySetContainer { + + /** + * Get all PolicySet of this container + * + * @return Collection contains all PolicySet of this container + */ + Collection<PolicySet> getAllPolicySet(); + + /** + * Get PolicySet by name. + * + * @param name QName of PolicySet. + * @return PolicySet with specified name + */ + PolicySet getPolicySet(QName name); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SCATypeManager.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SCATypeManager.java new file mode 100644 index 0000000000..3a5127f014 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SCATypeManager.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.policy; + +import javax.xml.namespace.QName; + +public interface SCATypeManager { + + /** + * Whether the <code>subType</code> is a sub type of <code>type</code> or the type itself. + */ + boolean isTypeOf(QName subType, QName type); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilder.java new file mode 100644 index 0000000000..677ceaab30 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilder.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.policy; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.wire.Wire; + +/** + * Implementations contribute {@link org.apache.tuscany.spi.wire.Interceptor}s to handle source-side policy on a wire. + * + * @version $$Rev$$ $$Date$$ + * @deprecated + */ +public interface SourcePolicyBuilder { + + /** + * Callback for attaching policy to a source-side wire + * + * @param definition the service definition + * @param wire the wire to attach policy to + * @throws BuilderException + */ + void build(ReferenceDefinition definition, Wire wire) throws BuilderException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtension.java new file mode 100644 index 0000000000..d577ae97bf --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtension.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.policy; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * A runtime extension point for {@link SourcePolicyBuilder}s + * + * @version $Rev$ $Date$ + */ +@EagerInit +public abstract class SourcePolicyBuilderExtension implements SourcePolicyBuilder { + protected int phase = PolicyBuilderRegistry.EXTENSION; + private PolicyBuilderRegistry registry; + + @Reference + public void setRegistry(PolicyBuilderRegistry registry) { + this.registry = registry; + } + + @Property + public void setPhase(int phase) { + this.phase = phase; + } + + @Init + public void init() { + registry.registerSourceBuilder(phase, this); + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilder.java new file mode 100644 index 0000000000..f26c7fc4ad --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilder.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.policy; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.model.ServiceDefinition; +import org.apache.tuscany.spi.wire.Wire; + +/** + * Implementations contribute {@link org.apache.tuscany.spi.wire.Interceptor}s to handle target-side policy on a wire. + * + * @version $$Rev$$ $$Date$$ + * @deprecated + */ +public interface TargetPolicyBuilder { + + /** + * Callback for attaching policy to a target-side wire + * + * @param definition the service definition + * @param wire the wire to attach policy to + * @throws BuilderException + */ + void build(ServiceDefinition definition, Wire wire) throws BuilderException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtension.java new file mode 100644 index 0000000000..3b01cd457f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtension.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.policy; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * A runtime extension point for {@link org.apache.tuscany.spi.policy.SourcePolicyBuilder}s + * + * @version $Rev$ $Date$ + */ +@EagerInit +public abstract class TargetPolicyBuilderExtension implements TargetPolicyBuilder { + protected int phase = PolicyBuilderRegistry.EXTENSION; + private PolicyBuilderRegistry registry; + + @Reference + public void setRegistry(PolicyBuilderRegistry registry) { + this.registry = registry; + } + + @Property + public void setPhase(int phase) { + this.phase = phase; + } + + @Init + public void init() { + registry.registerTargetBuilder(phase, this); + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolutionException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolutionException.java new file mode 100644 index 0000000000..fd7394b6dd --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolutionException.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.resolver; + +import org.apache.tuscany.api.TuscanyException; + +/** + * Denotes an error during the resolve phase as an assembly is evaluated + * + * @version $Rev$ $Date$ + */ +public abstract class ResolutionException extends TuscanyException { + + public ResolutionException() { + } + + public ResolutionException(String message) { + super(message); + } + + public ResolutionException(String message, String identifier) { + super(message, identifier); + } + + public ResolutionException(String message, Throwable cause) { + super(message, cause); + } + + public ResolutionException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public ResolutionException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/Resolver.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/Resolver.java new file mode 100644 index 0000000000..30ccfb2c2e --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/Resolver.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.resolver; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Implementations are responsible for resolving resources referenced by an assembly model object + * + * @version $Rev$ $Date$ + */ +public interface Resolver<T extends ModelObject> { + + /** + * Processes a model object, resolving resources referenced by it + * + * @param registry the resolver registry to callback when processing sub-elements + * @param object the model object to process + * @throws ResolutionException + */ + void resolve(ResolverRegistry registry, T object) throws ResolutionException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolverRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolverRegistry.java new file mode 100644 index 0000000000..c0c7fdbbab --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolverRegistry.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.resolver; + +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Registry for resolvers that handle resolution of resources referenced by assembly model elements + * <p/> + * Resolvers are contributed by system extensions + * + * @version $Rev$ $Date$ + */ +public interface ResolverRegistry { + /** + * Register a resolver for a model type. + * + * @param modelClass the type model element the resolver handles + * @param resolver the resolver to be registered + */ + <T extends ModelObject> void register(Class<T> modelClass, Resolver<T> resolver); + + /** + * Unregister a resolver for a model type. + * + * @param modelClass the model type whose builder should be unregistered + */ + <T extends ModelObject> void unregister(Class<T> modelClass); + + /** + * Initiates the resolution process + * + * @param object the top-level element to resolve + */ + <T extends ModelObject> void resolve(T object) throws ResolutionException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java new file mode 100644 index 0000000000..777cfbd3e9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services; + +import org.osoa.sca.annotations.Service; + +/** + * Empty interface for a service component that has no operations. + * This can be used as a default service interface by components that + * do not wish the base class to be used as the interface as specified + * by the defaulting rules. + * + * @version $Rev$ $Date$ + */ +@Service +public interface VoidService { +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/Artifact.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/Artifact.java new file mode 100644 index 0000000000..4da522d196 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/Artifact.java @@ -0,0 +1,197 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.artifact; + +import java.net.URL; +import java.util.HashSet; +import java.util.Set; + +/** + * Description of some packaged artifact such as a JAR file or a Composite. + * + * @version $Rev$ $Date$ + */ +public class Artifact { + + /* Artifact group */ + private String group; + + /* Artifact name */ + private String name; + + /* Artifact version */ + private String version; + + /* Artifact classifier */ + private String classifier; + + /* Artifact type */ + private String type; + + /* Artifact url */ + private URL url; + + /* Transitive dependencies */ + private Set<Artifact> dependencies = new HashSet<Artifact>(); + + /** + * Adds a transitive dependency to the artifact. + * + * @param artifact Dependency to be added. + */ + public void addDependency(Artifact artifact) { + dependencies.add(artifact); + } + + /** + * Gets the URLs for all the transitive dependencies. + * + * @return Sets of URLs for all the transitive dependencies. + */ + public Set<URL> getUrls() { + + Set<URL> urls = new HashSet<URL>(); + + for (Artifact artifact : dependencies) { + urls.add(artifact.getUrl()); + } + urls.add(getUrl()); + + return urls; + + } + + /** + * Returns the name of a logical grouping to which this artifact belongs. For example, this might represent the + * original publisher of the artifact. + * + * @return the name of a logical grouping to which this artifact belongs + */ + public String getGroup() { + return group; + } + + /** + * Sets the name of a logical grouping to which this artifact belongs. + * + * @param group the name of a logical grouping to which this artifact belongs + */ + public void setGroup(String group) { + this.group = group; + } + + /** + * Returns the name of an artifact. + * + * @return the name of an artifact + */ + public String getName() { + return name; + } + + /** + * Sets the name of an artifact. + * + * @param name the name of an artifact + */ + public void setName(String name) { + this.name = name; + } + + /** + * Returns the version of an artifact. + * + * @return the version of an artifact + */ + public String getVersion() { + return version; + } + + /** + * Sets the version of an artifact. + * + * @param version the version of an artifact + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * Returns a way of classifying an artifact. This can be used to distinguish variants of an artifact that provide + * the same function but which may have platform specific requirements. For example, it may contain the name of a + * hardware platform for artifacts that contain native code. + * + * @return a way of classifying an artifact + */ + public String getClassifier() { + return classifier; + } + + /** + * Sets a way of classifying an artifact + * + * @param classifier a way of classifying an artifact + */ + public void setClassifier(String classifier) { + this.classifier = classifier; + } + + /** + * Returns the type of artifact. + * + * @return the type of artifact + */ + public String getType() { + return type; + } + + /** + * Sets the type of artifact. + * + * @param type the type of artifact + */ + public void setType(String type) { + this.type = type; + } + + /** + * Returns a URL from which the artifact can be obtained. + * + * @return a URL from which the artifact can be obtained + */ + public URL getUrl() { + return url; + } + + /** + * Sets a URL from which the artifact can be obtained. + * + * @param url a URL from which the artifact can be obtained + */ + public void setUrl(URL url) { + this.url = url; + } + + + public String toString() { + StringBuilder buf = new StringBuilder(); + buf.append(group).append(':').append(name).append(':').append(version).append(':').append(type); + return buf.toString(); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/ArtifactRepository.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/ArtifactRepository.java new file mode 100644 index 0000000000..b0f590e163 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/ArtifactRepository.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.artifact; + +import java.util.Collection; + +/** + * Abstraction for a repository of SCA and other artifacts. + * + * @version $Rev$ $Date$ + */ +public interface ArtifactRepository { + /** + * Resolve an artifact. + * This ensures that the information associated with an artifact is fully populated; + * Specifically, after this operation the URL should contain a location where the artifact can be obtained. + * + * @param artifact the artifact to be resolved + */ + void resolve(Artifact artifact); + + /** + * Resolve a collection of Artifacts. + * + * @param artifacts a collection of artifacts to be resolved + * @see #resolve(Artifact) + */ + void resolve(Collection<? extends Artifact> artifacts); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/ClassLoaderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/ClassLoaderRegistry.java new file mode 100644 index 0000000000..f74d66268b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/ClassLoaderRegistry.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.classloading; + +import java.net.URI; + +/** + * Registry for classloaders available to the local runtime. + * + * @version $Rev$ $Date$ + */ +public interface ClassLoaderRegistry { + /** + * Register a ClassLoader with the runtime. + * + * @param id a unique id for the classloader + * @param classLoader the classloader to register + * @throws DuplicateClassLoaderException if there is already a classloader registered with the same id + */ + void register(URI id, ClassLoader classLoader) throws DuplicateClassLoaderException; + + /** + * Returns the classloader registered with the supplied id, or null if none is registered. + * + * @param id the id for the classloader + * @return the ClassLoader registered with that id, or null + */ + ClassLoader getClassLoader(URI id); + + /** + * Unregister the specified classloader from the system. + * + * @param id the id for the classloader + * @return the classloader that was registed with the id, or null if none + */ + ClassLoader unregister(URI id); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/DuplicateClassLoaderException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/DuplicateClassLoaderException.java new file mode 100644 index 0000000000..77cc836811 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/DuplicateClassLoaderException.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.classloading; + +import org.apache.tuscany.spi.CoreRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class DuplicateClassLoaderException extends CoreRuntimeException { + /** + * Constructor specifying message and the ID of the duplicate classloader. + * + * @param message exception message + * @param identifier the id of the classloader that is already present + */ + public DuplicateClassLoaderException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/AbstractDiscoveryService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/AbstractDiscoveryService.java new file mode 100644 index 0000000000..c42493340f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/AbstractDiscoveryService.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.discovery; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; + +import org.apache.tuscany.host.RuntimeInfo; + +/** + * Abstract implementation of the discovery service. + * + * @version $Revision$ $Date$ + */ +@EagerInit +public abstract class AbstractDiscoveryService implements DiscoveryService { + + /** + * Runtime info. + */ + private RuntimeInfo runtimeInfo; + + /** + * Request listeners. + */ + private Map<QName, RequestListener> requestListenerMap = new ConcurrentHashMap<QName, RequestListener>(); + + /** + * Response listeners. + */ + private Map<QName, ResponseListener> responseListenerMap = new ConcurrentHashMap<QName, ResponseListener>(); + + /** + * Registers a request listener for async messages. + * + * @param messageType Message type that can be handled by the listener. + * @param listener Recipient of the async message. + */ + public void registerRequestListener(QName messageType, RequestListener listener) { + requestListenerMap.put(messageType, listener); + } + + /** + * Registers a response listener for async messages. + * + * @param messageType Message type that can be handled by the listener. + * @param listener Recipient of the async message. + */ + public void registerResponseListener(QName messageType, ResponseListener listener) { + responseListenerMap.put(messageType, listener); + } + + /** + * Sets the runtime info for the runtime using the discovery service. + * + * @param runtimeInfo Runtime info for the runtime using the discovery service. + */ + @Reference + public final void setRuntimeInfo(RuntimeInfo runtimeInfo) { + this.runtimeInfo = runtimeInfo; + } + + /** + * Starts the discovery service. + */ + @Init + public final void start() throws DiscoveryException { + onStart(); + } + + /** + * Stops the discovery service. + */ + @Destroy + public final void stop() throws DiscoveryException { + onStop(); + } + + /** + * Gets the runtime info for the runtime using the discovery service. + * + * @return Runtime info for the runtime using the discovery service. + */ + protected final RuntimeInfo getRuntimeInfo() { + return runtimeInfo; + } + + /** + * Returns the request listener for the specified message type. + * + * @param messageType Message type for the incoming message. + * @return Listener interested in the message type. + */ + public final RequestListener getRequestListener(QName messageType) { + return requestListenerMap.get(messageType); + } + + /** + * Returns the request listener for the specified message type. + * + * @param messageType Message type for the incoming message. + * @return Listener interested in the message type. + */ + public final ResponseListener getResponseListener(QName messageType) { + return responseListenerMap.get(messageType); + } + + /** + * Broadcasts the messages to all runtimes in the domain. + * + * @param content Message content. + * @return The message id. + * @throws DiscoveryException In case of discovery errors. + */ + public int broadcastMessage(XMLStreamReader content) throws DiscoveryException { + return sendMessage(null, content); + } + + /** + * Required to be overridden by sub-classes. + */ + protected abstract void onStart() throws DiscoveryException; + + /** + * Required to be overridden by sub-classes. + */ + protected abstract void onStop() throws DiscoveryException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryException.java new file mode 100644 index 0000000000..f093321e26 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryException.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.discovery; + +import org.apache.tuscany.api.TuscanyException; + +/** + * Checked exception thrown during discovery operations. + * + * @version $Revision$ $Date$ + */ +@SuppressWarnings("serial") +public class DiscoveryException extends TuscanyException { + + /** + * Initialises the exception message. + * + * @param message Message for the exception. + */ + public DiscoveryException(String message) { + super(message); + } + + /** + * Initialises the exception root cause. + * + * @param cause Root cause for the exception. + */ + public DiscoveryException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryService.java new file mode 100644 index 0000000000..5c0a518323 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryService.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 org.apache.tuscany.spi.services.discovery; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +/** + * Defines the abstraction that allows runtimes participating + * in the domain to discover each other and broadcast liveness + * to the admin server that holds the domain's runtime physical + * model and the domain-wide assembly model.. + * + * @version $Revision$ $Date$ + * + */ +public interface DiscoveryService { + + /** + * Sends a message to the specified runtime. The method returns a unique + * message id for the sent message. The consumers can use the message id for + * correlating responses to sent messages. + * + * @param runtimeId Runtime id of recipient. + * @param content Message content. + * @return The message id. + * @throws DiscoveryException In case of discovery errors. + */ + int sendMessage(String runtimeId, XMLStreamReader content) throws DiscoveryException; + + /** + * Broadcasts the messages to all runtimes in the domain. + * + * @param content Message content. + * @return The message id. + * @throws DiscoveryException In case of discovery errors. + */ + int broadcastMessage(XMLStreamReader content) throws DiscoveryException; + + /** + * Registers a request listener for async messages. Request listeners handle + * unslolicited async messages sent by recipients. + * + * @param messageType Message type that can be handled by the listener. + * @param listener Recipient of the async message. + */ + void registerRequestListener(QName messageType, RequestListener listener); + + /** + * Registers a response listener for async messages. Response listeners handle + * async meesages that are received in response to a request message that was + * originally sent. + * + * @param messageType Message type that can be handled by the listener. + * @param listener Recipient of the async message. + */ + void registerResponseListener(QName messageType, ResponseListener listener); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/RequestListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/RequestListener.java new file mode 100644 index 0000000000..8729757a6b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/RequestListener.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.discovery; + +import javax.xml.stream.XMLStreamReader; + +/** + * Message listener for propogating callbacks. Request listeners handle + * unslolicited async messages sent by recipients. + * + * @version $Revision$ $Date$ + * + */ +public interface RequestListener { + + /** + * Callback for propogating async messages. + * @param content Message content. + * @return Response to the request message. + */ + XMLStreamReader onRequest(XMLStreamReader content); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/ResponseListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/ResponseListener.java new file mode 100644 index 0000000000..88411ac660 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/ResponseListener.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.discovery; + +import javax.xml.stream.XMLStreamReader; + +/** + * Message listener for propogating callbacks. Response listeners handle async meesages that are received in response to + * a request message that was originally sent. + * + * @version $Revision$ $Date$ + */ +public interface ResponseListener { + + /** + * Callback for propogating async messages. + * + * @param content Message content. + * @param messageId optional message id if this was in response to a message that was sent. + */ + void onResponse(XMLStreamReader content, int messageId); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/management/TuscanyManagementService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/management/TuscanyManagementService.java new file mode 100644 index 0000000000..10c2215bf6 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/management/TuscanyManagementService.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.management; + +import org.apache.tuscany.host.management.ManagementService; +import org.apache.tuscany.spi.component.Component; + +/** + * Interface for the management service abstraction. The implementaion + * could be based on a variety of technologies including JMX, WSDM, + * SNMP etc. + * + * @version $Revision$ $Date$ + */ +public interface TuscanyManagementService extends ManagementService<Component> { + + /** + * Registers a component for management. + * + * @param name Name of the component. + * @param component Component to be registered. + */ + void registerComponent(String name, Component component); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/DuplicateRecordException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/DuplicateRecordException.java new file mode 100644 index 0000000000..1210d05f5a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/DuplicateRecordException.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.store; + +/** + * thrown when a record already exists during an insert operation + * + * @version $Rev$ $Date$ + */ +public class DuplicateRecordException extends StoreWriteException { + + public DuplicateRecordException(String owner, String identifier) { + super(null, owner, identifier); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/RecoveryListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/RecoveryListener.java new file mode 100644 index 0000000000..186d741c04 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/RecoveryListener.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.store; + +import java.util.UUID; + +/** + * Implementations receive callback events during a store recovery operation + * + * @version $Rev$ $Date$ + */ +public interface RecoveryListener { + + /** + * Signals the start of a recovery + */ + void onBegin(); + + /** + * Received when a record is recovered + * + * @param id + */ + void onRecord(UUID id); + + /** + * Signals the end of recovery + */ + void onEnd(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/Store.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/Store.java new file mode 100644 index 0000000000..7a09f90811 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/Store.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.store; + +import org.apache.tuscany.spi.component.SCAObject; +import org.apache.tuscany.spi.event.EventPublisher; + +/** + * Implementations provide a persistent store for runtime data such as conversational state. A persistent store could be + * implemented in a durable fashion using JDBC or a journaling system, or using a non-durable mechanism such as an + * in-memory map. + * + * @version $Rev$ $Date$ + */ +public interface Store extends EventPublisher { + + /* Used to indicate an the default expiration offset for records for the store */ + long DEFAULT_EXPIRATION_OFFSET = -1; + + /* Used to indicate an entry should not expire */ + long NEVER = -2; + + /** + * Adds the given record to the store. Implementations may choose different strategies for writing data such as + * write-through or write-behind. + * + * @param owner the instance owner + * @param id the unique id of the record + * @param object the object representing the data to write + * @param expiration the time in milliseconds when the entry expires + * @throws StoreWriteException if an error occurs during the write operation + */ + void insertRecord(SCAObject owner, String id, Object object, long expiration) throws StoreWriteException; + + /** + * Updates a given record in the store, overwriting previous information. + * + * @param owner the instance owner + * @param id the unique id of the record + * @param object the object representing the data to write + * @param expiration the time in milliseconds when the entry expires + * @throws StoreWriteException + */ + void updateRecord(SCAObject owner, String id, Object object, long expiration) throws StoreWriteException; + + /** + * Returns the deserialized object in the store corresponding to the given id + * + * @param owner the instance owner + * @param id the unique id of the record + * @return the deserialized object or null if one is not found + * @throws StoreReadException + */ + Object readRecord(SCAObject owner, String id) throws StoreReadException; + + /** + * Removes a record from the store + * + * @param owner the instance owner + * @param id the unique id of the record + * @throws StoreWriteException + */ + void removeRecord(SCAObject owner, String id) throws StoreWriteException; + + /** + * Removes all records from the store + * + * @throws StoreWriteException + */ + void removeRecords() throws StoreWriteException; + + /** + * Initiates a recovery operation, for example during restart after a crash + * + * @param listener the listener to receive recovery callback events + * @throws StoreReadException + */ + void recover(RecoveryListener listener) throws StoreReadException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreException.java new file mode 100644 index 0000000000..59f1797490 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreException.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 org.apache.tuscany.spi.services.store; + +import org.apache.tuscany.api.TuscanyException; + +/** + * Represents a generic exception thrown by a <code>Store</code> + * + * @version $Rev$ $Date$ + */ +public class StoreException extends TuscanyException { + private final String owner; + + public StoreException(String message, String owner, String identifier) { + super(message, identifier); + this.owner = owner; + } + + public StoreException(String message, String owner, String identifier, Throwable cause) { + super(message, identifier, cause); + this.owner = owner; + } + + public StoreException(String message, String owner, Throwable cause) { + super(message, cause); + this.owner = owner; + } + + public StoreException(Throwable cause) { + super(cause); + owner = null; + } + + public String getOwner() { + return owner; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreExpirationEvent.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreExpirationEvent.java new file mode 100644 index 0000000000..fbb38dd362 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreExpirationEvent.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 org.apache.tuscany.spi.services.store; + +import org.apache.tuscany.spi.component.SCAObject; +import org.apache.tuscany.spi.event.Event; + +/** + * Fired when a store implementation expires a resource + * + * @version $Rev$ $Date$ + */ +public class StoreExpirationEvent implements Event { + private Object source; + private SCAObject owner; + private Object instance; + + /** + * Constructor. + * + * @param source the source of the event + * @param owner the owner of the expiring object + * @param instance the expiring object + */ + public StoreExpirationEvent(Object source, SCAObject owner, Object instance) { + assert source != null; + assert owner != null; + assert instance != null; + this.source = source; + this.owner = owner; + this.instance = instance; + } + + public Object getSource() { + return source; + } + + /** + * Returns the owner of the expiring object. + * + * @return the owner of the expiring object. + */ + public SCAObject getOwner() { + return owner; + } + + /** + * Returns the expiring object. + * + * @return the expiring object. + */ + public Object getInstance() { + return instance; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreMonitor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreMonitor.java new file mode 100644 index 0000000000..f3bbbf0b73 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreMonitor.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.store; + +import org.apache.tuscany.api.annotation.LogLevel; + +/** + * A generic monintor interface for services to log events + * + * @version $Rev$ $Date$ + */ +public interface StoreMonitor { + + /** + * Signals the service has started + * + * @param msg + */ + @LogLevel("DEBUG") + void start(String msg); + + /** + * Signals the service has been shutdown + * + * @param msg + */ + @LogLevel("DEBUG") + void stop(String msg); + + /** + * Fired when recovery is started + */ + @LogLevel("DEBUG") + void beginRecover(); + + /** + * Fired when recovery is completed + */ + @LogLevel("DEBUG") + void endRecover(); + + /** + * Fired when a record is processed during recovery + * + * @param recordId the id of the record being recovered + */ + @LogLevel("DEBUG") + void recover(Object recordId); + + /** + * Signals an error event + * + * @param e the error + */ + @LogLevel("ERROR") + void error(Throwable e); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreReadException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreReadException.java new file mode 100644 index 0000000000..0f46ac6878 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreReadException.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.store; + +/** + * Thrown when an error occurs reading from persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreReadException extends StoreException { + + public StoreReadException(Throwable cause) { + super(cause); + } + + public StoreReadException(String message, String owner, String identifier) { + super(message, owner, identifier); + } + + public StoreReadException(String owner, String identifier, Throwable throwable) { + super(owner, identifier, throwable); + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreWriteException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreWriteException.java new file mode 100644 index 0000000000..9eef91db9a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreWriteException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.store; + +/** + * Thrown when an error occurs writing to persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreWriteException extends StoreException { + + public StoreWriteException(String message, String owner, String identifier) { + super(message, owner, identifier); + } + + public StoreWriteException(String message, String owner, String identifier, Throwable cause) { + super(message, owner, identifier, cause); + } + + public StoreWriteException(String message, String owner, Throwable cause) { + super(message, owner, cause); + } + + public StoreWriteException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListener.java new file mode 100644 index 0000000000..9675cdce53 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListener.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.work; + +/** + * A callback inyterface that can be optionally used for registering + * interest in status of asynchronously scheduled unit of work. + * + */ +public interface NotificationListener<T extends Runnable> { + + /** + * Callback method when the unit of work is accepted. + * + * @param work Work that was accepted. + */ + void workAccepted(T work); + + /** + * Callback method when the unit of work is successfully completed. + * + * @param work Work that was succesfully completed. + */ + void workCompleted(T work); + + /** + * Callback when the unit of work is started. + * + * @param work Unit of work that was started. + */ + void workStarted(T work); + + /** + * Callback when the unit of work is rejected. + * + * @param work Unit of work that was rejected. + */ + void workRejected(T work); + + /** + * Callnack when the unit of work fails to complete. + * + * @param work Unit of work that failed to complete. + * @param error Error that caused the unit of work to fail. + */ + void workFailed(T work, Throwable error); + + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListenerAdaptor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListenerAdaptor.java new file mode 100644 index 0000000000..8192f9db1d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListenerAdaptor.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 org.apache.tuscany.spi.services.work; + +/** + * Adaptor class for the notification listsner. + * + * @version $Revision$ $Date$ + * + */ +public class NotificationListenerAdaptor<T extends Runnable> implements NotificationListener<T> { + + /** + * Callback method when the unit of work is accepted. + * + * @param work Work that was accepted. + */ + public void workAccepted(T work) { + } + + /** + * Callback method when the unit of work is successfully completed. + * + * @param work Work that was succesfully completed. + */ + public void workCompleted(T work) { + } + + /** + * Callback when the unit of work is started. + * + * @param work Unit of work that was started. + */ + public void workStarted(T work) { + } + + /** + * Callback when the unit of work is rejected. + * + * @param work Unit of work that was rejected. + */ + public void workRejected(T work) { + } + + /** + * Callnack when the unit of work fails to complete. + * + * @param work Unit of work that failed to complete. + * @param error Error that caused the unit of work to fail. + */ + public void workFailed(T work, Throwable error) { + error.printStackTrace(); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkScheduler.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkScheduler.java new file mode 100644 index 0000000000..0824990c93 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkScheduler.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.work; + +/** + * Defines the contract for scheduling asychronous units of work. + * + * <p> + * Units of work can be scheduled with an optional <code>NotificationListener</code>. + * If a notification listener is specified, the caller will be notified regarding the + * status of the work. The unit of work can either be completed, rejected or completed + * with an error. If the work completed with an error, the caller is notfied with the + * error details. + * </p> + * + */ +public interface WorkScheduler { + + /** + * Schedules a unit of work for future execution. The notification listener + * is used to register interest in callbacks regarding the status of the work. + * + * @param work The unit of work that needs to be asynchronously executed. + * @param listener Notification listener for callbacks. + */ + <T extends Runnable>void scheduleWork(T work, NotificationListener<T> listener); + + /** + * Schedules a unit of work for future execution. The notification listener + * is used to register interest in callbacks regarding the status of the work. + * + * @param work The unit of work that needs to be asynchronously executed. + */ + <T extends Runnable>void scheduleWork(T work); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkSchedulerException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkSchedulerException.java new file mode 100644 index 0000000000..d13edab6a7 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkSchedulerException.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.services.work; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * Exception thrown by the work scheduler in case of unexpected exceptions. + * + * @version $Rev$ $Date$ + * + */ +@SuppressWarnings("serial") +public class WorkSchedulerException extends TuscanyRuntimeException { + + /** + * Wraps the root cause. + * + * @param cause Root cause for the exception. + */ + public WorkSchedulerException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/UriHelper.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/UriHelper.java new file mode 100644 index 0000000000..07067a59cf --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/UriHelper.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.util; + +import java.net.URI; + +/** + * Utility methods for handling URIs + * + * @version $Rev$ $Date$ + */ +public final class UriHelper { + + private UriHelper() { + } + + /** + * Returns the base name for a component URI, e.g. 'Bar' for 'sca://foo/Bar' + * + * @param uri the URI to parse + * @return the base name + */ + public static String getBaseName(URI uri) { + String s = uri.toString(); + int pos = s.lastIndexOf('/'); + if (pos > -1) { + return s.substring(pos + 1); + } else { + return s; + } + } + + public static URI getDefragmentedName(URI uri) { + if (uri.getFragment() == null) { + return uri; + } + String s = uri.toString(); + int pos = s.lastIndexOf('#'); + return URI.create(s.substring(0, pos)); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/stax/StaxUtil.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/stax/StaxUtil.java new file mode 100644 index 0000000000..9b99c78ab2 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/stax/StaxUtil.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.util.stax; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +/** + * Utility for stax operations. + * + * @version $Revision$ $Date$ + */ +public abstract class StaxUtil { + + /** + * XML input factory. + */ + private static final XMLInputFactory XML_FACTORY = + XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", StaxUtil.class.getClassLoader()); + + private StaxUtil() { + } + + /** + * Serializes the infoset in the stream reader. + * + * @param reader Stream reader. + * @return Serialized XML. + * @throws XMLStreamException In case of an xml stream error. + */ + public static String serialize(XMLStreamReader reader) throws XMLStreamException { + + try { + + StringBuffer xml = new StringBuffer(); + + int event = reader.getEventType(); + while (true) { + + switch (event) { + case XMLStreamConstants.START_ELEMENT: + onStartElement(reader, xml); + onNsMappings(reader, xml); + onAttributes(reader, xml); + xml.append(">"); + break; + case XMLStreamConstants.CHARACTERS: + if (reader.isWhiteSpace()) { + break; + } + xml.append(reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + onEndElement(reader, xml); + break; + } + + if (!reader.hasNext()) { + break; + } + event = reader.next(); + + } + return xml.toString(); + + } finally { + reader.close(); + } + + } + + /** + * Creates a stream reader to the serialized XML. + * + * @param xml Serialized XML to which reader is to be created. + * @return XML stream reader instance. + * @throws XMLStreamException In case of an xml stream error. + */ + public static XMLStreamReader createReader(String xml) throws XMLStreamException { + + InputStream in = new ByteArrayInputStream(xml.getBytes()); + return XML_FACTORY.createXMLStreamReader(in); + + } + + /** + * Creates a stream reader to the serialized XML. + * + * @param xml XML stream to which reader is to be created. + * @return XML stream reader instance. + * @throws XMLStreamException In case of an xml stream error. + */ + public static XMLStreamReader createReader(InputStream xml) throws XMLStreamException { + + return XML_FACTORY.createXMLStreamReader(xml); + + } + + /** + * Returns the qualified name of the document element. + * + * @param xml Serialized xml that needs to be checked. + * @return Qualified name of the document element. + * @throws XMLStreamException In case of an xml stream error. + */ + public static QName getDocumentElementQName(String xml) throws XMLStreamException { + + XMLStreamReader reader = null; + try { + reader = createReader(xml); + reader.next(); + return reader.getName(); + } finally { + if (reader != null) { + reader.close(); + } + } + + } + + /* + * Renders end element markup. + */ + private static void onEndElement(XMLStreamReader reader, StringBuffer xml) { + String name = getName(reader); + xml.append("</"); + xml.append(name); + xml.append(">"); + } + + /* + * Gets the fully-qualified name of the element. + */ + private static String getName(XMLStreamReader reader) { + QName qname = reader.getName(); + String namePrefix = qname.getPrefix(); + String localPart = qname.getLocalPart(); + return namePrefix == null || "".equals(namePrefix) ? localPart : namePrefix + ":" + localPart; + } + + /* + * Render the attributes. + */ + private static void onAttributes(XMLStreamReader reader, StringBuffer xml) { + int n = reader.getAttributeCount(); + for (int i = 0; i < n; ++i) { + xml.append(' '); + xml.append(reader.getAttributeLocalName(i)); + xml.append('='); + xml.append('\''); + xml.append(reader.getAttributeValue(i)); + xml.append('\''); + } + } + + /* + * Renedr namespace mappings. + */ + private static void onNsMappings(XMLStreamReader reader, StringBuffer xml) { + int n = reader.getNamespaceCount(); + for (int i = 0; i < n; ++i) { + String prefix = reader.getNamespacePrefix(i); + xml.append(" xmlns"); + if (prefix != null) { + xml.append(':').append(prefix); + } + xml.append('='); + xml.append('\''); + xml.append(reader.getNamespaceURI(i)); + xml.append('\''); + } + } + + /* + * Render start element. + */ + private static void onStartElement(XMLStreamReader reader, StringBuffer xml) { + xml.append("<"); + String name = getName(reader); + xml.append(name); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java new file mode 100644 index 0000000000..7ad42cf41d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.component.WorkContext; + +/** + * Base class for performing invocations on a wire. Subclasses are responsible for retrieving and supplying the + * appropriate chain, target invoker, and invocation arguments. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractInvocationHandler { + protected boolean conversational; + private boolean conversationStarted; + + protected AbstractInvocationHandler(boolean conversational) { + this.conversational = conversational; + } + + public AbstractInvocationHandler() { + } + + @Deprecated + protected Object invoke(InvocationChain chain, + TargetInvoker invoker, + Object[] args, + Object correlationId, + LinkedList<URI> callbackUris, WorkContext workContext) + throws Throwable { + Interceptor headInterceptor = chain.getHeadInterceptor(); + if (headInterceptor == null) { + try { + // short-circuit the dispatch and invoke the target directly + TargetInvoker targetInvoker = chain.getTargetInvoker(); + if (targetInvoker == null) { + String name = chain.getOperation().getName(); + throw new AssertionError("No target invoker [" + name + "]"); + } + return targetInvoker.invokeTarget(args, TargetInvoker.NONE, workContext); + } catch (InvocationTargetException e) { + // the cause was thrown by the target so throw it + throw e.getCause(); + } + } else { + Message msg = new MessageImpl(); + msg.setWorkContext(workContext); + msg.setTargetInvoker(invoker); + msg.setCorrelationId(workContext.getCorrelationId()); + msg.setCallbackUris(workContext.getCallbackUris()); + Operation operation = chain.getOperation(); + ServiceContract contract = operation.getServiceContract(); + if (contract.isConversational()) { + int sequence = chain.getOperation().getConversationSequence(); + if (sequence == Operation.CONVERSATION_END) { + msg.setConversationSequence(TargetInvoker.END); + conversationStarted = false; + } else if (sequence == Operation.CONVERSATION_CONTINUE) { + if (conversationStarted) { + msg.setConversationSequence(TargetInvoker.CONTINUE); + } else { + conversationStarted = true; + msg.setConversationSequence(TargetInvoker.START); + } + } + } + msg.setBody(args); + // dispatch the wire down the chain and get the response + Message resp = headInterceptor.invoke(msg); + Object body = resp.getBody(); + if (resp.isFault()) { + throw (Throwable) body; + } + return body; + } + } + + protected Object invokeTarget(InvocationChain chain, + Object[] args, + Object correlationId, + LinkedList<Wire> callbackWires) + throws Throwable { + Interceptor headInterceptor = chain.getHeadInterceptor(); + assert headInterceptor != null; + Message msg = new MessageImpl(); + if (correlationId != null) { + msg.setCorrelationId(correlationId); + } + if (callbackWires != null) { + msg.setCallbackWires(callbackWires); + } + PhysicalOperationDefinition operation = chain.getPhysicalOperation(); + if (conversational) { + int sequence = operation.getConversationSequence(); + if (sequence == Operation.CONVERSATION_END) { + msg.setConversationSequence(TargetInvoker.END); + conversationStarted = false; + } else if (sequence == Operation.CONVERSATION_CONTINUE) { + if (conversationStarted) { + msg.setConversationSequence(TargetInvoker.CONTINUE); + } else { + conversationStarted = true; + msg.setConversationSequence(TargetInvoker.START); + } + } + } + msg.setBody(args); + // dispatch the wire down the chain and get the response + Message resp = headInterceptor.invoke(msg); + Object body = resp.getBody(); + if (resp.isFault()) { + throw (Throwable) body; + } + return body; + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ChainHolder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ChainHolder.java new file mode 100644 index 0000000000..817599225e --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ChainHolder.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +/** + * A holder used to associate an wire chain with a local copy of a target invoker that was previously cloned from the + * chain master + * + * @version $Rev$ $Date$ + */ +public class ChainHolder implements Cloneable { + InvocationChain chain; + TargetInvoker cachedInvoker; + + public ChainHolder(InvocationChain config) { + this.chain = config; + } + + public InvocationChain getChain() { + return chain; + } + + public TargetInvoker getCachedInvoker() { + return cachedInvoker; + } + + public void setCachedInvoker(TargetInvoker invoker) { + this.cachedInvoker = invoker; + } + + @SuppressWarnings({"CloneDoesntDeclareCloneNotSupportedException"}) + @Override + public ChainHolder clone() { + try { + return (ChainHolder) super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(); + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/IncompatibleServiceContractException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/IncompatibleServiceContractException.java new file mode 100644 index 0000000000..114df5a55c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/IncompatibleServiceContractException.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.wire; + +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; + +import org.apache.tuscany.api.TuscanyException; + +/** + * Denotes imcompatible service contracts for a wire + * + * @version $Rev$ $Date$ + */ +public class IncompatibleServiceContractException extends TuscanyException { + private static final long serialVersionUID = 5127478601823295587L; + private final ServiceContract<?> source; + private final ServiceContract<?> target; + private final Operation<?> sourceOperation; + private final Operation<?> targetOperation; + + public IncompatibleServiceContractException(String message, ServiceContract<?> source, ServiceContract<?> target) { + super(message, (String) null); + this.source = source; + this.target = target; + this.sourceOperation = null; + this.targetOperation = null; + } + + + public IncompatibleServiceContractException(String message, + ServiceContract<?> source, + ServiceContract<?> target, + Operation<?> sourceOperation, Operation<?> targetOperation) { + super(message, (String) null); + this.source = source; + this.target = target; + this.sourceOperation = sourceOperation; + this.targetOperation = targetOperation; + } + + public ServiceContract<?> getTarget() { + return target; + } + + public ServiceContract<?> getSource() { + return source; + } + + public Operation<?> getSourceOperation() { + return sourceOperation; + } + + public Operation<?> getTargetOperation() { + return targetOperation; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Interceptor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Interceptor.java new file mode 100644 index 0000000000..ad38ed1cf1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Interceptor.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 org.apache.tuscany.spi.wire; + +/** + * Synchronous, around-style mediation associated with a client- or target- side wire. + * + * @version $Rev$ $Date$ + */ +public interface Interceptor { + + /** + * Process a synchronous wire + * + * @param msg the request Message for the wire + * @return the response Message from the wire + */ + Message invoke(Message msg); + + /** + * Sets the next interceptor + */ + void setNext(Interceptor next); + + /** + * Returns the next interceptor or null + */ + Interceptor getNext(); + + /** + * Returns true if the interceptor can be optimized away from a wire + */ + boolean isOptimizable(); +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java new file mode 100644 index 0000000000..c034cf6e86 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; + +/** + * A wire consists of 1..n invocation chains associated with the operations of its source service contract. + * <p/> + * Invocation chains may contain </ode>Interceptors</code> that process invocations in an around-style manner. + * Invocation chains are also associated with a <code>TargetInvoker</code> which is responsible for dispatching on the + * target service provider. + * <p/> + * A <code>Message</code> is used to pass data associated with an invocation through the chain. The TargetInvoker is + * passed with the Message through the interceptor stack, if one is present. At last interceptor in the stack, must call + * the TargetInvoker. + * <p/> + * In certain circumstances, the TargetInvoker may be cached in the source-side proxy. Caching allows various + * optimizations such as avoiding target instance resolution when the client-side lifecycle scope is a shorter duration + * than the target. + * + * @version $Rev$ $Date$ + */ +public interface InvocationChain { + /** + * Returns the target operation for this invocation chain. + * + * @return the target operation for this invocation chain + */ + Operation getOperation(); + + /** + * Returns the target physical operation for this invocation chain. + * + * @return the target physical operation for this invocation chain + */ + PhysicalOperationDefinition getPhysicalOperation(); + + /** + * Sets the target invoker to pass down the chain + * + * @param invoker the invoker + */ + void setTargetInvoker(TargetInvoker invoker); + + /** + * Returns the target invoker that is passed down the chain + * + * @return the target invoker + */ + TargetInvoker getTargetInvoker(); + + /** + * Adds an interceptor to the chain + * + * @param interceptor the interceptor to add + */ + void addInterceptor(Interceptor interceptor); + + /** + * Adds an interceptor at the given position in the interceptor stack + * + * @param index the position in the interceptor stack to add the interceptor + * @param interceptor the interceptor to add + */ + void addInterceptor(int index, Interceptor interceptor); + + /** + * Returns the first interceptor in the chain. + * + * @return the first interceptor in the chain + */ + Interceptor getHeadInterceptor(); + + /** + * Returns the last interceptor in the chain. + * + * @return the last interceptor in the chain + */ + Interceptor getTailInterceptor(); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationRuntimeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationRuntimeException.java new file mode 100644 index 0000000000..c2ba19c48a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationRuntimeException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import org.osoa.sca.ServiceRuntimeException; + +/** + * Denotes a runtime exception thrown during an invocation over a wire + * + * @version $Rev$ $Date$ + */ +public class InvocationRuntimeException extends ServiceRuntimeException { + + public InvocationRuntimeException() { + super(); + } + + public InvocationRuntimeException(String message) { + super(message); + } + + public InvocationRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public InvocationRuntimeException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java new file mode 100644 index 0000000000..c67ca4f7b3 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.spi.component.WorkContext; + +/** + * Represents a request, response, or exception flowing through a wire + * + * @version $Rev $Date + */ +public interface Message { + + /** + * Returns the body of the message, which will be the payload or parameters associated with the wire + */ + Object getBody(); + + /** + * Sets the body of the message. + */ + void setBody(Object body); + + /** + * Returns the context associated with this invocation. + * @return the context associated with this invocation + */ + WorkContext getWorkContext(); + + /** + * Sets the context associated with this invocation. + * @param workContext the context associated with this invocation + */ + void setWorkContext(WorkContext workContext); + + /** + * Sets the target invoker to dispatch to when the message passes through the request side of the invocation chain + * + * @Deprecated + */ + void setTargetInvoker(TargetInvoker invoker); + + /** + * Sets the target invoker to dispatch to when the message passes through the request side of the invocation chain + * + * @Deprecated + */ + TargetInvoker getTargetInvoker(); + + /** + * Adds a URI to the ordered list of callback URIs. Callback URIs are used to resolve the correct wire for a + * callback. + * + * @Deprecated + */ + void pushCallbackUri(URI uri); + + /** + * Returns the ordered list of callback URIs. Callback URIs are used to resolve the correct wire for a callback. + * + * @Deprecated + */ + LinkedList<URI> getCallbackUris(); + + /** + * Sets the ordered list of callback URIs. Callback URIs are used to resolve the correct wire for a callback. + * + * @Deprecated + */ + void setCallbackUris(LinkedList<URI> uris); + + /** + * Adds a callback wire to the ordered list of callbacks for the current invocation + * + * @param wire the callback wire + */ + void pushCallbackWire(Wire wire); + + /** + * Returns the ordered list of callback wires for the current invocation + * + * @return the ordered list of callback wires for the current invocation + */ + LinkedList<Wire> getCallbackWires(); + + /** + * Sets the ordered list of callback wires for the current invocation + * + * @param wires the ordered list of callback wires for the current invocation + */ + void setCallbackWires(LinkedList<Wire> wires); + + /** + * Returns the id of the message + */ + Object getMessageId(); + + /** + * Sets the id of the message + */ + void setMessageId(Object messageId); + + /** + * Returns the correlation id of the message or null if one is not available. Correlation ids are used by transports + * for message routing. + */ + Object getCorrelationId(); + + /** + * Sets the correlation id of the message. Correlation ids are used by transports for message routing. + */ + void setCorrelationId(Object correlationId); + + /** + * Determines if the message represents a fault/exception + * + * @return true if the message body is a fault object, false if the body is a normal payload + */ + boolean isFault(); + + /** + * Set the message body with a fault object. After this method is called, isFault() returns true. + * + * @param fault The fault object represents an exception + */ + void setBodyWithFault(Object fault); + + /** + * Returns the conversational sequence the message is associated with, NONE, START, CONTINUE, or END on {@link + * TargetInvoker} + * + * @return the conversational sequence the message is associated with + */ + short getConversationSequence(); + + /** + * Returns the conversational sequence the message is associated with, NONE, START, CONTINUE, or END on {@link + * TargetInvoker} + * + * @param sequence the conversational sequence + */ + void setConversationSequence(short sequence); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageId.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageId.java new file mode 100644 index 0000000000..f179eb79b1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageId.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +/** + * A unique identifier for a message flowing on a wire, potentially end-to-end (ie, through more than one SCAObject to + * SCAObject hop). + */ +public class MessageId { + + private long timestamp; + + public MessageId() { + this.timestamp = System.currentTimeMillis(); + } + + public long getTimestamp() { + return timestamp; + } + + public String toString() { + return "MsgId[" + timestamp + "]"; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + final MessageId messageId = (MessageId) o; + return timestamp == messageId.timestamp; + } + + public int hashCode() { + return (int) (timestamp ^ (timestamp >>> 32)); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java new file mode 100644 index 0000000000..91840ad299 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.spi.component.WorkContext; + +/** + * The default implementation of a message flowed through a wire during an invocation + * + * @version $Rev $Date + */ +public class MessageImpl implements Message { + private Object body; + private TargetInvoker invoker; + private LinkedList<URI> callbackUris; + private LinkedList<Wire> callbackWires; + private Object messageId; + private Object correlationId; + private boolean isFault; + private short conversationSequence; + private WorkContext workContext; + + public MessageImpl(WorkContext workContext, short conversationSequence, Object body) { + this.workContext = workContext; + this.conversationSequence = conversationSequence; + this.body = body; + } + + public MessageImpl() { + } + + public Object getBody() { + return body; + } + + public void setBody(Object body) { + this.isFault = false; + this.body = body; + } + + public WorkContext getWorkContext() { + return workContext; + } + + public void setWorkContext(WorkContext workContext) { + this.workContext = workContext; + } + + public short getConversationSequence() { + return conversationSequence; + } + + public void setConversationSequence(short conversationSequence) { + this.conversationSequence = conversationSequence; + } + + public void setTargetInvoker(TargetInvoker invoker) { + this.invoker = invoker; + } + + public TargetInvoker getTargetInvoker() { + return invoker; + } + + public void pushCallbackUri(URI uri) { + if (callbackUris == null) { + callbackUris = new LinkedList<URI>(); + } + callbackUris.add(uri); + } + + public LinkedList<URI> getCallbackUris() { + return callbackUris; + } + + public void setCallbackUris(LinkedList<URI> callbackRoutingChain) { + this.callbackUris = callbackRoutingChain; + } + + public void pushCallbackWire(Wire wire) { + if (callbackWires == null) { + callbackWires = new LinkedList<Wire>(); + } + callbackWires.add(wire); + } + + public LinkedList<Wire> getCallbackWires() { + return callbackWires; + } + + public void setCallbackWires(LinkedList<Wire> wires) { + this.callbackWires = wires; + } + + public Object getMessageId() { + return messageId; + } + + public void setMessageId(Object messageId) { + this.messageId = messageId; + } + + public Object getCorrelationId() { + return correlationId; + } + + public void setCorrelationId(Object correlationId) { + this.correlationId = correlationId; + } + + public boolean isFault() { + return isFault; + } + + public void setBodyWithFault(Object fault) { + this.isFault = true; + this.body = fault; + } + + public TargetInvoker getInvoker() { + return invoker; + } + + public void setInvoker(TargetInvoker invoker) { + this.invoker = invoker; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyCreationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyCreationException.java new file mode 100644 index 0000000000..4805c75252 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyCreationException.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 org.apache.tuscany.spi.wire; + +import org.apache.tuscany.spi.CoreRuntimeException; + +/** + * Denotes an error creating a proxy + * + * @version $$Rev$$ $$Date$$ + */ +public class ProxyCreationException extends CoreRuntimeException { + public ProxyCreationException() { + } + + public ProxyCreationException(String message) { + super(message); + } + + public ProxyCreationException(String message, String identifier) { + super(message, identifier); + } + + public ProxyCreationException(String message, Throwable cause) { + super(message, cause); + } + + public ProxyCreationException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public ProxyCreationException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java new file mode 100644 index 0000000000..7ea0dd2534 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import java.lang.reflect.Method; +import java.util.List; +import java.util.Map; + +import org.osoa.sca.CallableReference; + +import org.apache.tuscany.spi.model.ServiceContract; + +/** + * Creates proxies that implement Java interfaces and invocation handlers for fronting wires + * + * @version $$Rev$$ $$Date$$ + */ + +public interface ProxyService { + + /** + * Creates a Java proxy for the given wire + * + * @param interfaze the interface the proxy implements + * @param wire the wire to proxy @return the proxy + * @throws ProxyCreationException + * @Deprecated + */ + <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException; + + <T> T createProxy2(Class<T> interfaze, boolean conversational, Wire wire) throws ProxyCreationException; + + + /** + * Creates a Java proxy for the given wire + * + * @param interfaze the interface the proxy implements + * @param wire the wire to proxy @return the proxy + * @param mapping the method to chain holder mapping to use in creating the proxy. Clients may cache and resuse + * this mapping for performance. + * @throws ProxyCreationException + * @Deprecated + */ + <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping) + throws ProxyCreationException; + + /** + * Creates a Java proxy for the service contract callback + * + * @param interfaze the interface the proxy should implement + * @return the proxy + * @throws ProxyCreationException + * @Deprecated + */ + Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException; + + /** + * Creates a Java proxy for the service contract callback + * + * @param interfaze the interface the proxy should implement + * @return the proxy + * @throws ProxyCreationException if an error is encountered during proxy generation + */ + Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException; + + /** + * Cast a proxy to a CallableReference. + * + * @param target a proxy generated by this implementation + * @return a CallableReference (or subclass) equivalent to this prozy + * @throws IllegalArgumentException if the object supplied is not a proxy + */ + <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException; + + /** + * Check the compatiblity of the source and the target service contracts.<p> A wire may only connect a source to a + * target if the target implements an interface that is compatible with the interface required by the source. The + * source and the target are compatible if: + * <p/> + * <ol> <li>the source interface and the target interface MUST either both be remotable or they are both local + * <li>the methods on the target interface MUST be the same as or be a superset of the methods in the interface + * specified on the source <li>compatibility for the individual method is defined as compatibility of the signature, + * that is method name, input types, and output types MUST BE the same. <li>the order of the input and output types + * also MUST BE the same. <li>the set of Faults and Exceptions expected by the source MUST BE the same or be a + * superset of those specified by the service. <li>other specified attributes of the two interfaces MUST match, + * including Scope and Callback interface </ol> + * <p/> + * <p>Please note this test is not symetric: the success of checkCompatibility(A, B) does NOT imply + * checkCompatibility(B, A) + * + * @param source The source service contract + * @param target The target service contract + * @param ignoreCallback Indicate the callback should be checked + * @param silent if true, errors will be thrown if the service contracts are not compatible + * @return true if the service contracts are compatible + * @throws IncompatibleServiceContractException + * If the source service contract is not compatible with the target one + * <p/> + * TODO JFM this method should be moved from this interface to the allocator phase + */ + boolean checkCompatibility(ServiceContract<?> source, + ServiceContract<?> target, + boolean ignoreCallback, + boolean silent) throws IncompatibleServiceContractException; + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvoker.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvoker.java new file mode 100644 index 0000000000..9efa673ece --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvoker.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.spi.component.WorkContext; + +/** + * Implementations are responsible for resolving a target and performing the actual invocation on it, for example, a + * component implementation instance or a service client. + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public interface TargetInvoker extends Cloneable { + /* indicates that no conversational sequence is associated with the message */ + short NONE = 0; + /* indicates that the message initiates a conversation */ + short START = 1; + /* indicates that the message continues a conversation */ + short CONTINUE = 2; + /* indicates that the message ends a conversation */ + short END = 3; + + /** + * Invokes an operation on a target with the given payload. Used in optmized cases where messages do not need to be + * flowed such as in non-proxied wires. + * + * @param payload the invocation payload, typically an array of parameters + * @param sequence if the invocation is part of a conversation, the sequence. Valid values are {@link #NONE} for + * non-conversational, {@link #START} to begin a conversation, {@link #CONTINUE} to continue a + * conversation, or {@link #END} to end a conversation + * @param workContext work context associated with this invocation + * @return the result of the invocation + * @throws InvocationTargetException if there was a problem invoking the target + */ + Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) + throws InvocationTargetException; + + /** + * Invokes an operation on a target with the given message + * + * @throws InvocationRuntimeException + */ + Message invoke(Message msg) throws InvocationRuntimeException; + + /** + * Determines whether the proxy can be cached on the client/source side + */ + boolean isCacheable(); + + /** + * Sets whether the target service instance may be cached by the invoker. This is a possible optimization when a + * wire is configured for a "down-scope" reference, i.e. a reference from a source of a shorter lifetime to a source + * of greater lifetime. + */ + void setCacheable(boolean cacheable); + + /** + * Determines if the target invoker can be discarded during wire optimization + */ + boolean isOptimizable(); + + /** + * Implementations must support deep cloning + */ + Object clone() throws CloneNotSupportedException; +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java new file mode 100644 index 0000000000..7f4f1f84ac --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import java.net.URI; +import java.util.Map; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; + +/** + * The base wire type used to connect references and serviceBindings + * + * @version $$Rev$$ $$Date$$ + */ +public interface Wire { + QName LOCAL_BINDING = new QName("http://tuscany.apache.org/xmlns/sca/binding/1.0", "binding.local"); + + /** + * Returns the URI of the wire source + * + * @return the wire source URI + */ + URI getSourceUri(); + + /** + * Sets the URI of the wire source + * + * @param uri the source uri + */ + void setSourceUri(URI uri); + + /** + * Returns the URI of the wire target + * + * @return the URI of the wire target + */ + URI getTargetUri(); + + /** + * Sets the URI of the wire target + * + * @param uri the URI of the wire target + */ + void setTargetUri(URI uri); + + /** + * Returns the wire binding type + * + * @return the wire binding type + */ + QName getBindingType(); + + /** + * Returns the service contract associated with the the source side of the wire + * + * @return the service contract associated with the wire + * @Deprecated + */ + ServiceContract getSourceContract(); + + /** + * Sets the contract associated with the source side of the wire + * + * @param contract the contract associated with the wire + * @Deprecated + */ + void setSourceContract(ServiceContract contract); + + /** + * Returns the service contract associated with the the target side of the wire + * + * @return the service contract associated with the wire + * @Deprecated + */ + ServiceContract getTargetContract(); + + /** + * Sets the contract associated with the the target side of the wire + * + * @param contract the contract associated with the wire + * @Deprecated + */ + void setTargetContract(ServiceContract contract); + + /** + * Returns true if the wire is optimizable and its invocation chains may be bypassed + * + * @return true if the wire is optimizable and its invocation chains may be bypassed + * @Deprecated + */ + boolean isOptimizable(); + + /** + * Determines if the wire may be optimized + * + * @param optimizable true if the wire is optimizable + * @Deprecated + */ + void setOptimizable(boolean optimizable); + + /** + * Returns the non-proxied target instance for this wire + * + * @return the non-proxied target instance for this wire + * @Deprecated + */ + Object getTargetInstance() throws TargetResolutionException; + + /** + * Sets the target for the wire for optimizations + * + * @param target the target for the wire + * @Deprecated + */ + void setTarget(AtomicComponent target); + + /** + * Returns the invocation chains for service operations associated with the wire + * + * @return the invocation chains for service operations associated with the wire + * @Deprecated + */ + Map<Operation<?>, InvocationChain> getInvocationChains(); + + /** + * Adds the invocation chain associated with the given operation + * + * @param operation the service operation + * @param chain the invocation chain + * @Deprecated + */ + void addInvocationChain(Operation<?> operation, InvocationChain chain); + + /** + * Adds the invocation chain associated with the given operation + * + * @param operation the service operation + * @param chain the invocation chain + * @Deprecated + */ + void addInvocationChain(PhysicalOperationDefinition operation, InvocationChain chain); + + Map<PhysicalOperationDefinition, InvocationChain> getPhysicalInvocationChains(); + + /** + * Returns the invocation chains for callback service operations associated with the wire + * + * @return the invocation chains for callback service operations associated with the wire + * @Deprecated + */ + Map<Operation<?>, InvocationChain> getCallbackInvocationChains(); + + /** + * Adds the callback invocation chain associated with the given operation + * + * @param operation the service operation + * @param chain the invocation chain + * @Deprecated + */ + void addCallbackInvocationChain(Operation<?> operation, InvocationChain chain); + + Map<PhysicalOperationDefinition, InvocationChain> getCallbackPhysicalInvocationChains(); + + void addCallbackInvocationChain(PhysicalOperationDefinition operation, InvocationChain chain); + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessor.java new file mode 100644 index 0000000000..e3ccb155cd --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessor.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +/** + * Implementations are called after wires are decorated with policy and before they are connected. + * + * @version $Rev$ $Date$ + * @deprecated + */ +public interface WirePostProcessor { + + void process(Wire wire); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorExtension.java new file mode 100644 index 0000000000..d335df87b9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorExtension.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +@EagerInit +public abstract class WirePostProcessorExtension implements WirePostProcessor { + protected WirePostProcessorRegistry registry; + + @Reference + public void setRegistry(WirePostProcessorRegistry registry) { + this.registry = registry; + } + + @Init + public void init() { + registry.register(this); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorRegistry.java new file mode 100644 index 0000000000..f012d119c3 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorRegistry.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +/** + * Acts as a delegating <code>WirePostProcessor</code>, delegating post-processing of wires after policies have been + * applied and source an targets have been matched but before they are connected. + * + * @version $Rev$ $Date$ + */ +public interface WirePostProcessorRegistry extends WirePostProcessor { + + + /** + * Registers a post-processor in the runtime + * + * @param processor the processor to register + */ + void register(WirePostProcessor processor); + + /** + * De-registers a post-processor in the runtime + * + * @param processor the processor to de-register + */ + void unregister(WirePostProcessor processor); + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java new file mode 100644 index 0000000000..72739d56c4 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class AssertionTestCase extends TestCase { + /** + * test case that confirms that JRE assertions are enabled + */ + public void testAssertionsAreEnabled() { + try { + assert false; + fail("assertions are not enabled"); + } catch (AssertionError e) { + // ok + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java new file mode 100644 index 0000000000..1e7b2ab67c --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +import junit.framework.TestCase; + +/** + * Tests parsing of naming patters + * + * @version $Rev$ $Date$ + */ +public class QualifiedNameTestCase extends TestCase { + + public void testSimpleName() throws Exception { + QualifiedName name = new QualifiedName("Foo"); + assertEquals("Foo", name.getPartName()); + assertEquals(null, name.getPortName()); + assertEquals("Foo", name.getQualifiedName()); + assertEquals("Foo", name.getFragment()); + assertEquals("Foo", name.toString()); + } + + public void testCompoundName() throws Exception { + QualifiedName name = new QualifiedName("Foo/Bar"); + assertEquals("Foo", name.getPartName()); + assertEquals("Bar", name.getPortName()); + assertEquals("Foo/Bar", name.getQualifiedName()); + assertEquals("Foo#Bar", name.getFragment()); + assertEquals("Foo/Bar", name.toString()); + } + + public void testCompoundMultiName() throws Exception { + try { + new QualifiedName("Foo/Bar/Baz"); + fail("Invalid name exception not thrown"); + } catch (InvalidNameException e) { + // ok; + } + } + + public void testInvalidName() throws Exception { + try { + new QualifiedName("/Foo/Bar"); + fail("Invalid name exception not thrown"); + } catch (InvalidNameException e) { + //expected + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java new file mode 100644 index 0000000000..593b5a992b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi; + +import junit.framework.TestCase; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class TuscanyRuntimeExceptionTestCase extends TestCase { + + public void testIdentifier() throws Exception { + TuscanyRuntimeException e = new TestException("bar", "foo"); + assertEquals("foo", e.getIdentifier()); + } + + public void testEmptyGetMessage() throws Exception { + TuscanyRuntimeException e = new TestException(); + e.getMessage(); + } + + private class TestException extends TuscanyRuntimeException { + + public TestException() { + } + + public TestException(String message, String identifier) { + super(message, identifier); + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java new file mode 100644 index 0000000000..210997b8c8 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.net.URI; + +import org.apache.tuscany.spi.event.Event; +import org.apache.tuscany.spi.event.EventFilter; +import org.apache.tuscany.spi.event.RuntimeEventListener; +import org.apache.tuscany.spi.event.TrueFilter; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractSCAObjectTestCase extends TestCase { + + public void testFireListener() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + object.addListener(listener); + object.publish(event); + } + + public void testRemoveListener() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + object.addListener(listener); + object.removeListener(listener); + object.publish(event); + } + + public void testFalseFilterListener() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + object.addListener(new FalseFilter(), listener); + object.publish(event); + } + + public void testTrueFilterListener() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + object.addListener(new TrueFilter(), listener); + object.publish(event); + } + + public void testToString() throws Exception { + SCAObject object = new TestSCAObject(new URI("foo")); + assertNotNull(object.toString()); + } + + private class TestSCAObject extends AbstractSCAObject { + public TestSCAObject(URI name) { + super(name); + } + + } + + private class TestEvent implements Event { + public Object getSource() { + return null; + } + } + + private class FalseFilter implements EventFilter { + + public boolean match(Event event) { + return false; + } + } + + +} + + + diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.java new file mode 100644 index 0000000000..510e6e4390 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.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 org.apache.tuscany.spi.component; + +import java.io.Serializable; + +/** + * @version $Rev$ $Date$ + */ +@SuppressWarnings({"SerializableHasSerializationMethods"}) +public class MockSCAExternalizable implements Serializable, SCAExternalizable { + private static final long serialVersionUID = 5071815222959279772L; + + private WorkContext context; + private boolean activated; + + public void setWorkContext(WorkContext context) { + this.context = context; + } + + public WorkContext getContext() { + return context; + } + + public void reactivate() throws ReactivationException { + activated = true; + } + + public boolean isActivated() { + return activated; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.java new file mode 100644 index 0000000000..c853f427fb --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.io.Serializable; + +/** + * @version $Rev$ $Date$ + */ +@SuppressWarnings({"SerializableHasSerializationMethods"}) +public class MockSerializable implements Serializable { + private static final long serialVersionUID = 4013396228070042469L; + + private MockSCAExternalizable externalizable; + + public MockSerializable() { + } + + public MockSCAExternalizable getExternalizable() { + return externalizable; + } + + public void setExternalizable(MockSCAExternalizable externalizable) { + this.externalizable = externalizable; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.java new file mode 100644 index 0000000000..ae316bc441 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.component; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectOutputStream; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class SCAObjectInputStreamTestCase extends TestCase { + + public void testSCAExternalizable() throws Exception { + WorkContext context = EasyMock.createMock(WorkContext.class); + MockSCAExternalizable ext = new MockSCAExternalizable(); + MockSerializable serializable = new MockSerializable(); + serializable.setExternalizable(ext); + ByteArrayOutputStream bas = new ByteArrayOutputStream(); + ObjectOutputStream o = new ObjectOutputStream(bas); + o.writeObject(serializable); + o.close(); + ByteArrayInputStream bytes = new ByteArrayInputStream(bas.toByteArray()); + SCAObjectInputStream stream = new SCAObjectInputStream(bytes, context); + MockSerializable deserialized = (MockSerializable) stream.readObject(); + MockSCAExternalizable deserializedExt = deserialized.getExternalizable(); + assertTrue(deserializedExt.isActivated()); + assertEquals(context, deserializedExt.getContext()); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java new file mode 100644 index 0000000000..40843dea94 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.databinding.extension; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import junit.framework.TestCase; + +/** + * + */ +public class DOMHelperTestCase extends TestCase { + private static final QName FOO_NAME = new QName("http://foo", "foo"); + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testDOM() throws Exception { + DocumentBuilder builder = DOMHelper.newDocumentBuilder(); + assertNotNull(builder); + Document document = DOMHelper.newDocument(); + assertNotNull(document); + Element element = DOMHelper.createElement(document, FOO_NAME); + document.appendChild(element); + QName name = DOMHelper.getQName(element); + assertEquals(FOO_NAME, name); + + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java new file mode 100644 index 0000000000..b4b5f6a39a --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.databinding.extension; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.databinding.DataBindingRegistry; +import org.easymock.EasyMock; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * + */ +public class DataBindingExtensionTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testExtension() { + DataBinding1 binding1 = new DataBinding1(Node.class); + assertEquals(Node.class.getName(), binding1.getName()); + assertNotNull(binding1.introspect(Element.class)); + assertNull(binding1.introspect(String.class)); + assertNull(binding1.getWrapperHandler()); + + DataBindingRegistry registry = EasyMock.createMock(DataBindingRegistry.class); + registry.register(binding1); + EasyMock.expect(registry.getDataBinding(Node.class.getName())).andReturn(binding1); + EasyMock.replay(registry); + + binding1.setDataBindingRegistry(registry); + binding1.init(); + assertNotNull(registry.getDataBinding(Node.class.getName())); + + DataBinding1 binding2 = new DataBinding1("dom", Node.class); + assertEquals("dom", binding2.getName()); + } + + private static class DataBinding1 extends DataBindingExtension { + + /** + * @param baseType + */ + public DataBinding1(Class<?> baseType) { + super(baseType); + } + + /** + * @param name + * @param baseType + */ + public DataBinding1(String name, Class<?> baseType) { + super(name, baseType); + } + + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java new file mode 100644 index 0000000000..6ff7909fa3 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.databinding.extension; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.TypeInfo; + +import org.easymock.EasyMock; + +/** + * + */ +public class SimpleTypeMapperExtensionTestCase extends TestCase { + + private static final Map<String, Object> SAMPLE_VALUES = new HashMap<String, Object>(); + + static { + SAMPLE_VALUES.put("anyURI", "http://www.w3.com"); + SAMPLE_VALUES.put("boolean", new String[] {"true", "false", "1", "0"}); + SAMPLE_VALUES.put("byte", new String[] {"-128", "127"}); + SAMPLE_VALUES.put("date", new String[] {"2004-03-15", "2002-09-24-06:00"}); + SAMPLE_VALUES.put("dateTime", "2003-12-25T08:30:00"); + SAMPLE_VALUES.put("decimal", "3.1415292"); + SAMPLE_VALUES.put("double", new String[] {"3.1415292", "INF", "NaN"}); + SAMPLE_VALUES.put("duration", new String[] {"P8M3DT7H33M2S", "P5Y2M10DT15H"}); + SAMPLE_VALUES.put("float", new String[] {"3.1415292", "INF", "NaN"}); + SAMPLE_VALUES.put("gDay", "---11"); + /* + * The value space of xsd:gMonth is the period of one calendar month recurring + * each calendar year (such as the month of April). Its lexical space should + * follow the ISO 8601 syntax for such periods (i.e., -- MM) with an optional + * time zone. + * Tip: There's a typo in the W3C XML Schema Recommendation, in which the format + * is defined as -- MM -- --. Even though an erratum should be published to + * bring the W3C XML Schema inline with ISO 8601, most current schema processors + * expect the (bogus) -- MM -- -- format. + * + * The test might be broken in JDK 1.6 + */ + SAMPLE_VALUES.put("gMonth", "--02--"); + SAMPLE_VALUES.put("gMonthDay", "--02-14"); + SAMPLE_VALUES.put("gYear", "1999"); + SAMPLE_VALUES.put("gYearMonth", "1972-08"); + SAMPLE_VALUES.put("ID", "id-102"); + SAMPLE_VALUES.put("IDREF", "id-102"); + SAMPLE_VALUES.put("IDREFS", "id-102 id-103 id-100"); + SAMPLE_VALUES.put("int", "77"); + SAMPLE_VALUES.put("integer", "77"); + SAMPLE_VALUES.put("long", "214"); + SAMPLE_VALUES.put("negativeInteger", "-123"); + SAMPLE_VALUES.put("nonNegativeInteger", "2"); + SAMPLE_VALUES.put("nonPositiveInteger", "0"); + SAMPLE_VALUES.put("positiveInteger", "500"); + SAMPLE_VALUES.put("short", "476"); + SAMPLE_VALUES.put("string", "Joeseph"); + SAMPLE_VALUES.put("time", "13:02:00"); + SAMPLE_VALUES.put("base64Binary", "TWFu"); + SAMPLE_VALUES.put("hexBinary", "2CDB5F"); + SAMPLE_VALUES.put("QName", "f:foo"); + SAMPLE_VALUES.put("NOTATION", "f:bar"); + } + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testMap() throws Exception { + SimpleTypeMapperExtension extension = new SimpleTypeMapperExtension(); + TransformationContext context = EasyMock.createMock(TransformationContext.class); + Map<Class<?>, Object> metaData = new HashMap<Class<?>, Object>(); + EasyMock.expect(context.getMetadata()).andReturn(metaData).anyTimes(); + EasyMock.replay(context); + + NamespaceContext namespaceContext = EasyMock.createMock(NamespaceContext.class); + EasyMock.expect(namespaceContext.getNamespaceURI(EasyMock.eq("f"))).andReturn("http://foo") + .anyTimes(); + EasyMock.expect(namespaceContext.getPrefix(EasyMock.eq("http://foo"))).andReturn("f").anyTimes(); + EasyMock.replay(namespaceContext); + context.getMetadata().put(NamespaceContext.class, namespaceContext); + for (TypeInfo simpleType : SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.values()) { + String name = simpleType.getQName().getLocalPart(); + Object value = SAMPLE_VALUES.get(name); + if (value instanceof String[]) { + for (String s : (String[])value) { + Object obj = extension.toJavaObject(simpleType, s, context); + String str = extension.toXMLLiteral(simpleType, obj, context); + assertNotNull(str); + // assertTrue("[" + name + "] " + s + " " + str, + // str.contains((String) s)); + } + } else if (value instanceof String) { + Object obj = extension.toJavaObject(simpleType, (String)value, context); + String str = extension.toXMLLiteral(simpleType, obj, context); + assertNotNull(str); + // assertTrue("[" + name + "] " + value + " " + str, + // str.contains((String) value)); + } + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java new file mode 100644 index 0000000000..6f5dfc90e2 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.spi.databinding.extension; + +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.TransformerRegistry; +import org.easymock.EasyMock; +import org.w3c.dom.Node; + +/** + * Test case for TransformerExtension + */ +public class TransformerExtensionTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testExtension() { + MyTransformer transformer = new MyTransformer(); + assertEquals(Node.class.getName(), transformer.getSourceDataBinding()); + assertEquals(XMLStreamReader.class.getName(), transformer.getTargetDataBinding()); + assertEquals(50, transformer.getWeight()); + TransformerRegistry registry = EasyMock.createMock(TransformerRegistry.class); + registry.registerTransformer(EasyMock.isA(Transformer.class)); + EasyMock + .expect(registry.getTransformer(transformer.getSourceDataBinding(), transformer.getTargetDataBinding())) + .andReturn(transformer); + EasyMock.replay(registry); + transformer.setTransformerRegistry(registry); + transformer.init(); + assertSame(transformer, registry.getTransformer(transformer.getSourceDataBinding(), transformer + .getTargetDataBinding())); + } + + private static class MyTransformer extends TransformerExtension<Node, XMLStreamReader> { + + @Override + protected Class getSourceType() { + return Node.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java new file mode 100644 index 0000000000..4693025c11 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.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 org.apache.tuscany.spi.databinding.extension; + +import java.math.BigInteger; +import java.util.Calendar; +import java.util.GregorianCalendar; + +import junit.framework.TestCase; + +/** + * + */ +public class XSDDataTypeConverterTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testConvert() throws Exception { + XSDDataTypeConverter c = new XSDDataTypeConverter(); + assertEquals("123", c.parseAnySimpleType(c.printAnySimpleType("123"))); + assertEquals(true, c.parseBoolean(c.printBoolean(true))); + assertEquals(false, c.parseBoolean(c.printBoolean(false))); + assertEquals(123.0, c.parseDouble(c.printDouble(123.0))); + assertEquals(123.0f, c.parseFloat(c.printFloat(123.0f))); + assertEquals(64, c.parseByte(c.printByte((byte)64))); + assertEquals(123, c.parseInt(c.printInt(123))); + assertEquals(new BigInteger("123456"), c.parseInteger(c.printInteger(new BigInteger("123456")))); + assertEquals(123456L, c.parseLong(c.printLong(123456L))); + assertEquals((short)123, c.parseShort(c.printShort((short)123))); + + Calendar calendar = new GregorianCalendar(); + String s = c.printDate(calendar); + calendar = (GregorianCalendar)c.parseDate(s); + assertEquals(s, c.printDate(calendar)); + + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java new file mode 100644 index 0000000000..9eb96cd2f1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.event; + + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractEventPublisherTestCase extends TestCase { + EventPublisher publisher; + + public void testFireListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + publisher.addListener(listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + public void testRemoveListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + publisher.addListener(listener); + publisher.removeListener(listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + public void testFalseFilterListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + publisher.addListener(new FalseFilter(), listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + public void testTrueFilterListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + publisher.addListener(new TrueFilter(), listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + protected void setUp() throws Exception { + super.setUp(); + publisher = new AbstractEventPublisher() { + }; + } + + private class TestEvent implements Event { + public Object getSource() { + return null; + } + } + + private class FalseFilter implements EventFilter { + + public boolean match(Event event) { + return false; + } + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.java new file mode 100644 index 0000000000..e5d6cfe9f1 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.net.URI; +import java.util.List; + +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractComponentExtensionTestCase extends TestCase { + private Component composite; + + public void testGetService() throws Exception { + Service service = EasyMock.createMock(Service.class); + EasyMock.expect(service.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.replay(service); + composite.register(service); + assertNotNull(composite.getService("service")); + } + + public void testGetDefaultService() throws Exception { + Service service = EasyMock.createMock(Service.class); + EasyMock.expect(service.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.replay(service); + composite.register(service); + assertNotNull(composite.getService(null)); + } + + public void testGetReference() throws Exception { + Reference reference = EasyMock.createMock(Reference.class); + EasyMock.expect(reference.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.replay(reference); + composite.register(reference); + assertNotNull(composite.getReference("service")); + } + + public void testDefaultReference() throws Exception { + Reference reference = EasyMock.createMock(Reference.class); + EasyMock.expect(reference.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.replay(reference); + composite.register(reference); + assertNotNull(composite.getReference(null)); + } + + protected void setUp() throws Exception { + super.setUp(); + composite = new AbstractComponentExtension(new URI("foo")) { + + public Scope getScope() { + return null; + } + + public List<Wire> getWires(String name) { + throw new UnsupportedOperationException(); + } + + public void attachWire(Wire wire) { + throw new UnsupportedOperationException(); + } + + public void attachWires(List<Wire> wires) { + throw new UnsupportedOperationException(); + } + + public void attachCallbackWire(Wire wire) { + throw new UnsupportedOperationException(); + } + + public TargetInvoker createTargetInvoker(String targetName, Operation operation) + throws TargetInvokerCreationException { + return null; + } + + public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation) + throws TargetInvokerCreationException { + return null; + } + }; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java new file mode 100644 index 0000000000..d2e0c70d62 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.net.URI; +import java.util.List; + +import org.apache.tuscany.spi.ObjectCreationException; +import org.apache.tuscany.spi.component.InstanceWrapper; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.TargetInvokerCreationException; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class AtomicComponentExtensionTestCase extends TestCase { + private AtomicComponentExtension ext; + private URI uri; + + public void testURI() { + assertSame(uri, ext.getUri()); + } + + public void testRemoveInstance() throws Exception { + ScopeContainer scopeContainer = EasyMock.createMock(ScopeContainer.class); + EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE); + scopeContainer.remove(ext); + EasyMock.replay(scopeContainer); + ext.setScopeContainer(scopeContainer); + ext.removeInstance(); + EasyMock.verify(scopeContainer); + } + + protected void setUp() throws Exception { + super.setUp(); + uri = URI.create("http://example.com/foo"); + ext = new TestExtension(uri); + } + + private static class TestExtension extends AtomicComponentExtension { + + public TestExtension(URI uri) { + super(uri, null, null, URI.create("composite"), 0, -1, -1); + } + + public TargetInvoker createTargetInvoker(String targetName, Operation operation) + throws TargetInvokerCreationException { + throw new AssertionFailedError(); + } + + public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation) + throws TargetInvokerCreationException { + throw new AssertionFailedError(); + } + + public List<Wire> getWires(String name) { + throw new AssertionFailedError(); + } + + public void attachWire(Wire wire) { + throw new AssertionFailedError(); + } + + public void attachWires(List<Wire> wires) { + throw new AssertionFailedError(); + } + + public void attachCallbackWire(Wire wire) { + throw new AssertionFailedError(); + } + + public Object createInstance() throws ObjectCreationException { + throw new AssertionFailedError(); + } + + public Object getTargetInstance() throws TargetResolutionException { + throw new AssertionFailedError(); + } + + public InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException { + throw new AssertionFailedError(); + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java new file mode 100644 index 0000000000..3aefb37b7f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import junit.framework.TestCase; +import org.easymock.EasyMock; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.eq; + +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.model.Implementation; + +/** + * @version $Rev$ $Date$ + */ +public class ComponentTypeLoaderExtensionTestCase extends TestCase { + + public void testRegistrationDeregistration() throws Exception { + Extension loader = new Extension(); + LoaderRegistry registry = createMock(LoaderRegistry.class); + registry.registerLoader(eq(Implementation.class), eq(loader)); + registry.unregisterLoader(eq(Implementation.class)); + EasyMock.replay(registry); + loader.setLoaderRegistry(registry); + loader.start(); + loader.stop(); + } + + + private class Extension extends ComponentTypeLoaderExtension<Implementation> { + + protected Class<Implementation> getImplementationClass() { + return Implementation.class; + } + + public void load(Implementation implementation, DeploymentContext context) throws LoaderException { + + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java new file mode 100644 index 0000000000..f7f6bc45c0 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.lang.reflect.Type; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.component.ServiceBinding; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeComponentExtensionTestCase extends TestCase { + private Component composite; + + + public void testCreateTargetInvoker() throws Exception { + ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); + EasyMock.expect(binding.createTargetInvoker(EasyMock.eq("service"), EasyMock.isA(Operation.class))) + .andReturn(null); + EasyMock.replay(binding); + List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); + bindings.add(binding); + Service service = EasyMock.createMock(Service.class); + EasyMock.expect(service.getUri()).andReturn(URI.create("composite#service")).atLeastOnce(); + EasyMock.expect(service.getServiceBindings()).andReturn(bindings).atLeastOnce(); + EasyMock.replay(service); + composite.register(service); + Operation<Type> operation = new Operation<Type>("op", null, null, null); + composite.createTargetInvoker("service", operation); + EasyMock.verify(binding); + + } + + protected void setUp() throws Exception { + super.setUp(); + composite = new CompositeComponentExtension(new URI("foo")) { + + public List<Wire> getWires(String name) { + throw new UnsupportedOperationException(); + } + + public void attachWire(Wire wire) { + throw new UnsupportedOperationException(); + } + + public void attachWires(List<Wire> wires) { + throw new UnsupportedOperationException(); + } + + public void attachCallbackWire(Wire wire) { + throw new UnsupportedOperationException(); + } + + }; + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtensionTestCase.java new file mode 100644 index 0000000000..a934f52fc3 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtensionTestCase.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilder; +import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilderRegistry; +import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition; +import org.apache.tuscany.spi.wire.Interceptor; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class InterceptorBuilderExtensionTestCase extends TestCase { + private static final QName QNAME = new QName("builder"); + + public void testRegistration() { + InterceptorBuilderRegistry registry = EasyMock.createMock(InterceptorBuilderRegistry.class); + registry.register(EasyMock.eq(QNAME), EasyMock.isA(InterceptorBuilder.class)); + EasyMock.replay(registry); + InterceptorBuilderExtension builder = new InterceptorBuilderExtension() { + protected QName getName() { + return QNAME; + } + + public Interceptor build(PhysicalInterceptorDefinition definition) throws BuilderException { + return null; + } + }; + + builder.setRegistry(registry); + builder.init(); + EasyMock.verify(registry); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java new file mode 100644 index 0000000000..bf6e1d998d --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.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 org.apache.tuscany.spi.extension; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.model.ModelObject; + +import junit.framework.TestCase; +import org.easymock.EasyMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.isA; + +/** + * @version $Rev$ $Date$ + */ +public class LoaderExtensionTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testRegistrationDeregistration() throws Exception { + LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); + registry.registerLoader(isA(QName.class), isA(Extension.class)); + expectLastCall(); + registry.unregisterLoader(isA(QName.class), isA(Extension.class)); + expectLastCall(); + EasyMock.replay(registry); + Extension loader = new Extension(registry); + loader.start(); + loader.stop(); + } + + + private static class Extension extends LoaderExtension { + + public Extension(LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return new QName(""); + } + + public ModelObject load( + ModelObject object, XMLStreamReader reader, + DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + throw new AssertionError(); + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java new file mode 100644 index 0000000000..4f3d2c8042 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class TargetInvokerExtensionSequenceTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testStart() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); + Target target = EasyMock.createMock(Target.class); + target.invokeStart("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(target); + Message msg = new MessageImpl(); + msg.setWorkContext(context); + msg.pushCallbackUri(from); + msg.setBody("test"); + msg.setConversationSequence(Invoker.START); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + @SuppressWarnings("unchecked") + public void testContinue() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); + Target target = EasyMock.createMock(Target.class); + target.invokeContinue("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(target); + Message msg = new MessageImpl(); + msg.setWorkContext(context); + msg.pushCallbackUri(from); + msg.setBody("test"); + msg.setConversationSequence(Invoker.CONTINUE); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + @SuppressWarnings("unchecked") + public void testEnd() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); + Target target = EasyMock.createMock(Target.class); + target.invokeEnd("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(target); + Message msg = new MessageImpl(); + msg.setWorkContext(context); + msg.pushCallbackUri(from); + msg.setBody("test"); + msg.setConversationSequence(Invoker.END); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + @SuppressWarnings("unchecked") + public void testNone() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + Target target = EasyMock.createMock(Target.class); + target.invokeNone("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(target); + Message msg = new MessageImpl(); + msg.setWorkContext(context); + msg.pushCallbackUri(from); + msg.setBody("test"); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + protected void setUp() throws Exception { + super.setUp(); + + } + + private class Invoker extends TargetInvokerExtension { + private Target target; + + private Invoker(Target target) { + this.target = target; + } + + public Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) throws InvocationTargetException { + if (sequence == NONE) { + target.invokeNone((String) payload); + } else if (sequence == START) { + target.invokeStart((String) payload); + } else if (sequence == CONTINUE) { + target.invokeContinue((String) payload); + } else if (sequence == END) { + target.invokeEnd((String) payload); + } + return null; + } + } + + private interface Target { + void invokeStart(String msg); + + void invokeContinue(String msg); + + void invokeEnd(String msg); + + void invokeNone(String msg); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java new file mode 100644 index 0000000000..f1205544c5 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.extension; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class TargetInvokerExtensionTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testNonBlockingDispatch() { + URI from = URI.create("foo"); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.replay(wire); + WorkContext context; + context = EasyMock.createMock(WorkContext.class); + context.setCallbackUris(EasyMock.isA(LinkedList.class)); + EasyMock.replay(context); + Target target = EasyMock.createMock(Target.class); + target.invoke("test"); + EasyMock.replay(target); + Invoker invoker = new Invoker(target); + Message msg = new MessageImpl(); + msg.setWorkContext(context); + msg.pushCallbackUri(from); + msg.setBody("test"); + invoker.invoke(msg); + EasyMock.verify(wire); + EasyMock.verify(context); + EasyMock.verify(target); + } + + protected void setUp() throws Exception { + super.setUp(); + + } + + private class Invoker extends TargetInvokerExtension { + private Target target; + + private Invoker(Target target) { + this.target = target; + } + + public Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) throws InvocationTargetException { + target.invoke((String) payload); + return null; + } + } + + private interface Target { + void invoke(String msg); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java new file mode 100644 index 0000000000..cee80026f9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.idl.java; + +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findOperation; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; +import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class JavaIDLUtilsTestCase extends TestCase { + private List<Operation<?>> operations; + + public void testNoParamsFindOperation() throws Exception { + Method method = Foo.class.getMethod("foo"); + Operation ret = findOperation(method, operations); + assertEquals("foo", ret.getName()); + assertEquals(0, method.getParameterTypes().length); + } + + public void testParamsFindOperation() throws Exception { + Method method = Foo.class.getMethod("foo", String.class); + Operation ret = findOperation(method, operations); + assertEquals("foo", ret.getName()); + assertEquals(String.class, method.getParameterTypes()[0]); + } + + public void testPrimitiveParamFindOperation() throws NoSuchMethodException { + Method method = Foo.class.getMethod("foo", Integer.TYPE); + Operation<?> operation = findOperation(method, operations); + assertEquals(Integer.TYPE, operation.getInputType().getLogical().get(0).getPhysical()); + } + + protected void setUp() throws Exception { + super.setUp(); + + Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION); + operations = new ArrayList<Operation<?>>(); + operations.add(operation); + + List<DataType<Type>> types = new ArrayList<DataType<Type>>(); + DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + DataType<Type> type = new DataType<Type>(String.class, Object.class); + types.add(type); + operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + operations.add(operation); + + types = new ArrayList<DataType<Type>>(); + type = new DataType<Type>(String.class, Object.class); + DataType<Type> type2 = new DataType<Type>(String.class, Object.class); + types.add(type); + types.add(type2); + inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + operations.add(operation); + + types = new ArrayList<DataType<Type>>(); + type = new DataType<Type>(Integer.class, Object.class); + types.add(type); + inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + operations.add(operation); + + types = new ArrayList<DataType<Type>>(); + type = new DataType<Type>(Integer.TYPE, Object.class); + types.add(type); + inputType = new DataType<List<DataType<Type>>>(Object[].class, types); + operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION); + operations.add(operation); + + } + + private interface Foo { + void foo(); + + void foo(String foo); + + void foo(int b); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java new file mode 100644 index 0000000000..45a3bd4d68 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.implementation.java; + +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.List; + +import org.apache.tuscany.spi.ObjectFactory; +import org.apache.tuscany.spi.deployer.DeploymentContext; + +import junit.framework.TestCase; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractPropertyProcessorTestCase extends TestCase { + + private ImplementationProcessor processor; + + + public void testVisitMethod() throws Exception { + Method method = Foo.class.getMethod("setBar", String.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitMethod(method, type, null); + JavaMappedProperty<?> prop = type.getProperties().get("test"); + assertNotNull(prop.getDefaultValueFactory()); + } + + public void testVisitNoParamsMethod() throws Exception { + Method method = Foo.class.getMethod("setNoParamsBar"); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + try { + processor.visitMethod(method, type, null); + fail(); + } catch (IllegalPropertyException e) { + //expected + } + } + + public void testVisitNonVoidMethod() throws Exception { + Method method = Foo.class.getMethod("setBadBar", String.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + try { + processor.visitMethod(method, type, null); + fail(); + } catch (IllegalPropertyException e) { + //expected + } + } + + public void testDuplicateMethod() throws Exception { + Method method = Foo.class.getMethod("setBar", String.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitMethod(method, type, null); + try { + processor.visitMethod(method, type, null); + fail(); + } catch (DuplicatePropertyException e) { + //expected + } + } + + public void testVisitField() throws Exception { + Field field = Foo.class.getDeclaredField("d"); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitField(field, type, null); + JavaMappedProperty<?> prop = type.getProperties().get("test"); + assertNotNull(prop.getDefaultValueFactory()); + } + + public void testVisitConstructor() throws Exception { + Constructor<Foo> ctor = Foo.class.getConstructor(String.class); + PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = + new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); + processor.visitConstructor(ctor, type, null); + ConstructorDefinition def = type.getConstructorDefinition(); + assertEquals("test", def.getInjectionNames().get(0)); + assertNotNull(type.getProperties().get("test")); + } + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + ImplementationProcessorService service = EasyMock.createMock(ImplementationProcessorService.class); + service.addName(EasyMock.isA(List.class), EasyMock.eq(0), EasyMock.eq("test")); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + ((List<Object>) EasyMock.getCurrentArguments()[0]).add("test"); + return null; + } + }); + EasyMock.replay(service); + processor = new TestProcessor(service); + } + + @Retention(RUNTIME) + private @interface Bar { + + } + + private class TestProcessor extends AbstractPropertyProcessor<Bar> { + + public TestProcessor(ImplementationProcessorService service) { + super(Bar.class, service); + } + + @SuppressWarnings("unchecked") + protected <T> void initProperty(JavaMappedProperty<T> property, + Bar annotation, + DeploymentContext context) { + property.setDefaultValueFactory(EasyMock.createMock(ObjectFactory.class)); + property.setName("test"); + } + + protected String getName(Bar annotation) { + return "test"; + } + } + + + private static class Foo { + + @Bar + protected String d; + + public Foo(String a, @Bar String b) { + } + + public Foo(@Bar String d) { + this.d = d; + } + + @Bar + public void setBar(String d) { + this.d = d; + } + + @Bar + public void setNoParamsBar() { + } + + @Bar + public String setBadBar(String d) { + return null; + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java new file mode 100644 index 0000000000..f8c991f7d4 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.loader; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class LoaderExceptionTestCase extends TestCase { + + public void testResourceURI() throws Exception { + LoaderException e = new LoaderException(); + e.setResourceURI("test"); + assertEquals("test", e.getResourceURI()); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.java new file mode 100644 index 0000000000..c7170e0597 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.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 org.apache.tuscany.spi.model; + +import java.net.URI; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class ComponentTypeTestCase extends TestCase { + + /** + * Verifies fragments are used to retrieve service names + */ + public void testSetServiceName() { + ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type = + new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>(); + ServiceDefinition definition = new ServiceDefinition(); + definition.setUri(URI.create("foo#bar")); + type.add(definition); + assertEquals(definition, type.getServices().get("bar")); + } + + /** + * Verifies fragments are used to retrieve service names + */ + public void testSetReferenceName() { + ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type = + new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>(); + ReferenceDefinition definition = new ReferenceDefinition(); + definition.setUri(URI.create("foo#bar")); + type.add(definition); + assertEquals(definition, type.getReferences().get("bar")); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java new file mode 100644 index 0000000000..d348d2b3c8 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java @@ -0,0 +1,43 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import junit.framework.TestCase;
+
+public class CompositeComponentTypeTestCase extends TestCase {
+
+ public void testWireCreationAndRetrieval() throws Exception {
+ WireDefinition wire1 = new WireDefinition();
+ WireDefinition wire2 = new WireDefinition();
+
+ CompositeComponentType composite = new CompositeComponentType();
+ CompositeComponentType includedComposite = new CompositeComponentType();
+ includedComposite.add(wire1);
+ Include compositeInclude = new Include();
+ compositeInclude.setIncluded(includedComposite);
+
+ composite.add(compositeInclude);
+ composite.add(wire1);
+
+ assertEquals(1, composite.getDeclaredWires().size());
+ assertEquals(wire1, composite.getDeclaredWires().get(0));
+ assertEquals(2, composite.getWires().size());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java new file mode 100644 index 0000000000..698b7835d9 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.Arrays; + +import junit.framework.TestCase; + +public class IntentNameTestCase extends TestCase { + + public void testConstructor() throws Exception { + String case1 = "sec.confidentiality/message/body"; + IntentName intentName = new IntentName(case1); + assertEquals("sec", intentName.getDomain()); + assertEquals(case1, intentName.toString()); + assertTrue(Arrays.equals(new String[]{"confidentiality", "message", "body"}, intentName.getQualifiedNames())); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java new file mode 100644 index 0000000000..de5f1719b0 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import java.util.ArrayList; +import java.util.List; + +import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class OperationTestCase extends TestCase { + + public void testClone() throws Exception { + DataType<Class> stringType = new DataType<Class>("xml:string", String.class, String.class); + List<DataType<Class>> inputTypes = new ArrayList<DataType<Class>>(); + inputTypes.add(stringType); + DataType<List<DataType<Class>>> inputType = + new DataType<List<DataType<Class>>>("xml:string", Object[].class, inputTypes); + + DataType<Class> faultType = new DataType<Class>("xml:foo", String.class, String.class); + List<DataType<Class>> faultTypes = new ArrayList<DataType<Class>>(); + faultTypes.add(faultType); + + Operation<Class> operation1 = + new Operation<Class>("call", inputType, stringType, faultTypes, true, "xml:string", NO_CONVERSATION); + Operation<Class> operation2 = operation1.clone(); + assertEquals(operation1, operation2); + assertEquals(NO_CONVERSATION, operation2.getConversationSequence()); + assertEquals("call", operation2.getName()); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java new file mode 100644 index 0000000000..a8a88626ec --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class ScopeTestCase extends TestCase { + + public void testEquals() throws Exception { + Scope scope = new Scope("COMPOSITE"); + assertTrue(scope.equals(Scope.COMPOSITE)); + } + + public void testEqualsNew() throws Exception { + Scope foo = new Scope("foo"); + Scope foo2 = new Scope("FOO"); + assertTrue(foo.equals(foo2)); + } + + public void testNotEquals() throws Exception { + Scope foo = new Scope("BAR"); + Scope foo2 = new Scope("FOO"); + assertFalse(foo.equals(foo2)); + } + + public void testNotEqualsDifferent() throws Exception { + Scope foo = new Scope("FOO"); + assertFalse(foo.equals(new Bar("FOO"))); + } + + public class Bar { + private String scope; + + public Bar(String scope) { + this.scope = scope; + } + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java new file mode 100644 index 0000000000..4cf98d1542 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.model; + +import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; + +import java.util.Map; +import java.util.HashMap; +import java.lang.reflect.Type; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class ServiceContractTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testAddOperation() throws Exception { + ServiceContract<Type> contract = new TestContract(); + Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION); + Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>(); + ops.put("foo", operation); + contract.setOperations(ops); + assertEquals(contract, operation.getServiceContract()); + assertFalse(operation.isCallback()); + } + + public void testAddCallbackOperation() throws Exception { + ServiceContract<Type> contract = new TestContract(); + Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION); + Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>(); + ops.put("foo", operation); + contract.setCallbackOperations(ops); + assertEquals(contract, operation.getServiceContract()); + assertTrue(operation.isCallback()); + } + + @SuppressWarnings("unchecked") + public void testClone() throws Exception { + ServiceContract<Type> contract = new TestContract(); + Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION); + Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>(); + ops.put("foo", operation); + contract.setOperations(ops); + + operation = new Operation<Type>("bar", null, null, null, false, null, NO_CONVERSATION); + Map<String, Operation<Type>> callbackOps = new HashMap<String, Operation<Type>>(); + ops.put("bar", operation); + contract.setCallbackOperations(callbackOps); + + ServiceContract<Type> copy = (ServiceContract<Type>) contract.clone(); + assertEquals(contract, copy); + } + + + private class TestContract extends ServiceContract<Type> { + + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java new file mode 100644 index 0000000000..be0d96f3ea --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.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 org.apache.tuscany.spi.policy; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import static org.apache.tuscany.spi.policy.PolicyBuilderRegistry.EXTENSION; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + * @deprecated + */ +public class SourcePolicyBuilderExtensionTestCase extends TestCase { + + public void testRegister() throws Exception { + PolicyBuilderRegistry registry = EasyMock.createMock(PolicyBuilderRegistry.class); + registry.registerSourceBuilder(EasyMock.eq(EXTENSION), EasyMock.isA(MockPolicyBuilderExtension.class)); + EasyMock.replay(registry); + SourcePolicyBuilderExtension extension = new MockPolicyBuilderExtension(); + extension.setRegistry(registry); + extension.init(); + EasyMock.verify(registry); + } + + private static class MockPolicyBuilderExtension extends SourcePolicyBuilderExtension { + + public void build(ReferenceDefinition definition, Wire wire) throws BuilderException { + + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java new file mode 100644 index 0000000000..a044f6e507 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.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 org.apache.tuscany.spi.policy; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.model.ServiceDefinition; +import static org.apache.tuscany.spi.policy.PolicyBuilderRegistry.EXTENSION; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class TargetPolicyBuilderExtensionTestCase extends TestCase { + + public void testRegister() throws Exception { + PolicyBuilderRegistry registry = EasyMock.createMock(PolicyBuilderRegistry.class); + registry.registerTargetBuilder(EasyMock.eq(EXTENSION), EasyMock.isA(MockPolicyBuilderExtension.class)); + EasyMock.replay(registry); + TargetPolicyBuilderExtension extension = new MockPolicyBuilderExtension(); + extension.setRegistry(registry); + extension.init(); + EasyMock.verify(registry); + } + + private static class MockPolicyBuilderExtension extends TargetPolicyBuilderExtension { + + public void build(ServiceDefinition definition, Wire wire) throws BuilderException { + + } + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.java new file mode 100644 index 0000000000..832e3eb3a8 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.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 org.apache.tuscany.spi.util; + +import java.net.URI; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class URIHelperTestCase extends TestCase { + + public void testBaseName() throws Exception { + URI uri = new URI("foo"); + assertEquals("foo", UriHelper.getBaseName(uri)); + } + + public void testBaseNameScheme() throws Exception { + URI uri = new URI("sca://foo"); + assertEquals("foo", UriHelper.getBaseName(uri)); + } + + public void testBaseNameSchemePath() throws Exception { + URI uri = new URI("sca://bar/foo"); + assertEquals("foo", UriHelper.getBaseName(uri)); + } + + public void testBaseNamePath() throws Exception { + URI uri = new URI("bar/foo"); + assertEquals("foo", UriHelper.getBaseName(uri)); + } + + public void testBaseNameFragment() throws Exception { + URI uri = new URI("#foo"); + assertEquals("#foo", UriHelper.getBaseName(uri)); + } + + public void testDefragmentedNameScheme() throws Exception { + URI uri = new URI("sca://foo/bar#bar"); + assertEquals("sca://foo/bar", UriHelper.getDefragmentedName(uri).toString()); + } + + public void testDefragmentedName() throws Exception { + URI uri = new URI("foo/bar#bar"); + assertEquals("foo/bar", UriHelper.getDefragmentedName(uri).toString()); + } + + public void testDefragmentedNoName() throws Exception { + URI uri = new URI("#bar"); + assertEquals("", UriHelper.getDefragmentedName(uri).toString()); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.java new file mode 100644 index 0000000000..87be31b23b --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.util.stax; + +import java.io.InputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +/** + * Test case for StaxHelper + * + * @version $Revision$ $Date$ + * + */ +public class StaxUtilTestCase extends TestCase { + + public StaxUtilTestCase(String name) { + super(name); + } + + public void testSerialize() throws XMLStreamException { + + InputStream in = getClass().getClassLoader().getResourceAsStream("test.scdl"); + XMLStreamReader reader = StaxUtil.createReader(in); + StaxUtil.serialize(reader); + // TODO Do assertions + } + + public void testGetDocumentElementQName() throws XMLStreamException { + InputStream in = getClass().getClassLoader().getResourceAsStream("test.scdl"); + XMLStreamReader reader = StaxUtil.createReader(in); + String xml = StaxUtil.serialize(reader); + QName qname = StaxUtil.getDocumentElementQName(xml); + assertEquals("http://www.osoa.org/xmlns/sca/1.0", qname.getNamespaceURI()); + assertEquals("composite", qname.getLocalPart()); + } + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.java new file mode 100644 index 0000000000..41e2bb2e0f --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.LinkedList; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +import org.apache.tuscany.spi.component.WorkContext; + +/** + * @version $Rev$ $Date$ + */ +public class AbstractInvocationHandlerTestCase extends TestCase { + private WorkContext workContext; + + protected void setUp() throws Exception { + super.setUp(); + workContext = EasyMock.createMock(WorkContext.class); + EasyMock.expect(workContext.getCorrelationId()).andStubReturn(null); + EasyMock.expect(workContext.getCallbackUris()).andStubReturn(null); + EasyMock.replay(workContext); + } + + public void testInvocation() throws Throwable { + InvocationHandler handler = new InvocationHandler(); + Interceptor interceptor = new MockInterceptor(); + TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class); + EasyMock.replay(invoker); + InvocationChain chain = EasyMock.createMock(InvocationChain.class); + EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor); + EasyMock.replay(chain); + Object resp = handler.invoke(chain, invoker, new String[]{"foo"}, null, new LinkedList<URI>(), workContext); + assertEquals("response", resp); + } + + public void testShortCircuitInvocation() throws Throwable { + InvocationHandler handler = new InvocationHandler(); + TargetInvoker invoker = new MockInvoker(); + InvocationChain chain = EasyMock.createMock(InvocationChain.class); + EasyMock.expect(chain.getHeadInterceptor()).andReturn(null); + EasyMock.expect(chain.getTargetInvoker()).andReturn(invoker); + EasyMock.replay(chain); + Object resp = handler.invoke(chain, invoker, new String[]{"foo"}, null, new LinkedList<URI>(), workContext); + assertEquals("response", resp); + } + + + private class MockInvoker implements TargetInvoker { + + public Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) throws InvocationTargetException { + assertEquals("foo", Array.get(payload, 0)); + return "response"; + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + fail(); + return null; + } + + public boolean isCacheable() { + return false; + } + + public void setCacheable(boolean cacheable) { + + } + + public boolean isOptimizable() { + return false; + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + } + + private class InvocationHandler extends AbstractInvocationHandler { + + protected URI getFromAddress() { + return URI.create("from"); + } + + } + + private class MockInterceptor implements Interceptor { + + public Message invoke(Message msg) { + assertNotNull(msg.getCorrelationId()); + assertNotNull(msg.getTargetInvoker()); + assertNotNull(msg.getMessageId()); + assertNotNull(msg.getCallbackUris()); + assertEquals("foo", Array.get(msg.getBody(), 0)); + msg.setBody("response"); + return msg; + } + + public void setNext(Interceptor next) { + + } + + public Interceptor getNext() { + return null; + } + + public boolean isOptimizable() { + return false; + } + } + + +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.java new file mode 100644 index 0000000000..9b67ec53e4 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.spi.wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class ChainHolderTestCase extends TestCase { + + public void testClone() { + InvocationChain chain = EasyMock.createMock(InvocationChain.class); + EasyMock.replay(chain); + ChainHolder holder = new ChainHolder(chain); + assertNotNull(holder.clone()); + } +} diff --git a/tags/java/tsss-demo/kernel/spi/src/test/resources/test.scdl b/tags/java/tsss-demo/kernel/spi/src/test/resources/test.scdl new file mode 100644 index 0000000000..337ec02f06 --- /dev/null +++ b/tags/java/tsss-demo/kernel/spi/src/test/resources/test.scdl @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<!-- + Test for stax. + + $Rev$ $Date$ +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha" + name="test.scdl"> + + <component name="test.component"> + <system:implementation.system class="test.class"/> + <property name="testProperty">123</property> + </component> + +</composite> |