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 /sandbox/rajith |
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 'sandbox/rajith')
17 files changed, 1580 insertions, 0 deletions
diff --git a/sandbox/rajith/binding.jms/.ruleset b/sandbox/rajith/binding.jms/.ruleset new file mode 100644 index 0000000000..b74e1a701c --- /dev/null +++ b/sandbox/rajith/binding.jms/.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/sandbox/rajith/binding.jms/LICENSE.txt b/sandbox/rajith/binding.jms/LICENSE.txt new file mode 100644 index 0000000000..0084319535 --- /dev/null +++ b/sandbox/rajith/binding.jms/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/sandbox/rajith/binding.jms/NOTICE.txt b/sandbox/rajith/binding.jms/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sandbox/rajith/binding.jms/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/sandbox/rajith/binding.jms/pom.xml b/sandbox/rajith/binding.jms/pom.xml new file mode 100644 index 0000000000..4df008fb4b --- /dev/null +++ b/sandbox/rajith/binding.jms/pom.xml @@ -0,0 +1,100 @@ +<?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.services.bindings</groupId> + <artifactId>parent</artifactId> + <version>1.0-incubator-M2-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>jms</artifactId> + <name>Apache Tuscany Binding for JMS</name> + <description>Implementation of the SCA JMS binding spec.</description> + + <repositories> + <repository> + <id>apache.m1.snapshots</id> + <name>Apache M1 Snapshot Repository</name> + <url>http://people.apache.org/repo/m1-snapshot-repository</url> + <layout>legacy</layout> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>geronimo-spec</groupId> + <artifactId>geronimo-spec-jms</artifactId> + <version>1.1-rc4</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>core</artifactId> + <version>${sca.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sdo</groupId> + <artifactId>tuscany-sdo-impl</artifactId> + <version>${sca.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>databinding-sdo</artifactId> + <version>${sca.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-impl</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons</groupId> + <artifactId>XmlSchema</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>test</artifactId> + <version>${sca.version}</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/DefaultOperationSelector.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/DefaultOperationSelector.java new file mode 100644 index 0000000000..fe472e917c --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/DefaultOperationSelector.java @@ -0,0 +1,32 @@ +package org.apache.tuscany.binding.jms; + +import javax.jms.JMSException; +import javax.jms.Message; + +public class DefaultOperationSelector implements OperationSelector{ + + private JMSBinding jmsBinding; + + public DefaultOperationSelector(JMSBinding jmsBinding){ + this.jmsBinding = jmsBinding; + } + + public String getOperationName(Message message) { + try { + return message.getStringProperty(jmsBinding.getOperationSelectorPropertyName()); + } catch (JMSException e) { + e.printStackTrace(); + return null; + } + } + + public void setOperationName(String operationName,Message message) { + try { + message.setStringProperty(jmsBinding.getOperationSelectorPropertyName(),operationName); + } catch (JMSException e) { + e.printStackTrace(); + } + } + + +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBinding.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBinding.java new file mode 100644 index 0000000000..8bc8bc2c36 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBinding.java @@ -0,0 +1,167 @@ +package org.apache.tuscany.binding.jms; + +import javax.jms.DeliveryMode; + +import org.apache.tuscany.spi.model.Binding; + +/** + * Represents a binding to a JMS resource. + */ + +public class JMSBinding extends Binding { + + public final static int DESTINATION_TYPE_QUEUE = 0; + public final static int DESTINATION_TYPE_TOPIC = 1; + + private int destinationType = DESTINATION_TYPE_QUEUE; + + private String destinationName; + + // Topic or Query factory name + private String connectionFactoryName; + + private String activationSpecName; + + private String initialContextFactoryName; // "org.apache.activemq.jndi.ActiveMQInitialContextFactory" + + private String jNDIProviderURL; // "tcp://hostname:61616" + + // Maps to javax.jms.DeliveryMode + private int deliveryMode = DeliveryMode.NON_PERSISTENT; + + private int timeToLive = 1000 ; // in mili seconds + + private int priority; + + private String replyTo; + + private String jmsResourceFactoryName; + + private String operationSelectorName; + + private String operationSelectorPropertyName = "OpName"; + + public JMSBinding(int destinationType, String destinationName, String connectionFactoryName, String activationSpecName, String initialContextFactoryName, String providerURL, int deliveryMode, int timeToLive, int priority, String replyTo) { + super(); + this.destinationType = destinationType; + this.destinationName = destinationName; + this.connectionFactoryName = connectionFactoryName; + this.activationSpecName = activationSpecName; + this.initialContextFactoryName = initialContextFactoryName; + jNDIProviderURL = providerURL; + this.deliveryMode = deliveryMode; + this.timeToLive = timeToLive; + this.priority = priority; + this.replyTo = replyTo; + } + + public JMSBinding(){ + super(); + } + + public String getActivationSpecName() { + return activationSpecName; + } + + public void setActivationSpecName(String activationSpecName) { + this.activationSpecName = activationSpecName; + } + + public String getConnectionFactoryName() { + return connectionFactoryName; + } + + public void setConnectionFactoryName(String connectionFactoryName) { + this.connectionFactoryName = connectionFactoryName; + } + + public int getDeliveryMode() { + return deliveryMode; + } + + public void setDeliveryMode(int deliveryMode) { + this.deliveryMode = deliveryMode; + } + + public String getDestinationName() { + return destinationName; + } + + public void setDestinationName(String destinationName) { + this.destinationName = destinationName; + } + + public String getInitialContextFactoryName() { + return initialContextFactoryName; + } + + public void setInitialContextFactoryName(String initialContextFactoryName) { + this.initialContextFactoryName = initialContextFactoryName; + } + + public String getJNDIProviderURL() { + return jNDIProviderURL; + } + + public void setJNDIProviderURL(String providerURL) { + jNDIProviderURL = providerURL; + } + + public int getPriority() { + return priority; + } + + public void setPriority(int priority) { + this.priority = priority; + } + + public String getReplyTo() { + return replyTo; + } + + public void setReplyTo(String replyTo) { + this.replyTo = replyTo; + } + + public int getTimeToLive() { + return timeToLive; + } + + public void setTimeToLive(int timeToLive) { + this.timeToLive = timeToLive; + } + + public int getDestinationType() { + return destinationType; + } + + public void setDestinationType(int destinationType) { + this.destinationType = destinationType; + } + + public String getJmsResourceFactoryName() { + return jmsResourceFactoryName; + } + + public void setJmsResourceFactoryName(String jmsResourceFactoryName) { + this.jmsResourceFactoryName = jmsResourceFactoryName; + } + + public String getOperationSelectorName() { + return operationSelectorName; + } + + public void setOperationSelectorName(String operationSelectorName) { + this.operationSelectorName = operationSelectorName; + } + + public String getOperationSelectorPropertyName() { + return operationSelectorPropertyName; + } + + public void setOperationSelectorPropertyName( + String operationSelectorPropertyName) { + this.operationSelectorPropertyName = operationSelectorPropertyName; + } + +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java new file mode 100644 index 0000000000..f1359ed492 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingBuilder.java @@ -0,0 +1,137 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * 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. + */ +package org.apache.tuscany.binding.jms; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.spi.component.CompositeComponent; +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.extension.BindingBuilderExtension; +import org.apache.tuscany.spi.model.BoundReferenceDefinition; +import org.apache.tuscany.spi.model.BoundServiceDefinition; + +import commonj.sdo.helper.TypeHelper; + +/** + * Builds a Service or Reference for an RMI binding. + * + * @version $Rev$ $Date$ + */ + +public class JMSBindingBuilder extends BindingBuilderExtension<JMSBinding> { + + private static String DEFAULT_JMS_RESOURCE_FACTORY = "org.apache.tuscany.binding.jms.SimpleJMSResourceFactory"; + private static String DEFAULT_OPERATION_SELECTOR = "org.apache.tuscany.binding.jms.DefaultOperationSelector"; + + protected Class<JMSBinding> getBindingType() { + return JMSBinding.class; + } + + @SuppressWarnings({"unchecked"}) + public Service build(CompositeComponent parent, + BoundServiceDefinition<JMSBinding> serviceDefinition, + DeploymentContext deploymentContext) { + + JMSBinding jmsBinding = serviceDefinition.getBinding(); + Class<?> interfaze = serviceDefinition.getServiceContract().getInterfaceClass(); + TypeHelper typeHelper = (TypeHelper) deploymentContext.getExtension(TypeHelper.class.getName()); + if(typeHelper==null) typeHelper = TypeHelper.INSTANCE; + + JMSResourceFactory jmsResourceFactory = getJMSResourceFactory(jmsBinding); + OperationSelector opSec = getOperationSelector(jmsBinding); + + return new JMSService(serviceDefinition.getName(),parent, wireService, jmsBinding, jmsResourceFactory,opSec,interfaze,typeHelper); + } + + @SuppressWarnings({"unchecked"}) + public Reference build(CompositeComponent parent, + BoundReferenceDefinition<JMSBinding> referenceDefinition, + DeploymentContext deploymentContext) { + + String name = referenceDefinition.getName(); + Class<?> interfaze = referenceDefinition.getServiceContract().getInterfaceClass(); + + JMSBinding jmsBinding = referenceDefinition.getBinding(); + JMSResourceFactory jmsResourceFactory = getJMSResourceFactory(jmsBinding); + OperationSelector opSec = getOperationSelector(jmsBinding); + + return new JMSReference(name,parent,wireService, jmsBinding, jmsResourceFactory,opSec,interfaze); + + } + + private JMSResourceFactory getJMSResourceFactory(JMSBinding jmsBinding) { + String className = jmsBinding.getJmsResourceFactoryName(); + if (className != null && !className.equals("")){ + try { + Class factoryClass = Class.forName(className != null ? className : DEFAULT_JMS_RESOURCE_FACTORY); + Constructor constructor = factoryClass.getDeclaredConstructor(new Class[]{JMSBinding.class}); + return (JMSResourceFactory) constructor.newInstance(jmsBinding); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return new SimpleJMSResourceFactory(jmsBinding); + }else{ + return new SimpleJMSResourceFactory(jmsBinding); + } + + } + + + private OperationSelector getOperationSelector(JMSBinding jmsBinding) { + String className = jmsBinding.getOperationSelectorName(); + + if (className != null && !className.equals("")){ + try { + Class factoryClass = Class.forName(className != null ? className : DEFAULT_OPERATION_SELECTOR); + Constructor constructor = factoryClass.getDeclaredConstructor(new Class[]{JMSBinding.class}); + return (OperationSelector) constructor.newInstance(jmsBinding); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return new DefaultOperationSelector(jmsBinding); + }else{ + return new DefaultOperationSelector(jmsBinding); + } + } +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingLoader.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingLoader.java new file mode 100644 index 0000000000..c419df81f0 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSBindingLoader.java @@ -0,0 +1,119 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * 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. + */ +package org.apache.tuscany.binding.jms; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.osoa.sca.annotations.Scope; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMXMLParserWrapper; +import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.LoaderUtil; + +/** + * Loader for handling <binding.jms> elements. + * + * @version $Rev$ $Date$ + */ +@Scope("MODULE") +public class JMSBindingLoader extends LoaderExtension<JMSBinding> { + public static final QName BINDING_JMS = new QName( + "http://tuscany.apache.org/xmlns/binding/jms/1.0-SNAPSHOT", "binding.jms"); + + public JMSBindingLoader(@Autowire LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return BINDING_JMS; + } + + public JMSBinding load(CompositeComponent parent, + XMLStreamReader reader, + DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + + OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), reader); + OMElement omElement = builder.getDocumentElement(); + + OMElement connectionOM = omElement.getFirstChildWithName(new QName("connection.jms")); + + String activationSpecName = connectionOM.getAttributeValue(new QName("activationSpecName")); + String destinationName = connectionOM.getAttributeValue(new QName("destinationName")); + String connectionFactoryName = connectionOM.getAttributeValue(new QName("connectionFactoryName")) ; + String initialContextFactoryName = connectionOM.getAttributeValue(new QName("initialContextFactoryName")) ; + String jNDIProviderURL = connectionOM.getAttributeValue(new QName("providerURL")) ; + String deliveryMode = connectionOM.getAttributeValue(new QName(null, "deliveryMode")) ; + String timeToLive = connectionOM.getAttributeValue(new QName(null, "timeToLive")) ; + String priority = connectionOM.getAttributeValue(new QName(null, "priority")) ; + String replyTo = connectionOM.getAttributeValue(new QName(null, "replyTo")) ; + String jmsResourceFactoryName = connectionOM.getAttributeValue(new QName(null, "jmsResourceFactory")) ; + + OMElement opSecOM = omElement.getFirstChildWithName(new QName("operationSelector")); + String operationSelector = opSecOM.getAttributeValue(new QName("name")); + OMElement opSecPropertyOM = opSecOM.getFirstChildWithName(new QName("property")); + String jmsOpSecPropertyName = opSecPropertyOM.getText(); + + LoaderUtil.skipToEndElement(reader); + + JMSBinding binding = new JMSBinding(); + binding.setActivationSpecName(activationSpecName); + binding.setConnectionFactoryName(connectionFactoryName); + binding.setDestinationName(destinationName); + binding.setInitialContextFactoryName(initialContextFactoryName); + binding.setJNDIProviderURL(jNDIProviderURL); + binding.setReplyTo(replyTo); + binding.setJmsResourceFactoryName(jmsResourceFactoryName); + binding.setOperationSelectorName(operationSelector); + binding.setOperationSelectorPropertyName(jmsOpSecPropertyName); + + if (deliveryMode != null && deliveryMode.trim().equals("")){ + try{ + binding.setDeliveryMode(Integer.parseInt(deliveryMode)); + }catch (Exception e){ + + } + } + + if (priority != null && priority.trim().equals("")){ + try{ + binding.setPriority(Integer.parseInt(priority)); + }catch (Exception e){ + + } + } + + if (timeToLive != null && timeToLive.trim().equals("")){ + try{ + binding.setTimeToLive(Integer.parseInt(timeToLive)); + }catch (Exception e){ + + } + } + + return binding; + } +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSProxy.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSProxy.java new file mode 100644 index 0000000000..d088e0f288 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSProxy.java @@ -0,0 +1,80 @@ +package org.apache.tuscany.binding.jms; + +import java.lang.reflect.Method; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.naming.Context; +import javax.naming.NamingException; + +public class JMSProxy implements MessageListener{ + + protected Method operationMethod; + protected SDODataBinding dataBinding; + private Object entryPointProxy; + private JMSBinding jmsBinding; + private Context context; + private JMSResourceFactory jmsResourceFactory; + private OperationSelector operationSelector; + + public JMSProxy(Object entryPointProxy,JMSResourceFactory jmsResourceFactory, JMSBinding jmsBinding,SDODataBinding dataBinding, OperationSelector operationSelector) throws NamingException{ + + this.entryPointProxy = entryPointProxy; + this.dataBinding = dataBinding; + this.jmsBinding = jmsBinding; + this.jmsResourceFactory = jmsResourceFactory; + this.operationSelector = operationSelector; + } + + public void onMessage(Message msg){ + + String operationName = operationSelector.getOperationName(msg); + + try { + + Object[] args = dataBinding.fromXML(((TextMessage)msg).getText()); + + operationMethod = getOperationMethod(entryPointProxy,operationName,args); + + Object result = operationMethod.invoke(entryPointProxy,args); + + // if result is null then the method can be assumed as oneway + if (result != null){ + String response = dataBinding.toXML(new Object[] {result} ); + sendReply(operationName, response); + } + } catch (Exception e) { + // need to do proper error handling + e.printStackTrace(); + } + } + + private Method getOperationMethod(Object entryPointProxy2, String operationName, Object[] args) { + // TODO Auto-generated method stub + return null; + } + + private void sendReply(String operationName,String payload) throws JMSException, NamingException{ + + Session session = jmsResourceFactory.createSession(); + + javax.jms.Message message = jmsResourceFactory.createMessage(session); + message.setJMSCorrelationID(operationName); // I am using the existing header instead of adding a new JMS property. + + ((javax.jms.TextMessage)message).setText((String)payload); + + Destination destination = null; + Object obj = context.lookup(jmsBinding.getDestinationName()); + destination = (Destination) obj; + + MessageProducer producer = session.createProducer(destination); + producer.send(message); + producer.close(); + session.close(); + } +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSReference.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSReference.java new file mode 100644 index 0000000000..ac669653b8 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSReference.java @@ -0,0 +1,43 @@ +package org.apache.tuscany.binding.jms; + +import javax.naming.NamingException; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.extension.ReferenceExtension; +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.WireService; + +/** + * @version $Rev$ $Date$ + */ +public class JMSReference<T> extends ReferenceExtension { + + private JMSBinding jmsBinding; + private JMSResourceFactory jmsResourceFactory; + private OperationSelector operationSelector; + + public JMSReference(String name, + CompositeComponent parent, + WireService wireService, + JMSBinding jmsBinding, + JMSResourceFactory jmsResourceFactory, + OperationSelector operationSelector, + Class<?> service) { + + super(name, service, parent, wireService); + + this.jmsBinding = jmsBinding; + this.jmsResourceFactory = jmsResourceFactory; + this.operationSelector = operationSelector; + } + + public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) { + try { + return new JMSTargetInvoker(jmsResourceFactory, jmsBinding, operation.getName(),operationSelector); + } catch (NamingException e) { + throw new RuntimeException("Unable to create JMS resources for the invocation",e); + } + } +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSResourceFactory.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSResourceFactory.java new file mode 100644 index 0000000000..5633cbed16 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSResourceFactory.java @@ -0,0 +1,24 @@ +package org.apache.tuscany.binding.jms; + +import javax.jms.Connection; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; +import javax.naming.NamingException; + +public interface JMSResourceFactory { + + public abstract Connection getConnection() throws NamingException, + JMSException; + + public abstract Session createSession() throws JMSException, + NamingException; + + public abstract void startConnection() throws JMSException, NamingException; + + public abstract void closeConnection() throws JMSException, NamingException; + + public abstract Message createMessage(Session session) + throws JMSException; + +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSService.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSService.java new file mode 100644 index 0000000000..d92303145e --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSService.java @@ -0,0 +1,82 @@ +package org.apache.tuscany.binding.jms; + + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.Session; +import javax.naming.NamingException; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.extension.ServiceExtension; +import org.apache.tuscany.spi.wire.WireService; + +import commonj.sdo.helper.TypeHelper; + +/** + * @version $Rev$ $Date$ + */ +public class JMSService extends ServiceExtension { + + private JMSBinding jmsBinding; + private TypeHelper typeHelper; + private JMSResourceFactory jmsResourceFactory; + private MessageConsumer consumer; + private OperationSelector operationSelector; + + public JMSService(String name, + CompositeComponent parent, + WireService wireService, + JMSBinding jmsBinding, + JMSResourceFactory jmsResourceFactory, + OperationSelector operationSelector, + Class<?> service, + TypeHelper typeHelper) { + super(name, service, parent, wireService); + + this.jmsBinding = jmsBinding; + this.typeHelper = typeHelper; + this.jmsResourceFactory = jmsResourceFactory; + this.operationSelector = operationSelector; + } + + public void start() { + super.start(); + try { + registerListerner(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void stop() { + + try { + consumer.close(); + jmsResourceFactory.closeConnection(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + super.stop(); + } + + private void registerListerner() throws NamingException, JMSException{ + + Object entryPointProxy = this.getServiceInstance(); + QName responseQN = new QName("payload"); + SDODataBinding dataBinding = new SDODataBinding(typeHelper, false, responseQN); + + Session session = jmsResourceFactory.createSession(); + Destination destination = session.createQueue(jmsBinding.getDestinationName()); + + consumer = session.createConsumer(destination); + consumer.setMessageListener(new JMSProxy(entryPointProxy,jmsResourceFactory,jmsBinding,dataBinding,operationSelector)); + + jmsResourceFactory.startConnection(); + + } +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSTargetInvoker.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSTargetInvoker.java new file mode 100644 index 0000000000..97b2dbef83 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/JMSTargetInvoker.java @@ -0,0 +1,111 @@ +package org.apache.tuscany.binding.jms; + + +import java.lang.reflect.InvocationTargetException; +import java.util.Properties; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.TargetInvoker; + +/** + * Invoke a JMS reference. + * + * @version $Rev$ $Date$ + */ +public class JMSTargetInvoker implements TargetInvoker { + private JMSBinding jmsBinding; + private Context context; + private String operationName; + private JMSResourceFactory jmsResourceFactory; + private OperationSelector operationSelector; + + public JMSTargetInvoker(JMSResourceFactory jmsResourceFactory,JMSBinding jmsBinding, String operationName, OperationSelector operationSelector) throws NamingException { + this.jmsBinding = jmsBinding; + this.jmsResourceFactory = jmsResourceFactory; + this.operationName = operationName; + this.operationSelector = operationSelector; + } + + public Message invoke(Message msg) throws InvocationRuntimeException { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBody(e.getCause()); + } + return msg; + } + + public Object invokeTarget(Object payload) throws InvocationTargetException { + try { + + return sendReceiveMessage(payload); + + } catch (Exception e) { // catch JMS specific error + + throw new AssertionError(e); + } + + } + + public Object clone() throws CloneNotSupportedException { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(e); + } + } + + public boolean isOptimizable() { + return false; + } + + public boolean isCacheable() { + return false; + } + + public void setCacheable(boolean cacheable) { + } + + private Object sendReceiveMessage(Object payload) throws JMSException, NamingException{ + + Session session = jmsResourceFactory.createSession(); + + javax.jms.Message message = jmsResourceFactory.createMessage(session); + operationSelector.setOperationName(operationName,message); + + ((javax.jms.TextMessage)message).setText((String)payload); + + Destination destination = (Destination) context.lookup(jmsBinding.getDestinationName()); + + MessageProducer producer = session.createProducer(destination); + + // create a temporary queue and listen to the response + Destination replyDest = session.createTemporaryQueue(); + message.setJMSReplyTo(replyDest); + + producer.send(message); + producer.close(); + + MessageConsumer consumer = session.createConsumer(replyDest); + jmsResourceFactory.startConnection(); + javax.jms.Message reply = consumer.receive(jmsBinding.getTimeToLive()); + consumer.close(); + + session.close(); + + return ((javax.jms.TextMessage)reply).getText(); + } +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/OperationSelector.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/OperationSelector.java new file mode 100644 index 0000000000..2b510e6eb7 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/OperationSelector.java @@ -0,0 +1,12 @@ +package org.apache.tuscany.binding.jms; + +/* + * Defined by the SCA Messaging binding spec + */ +public interface OperationSelector { + + public String getOperationName(javax.jms.Message message); + + public void setOperationName(String operationName,javax.jms.Message message); + +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/SDODataBinding.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/SDODataBinding.java new file mode 100644 index 0000000000..f45a3f68d4 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/SDODataBinding.java @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.binding.jms; + +import java.io.ByteArrayInputStream; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMXMLParserWrapper; +import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory; +import org.apache.tuscany.core.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.databinding.sdo.XMLDocument2XMLStreamReader; +import org.apache.tuscany.databinding.sdo.XMLStreamReader2XMLDocument; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * DataBinding for converting between AXIOM OMElement and Java Objects + */ +public class SDODataBinding { + + private TypeHelper typeHelper; + + private boolean isWrapped; + + private QName elementName; + + public SDODataBinding(TypeHelper typeHelper, boolean isWrapped, QName elementName) { + this.typeHelper = typeHelper; + this.isWrapped = isWrapped; + this.elementName = elementName; + } + + public Object[] fromXML(String input) throws XMLStreamException, FactoryConfigurationError { + + ByteArrayInputStream bIn = new ByteArrayInputStream(input.getBytes()); + + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(bIn); + + XMLStreamReader2XMLDocument transformer = new XMLStreamReader2XMLDocument(); + TransformationContext context = new TransformationContextImpl(); + DataType<QName> binding = new DataType<QName>(DataObject.class, null); + binding.setMetadata(TypeHelper.class.getName(), typeHelper); + context.setTargetDataType(binding); + XMLDocument document = transformer.transform(reader, context); + return toObjects(document, isWrapped); + } + + public String toXML(Object[] os) { + XMLDocument document = toXMLDocument(typeHelper, os, elementName, isWrapped); + XMLDocument2XMLStreamReader transformer = new XMLDocument2XMLStreamReader(); + XMLStreamReader reader = transformer.transform(document, null); + OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), reader); + OMElement omElement = builder.getDocumentElement(); + return omElement.toString(); + } + + /** + * Convert a typed DataObject to Java objects + * + * @param dataObject + * @param isWrapped + * @return the array of Objects from the DataObject + */ + public static Object[] toObjects(XMLDocument document, boolean isWrapped) { + DataObject dataObject = document.getRootObject(); + if (isWrapped) { + List ips = dataObject.getInstanceProperties(); + Object[] os = new Object[ips.size()]; + for (int i = 0; i < ips.size(); i++) { + os[i] = dataObject.get((Property) ips.get(i)); + } + return os; + } else { + Object object = dataObject; + Type type = dataObject.getType(); + if (type.isSequenced()) { + object = dataObject.getSequence().getValue(0); + } + return new Object[] { object }; + } + } + + /** + * Convert objects to typed DataObject + * + * @param typeNS + * @param typeName + * @param os + * @return the DataObject + */ + private static XMLDocument toXMLDocument(TypeHelper typeHelper, Object[] os, QName elementQName, boolean isWrapped) { + XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper); + + Property property = xsdHelper.getGlobalProperty(elementQName.getNamespaceURI(), elementQName.getLocalPart(), true); + if (null == property) { + throw new InvocationRuntimeException("Type '" + elementQName.toString() + "' not found in registered SDO types."); + } + DataObject dataObject = null; + if (isWrapped) { + DataFactory dataFactory = SDOUtil.createDataFactory(typeHelper); + dataObject = dataFactory.create(property.getType()); + List ips = dataObject.getInstanceProperties(); + for (int i = 0; i < ips.size(); i++) { + dataObject.set(i, os[i]); + } + } else { + Object value = os[0]; + Type type = property.getType(); + if (!type.isDataType()) { + dataObject = (DataObject) value; + } else { + dataObject = SDOUtil.createDataTypeWrapper(type, value); + } + } + + XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper); + return xmlHelper.createDocument(dataObject, elementQName.getNamespaceURI(), elementQName.getLocalPart()); + + } + +} diff --git a/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/SimpleJMSResourceFactory.java b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/SimpleJMSResourceFactory.java new file mode 100644 index 0000000000..399e80e4b5 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/java/org/apache/tuscany/binding/jms/SimpleJMSResourceFactory.java @@ -0,0 +1,95 @@ +package org.apache.tuscany.binding.jms; + +import java.util.Properties; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; + +public class SimpleJMSResourceFactory implements JMSResourceFactory { + + private JMSBinding jmsBinding; + private Connection con; + private Context context; + private boolean isConnectionStarted; + + public SimpleJMSResourceFactory(JMSBinding jmsBinding){ + this.jmsBinding = jmsBinding; + } + + /* + * This is a simple implementation where a connection is created per binding + * Ideally the resource factory should be able to leverage the host environment + * to provide connection pooling if it can. + * + * For ex If Tuscany is running inside an AppServer + * Then we could leverage the JMS resources it provides + * + * @see org.apache.tuscany.binding.jms.JMSResourceFactory#getConnection() + */ + public Connection getConnection() throws NamingException, JMSException{ + if (con == null){ + createConnection(); + } + return con; + } + + /* (non-Javadoc) + * @see org.apache.tuscany.binding.jms.JMSResourceFactory#createSession() + */ + public Session createSession() throws JMSException, NamingException{ + return getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); + } + + /* (non-Javadoc) + * @see org.apache.tuscany.binding.jms.JMSResourceFactory#startConnection() + */ + public void startConnection() throws JMSException, NamingException{ + if(!isConnectionStarted){ + getConnection().start(); + isConnectionStarted = true; + } + } + + /* (non-Javadoc) + * @see org.apache.tuscany.binding.jms.JMSResourceFactory#closeConnection() + */ + public void closeConnection() throws JMSException, NamingException{ + if(con != null){ + con.close(); + } + } + + /* (non-Javadoc) + * @see org.apache.tuscany.binding.jms.JMSResourceFactory#createTextMessage(javax.jms.Session) + */ + public Message createMessage(Session session) throws JMSException{ + javax.jms.Message message = session.createTextMessage(); // default + message.setJMSDeliveryMode(jmsBinding.getDeliveryMode()); + message.setJMSPriority(jmsBinding.getPriority()); + + return message; + } + + private void createConnection() throws NamingException, JMSException { + if(context == null){ + createInitialContext(); + } + ConnectionFactory conFac = (ConnectionFactory)context.lookup(jmsBinding.getConnectionFactoryName()); + con = conFac.createConnection(); + } + + private void createInitialContext() throws NamingException{ + Properties props = new Properties(); + props.setProperty(Context.INITIAL_CONTEXT_FACTORY,jmsBinding.getInitialContextFactoryName()); + props.setProperty(Context.PROVIDER_URL,jmsBinding.getJNDIProviderURL()); + + context = new InitialContext(props); + } + +} diff --git a/sandbox/rajith/binding.jms/src/main/resources/META-INF/sca/default.scdl b/sandbox/rajith/binding.jms/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..f80bfed326 --- /dev/null +++ b/sandbox/rajith/binding.jms/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,16 @@ +<composite name="org.apache.tuscany.binding.jms.JMSBinding"> + <tuscany:dependency> + <group>org.apache.activemq</group> + <artifact>activemq-core</artifact> + <version>SNAPSHOT</version> + </tuscany:dependency> + + <component name="jms.bindingLoader"> + <system:implementation.system class="org.apache.tuscany.binding.jms.JMSBindingLoader"/> + </component> + + <component name="jms.bindingBuilder"> + <system:implementation.system class="org.apache.tuscany.binding.jms.JMSBindingBuilder"/> + </component> + +</composite> |